Go to https://github.com/mav-rik/facerestore_cf for a more up to date fork of this project.
These ComfyUI nodes can be used to restore faces in images similar to the face restore option in AUTOMATIC1111 webui.
Installation
Extract the zip and put the facerestore directory inside the ComfyUI custom_nodes directory.
If running the portable windows version of ComfyUI, run embedded_install.bat
Windows users not running the portable version can run install.bat. Linux and mac users can run install.sh
If the install fails for whatever reason, you'll need to work out how to install opencv-python yourself (you'll get a cv2 not found error otherwise)
Face Restoration Models
These models perform the face restoration. If you use automatic1111 you probably already have them but if not here are the download links.
Just put them in models/facerestore_models.
https://github.com/TencentARC/GFPGAN/releases/
https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth
https://github.com/sczhou/CodeFormer/releases/
https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth
Face detection models
The face restoration model only works with cropped face images. A face detection model is used to send a crop of each face found to the face restoration model.
These will automaticly be downloaded and placed in models/facedetection the first time each is used.
Here's the links if you'd rather download them yourself.
https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth
https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_mobilenet0.25_Final.pth
https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/yolov5l-face.pth
https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/yolov5n-face.pth
This also gets downloaded and put in the facedetection folder. It's used to put the restored faces back into the original image.
https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/parsing_parsenet.pth
Description
Changelog
The face restore node and crop face node now handle multi image batches
Added a face restore model loader. If migrating from an earlier version, move the face restore models from the upscale_models folder to the facerestore_models folder.
Added a requirements.txt & install.bat
FAQ
Comments (33)
It works, but produces slightly aliased/pixelized results. (You can especially notice it in hair.)
The face restore model works with 512x512 images so if the face is a different size to that some image resizing will occur which can be more noticable in some images than others (this is the same as what happens in automatic1111. A lot of the code was copied from there).
For best results I'd recommend running the image through another sampler with low denoising after restoring the face. The ComfyUI Impact Pack has its own detection nodes and can denoise parts of the image seperately so you could use that to denoise just the face after running it through the face restore GAN (or might the image looks better without the GAN as it has a tendancy to wipe emotions from faces)
I got this error on Mac m1: DEPRECATION: torchsde 0.2.5 has a non-standard dependency specifier numpy>=1.19.*; python_version >= "3.7". pip 23.3 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of torchsde or contact the author to suggest that they release a version with a conforming dependency specifiers. Discussion can be found at https://github.com/pypa/pip/issues/12063
No matter what I try, I always get this error:
Failed to validate prompt for output 73:
* FaceRestoreWithModel 53:
- Required input is missing: facerestore_model
I have downloaded every single file, and put them in the correct folders. I even tried to put the downloads in the node's folder along with the root folder for face detection adn face restoration but the node is skipped :S What can I do?
The error says no model node was connected to the input of the face restore node. Did you connect the face restore model loader node to the face restore node?
Any ideas?
Python stacktrace looks awful, sorry:
It looks like a problem with the version string from PyTorch
By the way, do you have any git repository?
Also, is it possible to follow the algorithm used by ComfyUI? Seems like it ignores completely --bf16-vae
This is critical for some videocards because they will get system crashes. That's also the main reason why I use PyTorch dev.
By using fp16-vae it causes a bad crash. bf16-vae only works for me by using the -dev branch of PyTorch.
Looks like that line of code is checking for a version in the format 1.2.3 but getting 1.2.3.dev20230805 and crashing because dev20230805 isn't a number. Until I get around to fixing it, just edit that face_detector.py file and replace line 20 with IS_HIGH_VERSION = True or alternatively just install a non-dev build of torch.
The --fp16-vae and --bf16-vae settings are only supposed to affect the vae. Facerestore doesn't use a vae so these shouldn't affect it.
Yeah, did the IS_HIGH_VERSION = True and was loaded fine.
The reason why I can't use a non-dev version is because my whole computer freezes if I don't use bf16-vae.
Now, while it loads fine, and my results work fine without facerestore-node, my laptop freezes when used. Will check and add some sys.exit and see where is the offender line. I was assuming it's related to the two conversions from uint8 to fp16/32.
Is there any way to control the strength of the restore model in comfy similar to the slider strength effect in the a1111webui?
Whilst it definitely does exactly the job needed for restoring faces in comfy, sometimes the effect is too polarising to the point where faces have that photoshopped look and a lot of the finer details are lost.
Not in the current version. I might try to add that slider in the future.
Until then, I find the GFPGAN model looks less photoshopped than the codeformer model so you should try that model if you haven't already.
You can also get good results by running the restored face through img2img with light denoising. The ComfyUI Impact Pack Is good for this task.
i have this error : module 'cv2.gapi.wip.draw' has no attribute 'Text'
i've tried everything, installing opencv, uninstall it, etc
Not sure what could cause that.
A new version all opencv-python==4.8.0.76 came out a few days ago. I just installed it and it still works on my system (tested on windows with the portable version of comfy) but just to be sure you might want to try installing the previous version opencv-python==4.8.0.74
it works okay, but I noticed that there is a blur in the final result, will upload some pictures in the showcase, doyou have any idea to prevent this? thanks.
This has also always been an issue with face restore in A1111. A few ideas on how to fix
- Import both the before and after images into photoshop and mask out the blurry bits in the restored picture.
- Run the restored picture through an image-to-image node with light denoising. There are detailer nodes that can target just the face for inpainting if you'd rather not denoise the whole image
- The face restore model operates on a fixed 512x512 crop of the face. The face restore code scales the face crop as required before sending it to the restore model. If you have a very high resolution final image that you try to restore, you could end up lowering the resolution of the face.
Does not seem to work with the experimental embedded python installation of comfyui
HELP PLZ !
Everything was fine with me, but at one moment the node disappeared, I'm trying to install it again and without success! I tried all the advice and comments, tell me who knows, thanks!
1. Can I add a repair strength value? It repairs the face so well that it doesn't match the surrounding picture.
2. Can I add a number of faces to fix? Sometimes there are other faces in the background that don't need to be fixed, just keep them blurry.
1. Not in the current version. 2. A small change to the code could limit the faces to fix, but it might fix only a background face instead of the foreground face. Idealy, it would detect blury faces with some bluriness threshold that you could set and ignore them. I haven't implemented any of that so for the time being you can fix the images by combining the restored and non-restored images either in image editing software like photoshop or you could try setting up a workflow in comfy that does that for you with something like instance segmentation.
@m99 Thank you for the advice and hope to see the intensity adjustment option sooner.
Unfortunately ComfyUI doesn't seem to load it at launch.
On a M2, I have this error message :
(IMPORT FAILED): (nylocaldirectory)/ComfyUI/custom_nodes/facerestore
it is just after a successful import of another custom node.
Didn't had any issue with running bash install.sh, everything was there, but the deprecated message as shown in another comment.
Any idea how to move forward from there ?
The line 20 about the version detection was causing the issue.
changing it to IS_HIGH_VERSION = True, allowed the loading of the custom net.
Note I use ROCm on Linux, but I am getting this error
Traceback (most recent call last): File "/home/noah/Documents/AI/ComfyUI/nodes.py", line 1725, in load_custom_node module_spec.loader.exec_module(module) File "<frozen importlib._bootstrap_external>", line 940, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/home/noah/Documents/AI/ComfyUI/custom_nodes/facerestore/__init__.py", line 8, in <module> from custom_nodes.facerestore.facelib.utils.face_restoration_helper import FaceRestoreHelper File "/home/noah/Documents/AI/ComfyUI/custom_nodes/facerestore/__init__.py", line 8, in <module> from custom_nodes.facerestore.facelib.utils.face_restoration_helper import FaceRestoreHelper File "/home/noah/Documents/AI/ComfyUI/custom_nodes/facerestore/facelib/utils/face_restoration_helper.py", line 7, in <module> from custom_nodes.facerestore.facelib.detection import init_detection_model File "/home/noah/Documents/AI/ComfyUI/custom_nodes/facerestore/facelib/detection/__init__.py", line 12, in <module> from .yolov5face.face_detector import YoloDetector File "/home/noah/Documents/AI/ComfyUI/custom_nodes/facerestore/facelib/detection/yolov5face/face_detector.py", line 20, in <module> IS_HIGH_VERSION = tuple(map(int, torch.__version__.split('+')[0].split('.'))) >= (1, 9, 0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: 'dev20230829' Cannot import /home/noah/Documents/AI/ComfyUI/custom_nodes/facerestore module for custom nodes: invalid literal for int() with base 10: 'dev20230829' Import times for custom nodes: 0.0 seconds: /home/noah/Documents/AI/ComfyUI/custom_nodes/sdxl_prompt_styler 0.0 seconds (IMPORT FAILED): /home/noah/Documents/AI/ComfyUI/custom_nodes/facerestore 0.0 seconds: /home/noah/Documents/AI/ComfyUI/custom_nodes/comfyui_controlnet_aux 0.0 seconds: /home/noah/Documents/AI/ComfyUI/custom_nodes/ComfyUI-Manager 0.7 seconds: /home/noah/Documents/AI/ComfyUI/custom_nodes/was-node-suite-comfyui Starting serverThat line of code expects the installed version of torch to be a number in the format 1.2.3, but its dev20230829. I'll keep a note to adress this if I do another release. Until then, try opening face_detector.py and changing line 20 to
IS_HIGH_VERSION = True
Hey, I get this error:
Cannot import C:\Users\david\Downloads\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyuiFacerestore_v10 module for custom nodes: [Errno 2] No such file or directory: 'C:\\Users\\david\\Downloads\\ComfyUI_windows_portable\\ComfyUI\\custom_nodes\\comfyuiFacerestore_v10\\__init__.py'
Any ideas?
Has anyone got this working on AMD GPUs? It seems to be using inpainting, which doesn't work with AMD unless you have certain command line args, which don't seem to be available in ComfyUI like they were in A1111.
I don't have an AMD gpu so can't verify what the issue might be.
This facerestore node uses a GFPGAN or Codeformer model to update the face rather than an inpainting stable diffusion chekpoint so I don't think that's the issue.
I can suggest trying the following:
1. Try the version on github. I don't maintain it and it's possible someone else has fixed the issue you're seeing.
2. Try deleting the line 'torch.cuda.empty_cache()' from __init.py__ (line 160 here or line 167 if you cloned from github). Idk if that line would cause a crash when using an amd gpu so let me know if removing that fixes the issue.
3. post the error you're seeing if none of the above fixes the issue.
took a while to get it work
with mixed results
After getting cv2 and manually adding IS_HIGH_VERSION = True to face_detectory.py it started for me
hi, is this node outdated? it suddently stopped working for no reason, i used to use it a lot and it just stopped working even before i updated comfy
I have all the requirements to use this node afaik.
After downloading and placing all of the files I keep getting this missing node Facerestorewithmodel not found.
https://github.com/mav-rik/facerestore_cf
is installed and ran embedding for portable.
ComfyUI starts with no red flags or errors.
Am trying to get this WF actively working
ezpz22step1080p - v2 1080p/4k | Stable Diffusion XL Workflows | Civitai
Is there something I am missing cuz the 720p and 1080p nodes are highlighted red and can't seem to figure it out.
