Gourieff / comfyui-reactor-node

Fast and Simple Face Swap Extension Node for ComfyUI
GNU General Public License v3.0
1.08k stars 114 forks source link

Gray noise output only when selected GFPGAN #326

Open abkcehtnn opened 1 month ago

abkcehtnn commented 1 month ago

First, confirm

What happened?

Only when I select GFPGAN for face_restore_model, I get gray noise in the output image. When I select the codeformer for face_restore_model the problem does not occur. I confirmed the same problem in both GFPGAN v1.3 and v1.4.

022144

Steps to reproduce the problem

Select GFPGAN for face_restore_model

Sysinfo

Microsoft Windows 10 Home AMD Ryzen 7 3700X 8-Core Processor 3.60 GHz RTX 2070 Super RAM 32.0 GB

Relevant console log

---

[ReActor] 02:26:20 - STATUS - Working: source face index [0], target face index [0]
[ReActor] 02:26:20 - STATUS - Analyzing Source Image...
[ReActor] 02:27:03 - STATUS - Analyzing Target Image...
[ReActor] 02:27:05 - STATUS - Swapping...
[ReActor] 02:27:06 - STATUS - --Done!--
[ReActor] 02:27:06 - STATUS - Restoring with GFPGANv1.4.pth
WARNING: comfy_extras.chainner_models is deprecated and has been replaced by the spandrel library.
Prompt executed in 48.77 seconds

---

[ReActor] 02:28:11 - STATUS - Working: source face index [0], target face index [0]
[ReActor] 02:28:11 - STATUS - Using Hashed Source Face(s) Model...
[ReActor] 02:28:11 - STATUS - Using Hashed Target Face(s) Model...
[ReActor] 02:28:11 - STATUS - Swapping...
[ReActor] 02:28:11 - STATUS - --Done!--
[ReActor] 02:28:11 - STATUS - Restoring with GFPGANv1.3.pth
WARNING: comfy_extras.chainner_models is deprecated and has been replaced by the spandrel library.
Prompt executed in 2.10 seconds

---

[ReActor] 02:28:28 - STATUS - Working: source face index [0], target face index [0]
[ReActor] 02:28:28 - STATUS - Using Hashed Source Face(s) Model...
[ReActor] 02:28:28 - STATUS - Using Hashed Target Face(s) Model...
[ReActor] 02:28:28 - STATUS - Swapping...
[ReActor] 02:28:29 - STATUS - --Done!--
[ReActor] 02:28:29 - STATUS - Restoring with codeformer-v0.1.0.pth
Prompt executed in 2.84 seconds

Additional information

No response

abee717171 commented 1 month ago

yes, same here, it seems the mask appears as a grey layer on top of the image. only occurs with GFPGAN.

grizwad commented 1 month ago

The latest comfyui update that added the spandrel library caused this, needs to be checked by the creator to make it compatible.

Bodo02 commented 1 month ago

I have exactly the same error as described :(

abkcehtnn commented 1 month ago

so everyone is facing the same problem... okay... Im a newbie and would like to know, how do I downgrade Reactor? OR do I have to downgrade comfyui because this issue was caused by an update to comfyui? If anyone knows of a guide, I'd appreciate it if you could give me the URL or something

Gourieff commented 1 month ago

🤔 Hm... Thanks guys for spotting this...

Gourieff commented 1 month ago

so everyone is facing the same problem... okay... Im a newbie and would like to know, how do I downgrade Reactor? OR do I have to downgrade comfyui because this issue was caused by an update to comfyui? If anyone knows of a guide, I'd appreciate it if you could give me the URL or something

You should downgrade Comfy to this commit I suppose https://github.com/comfyanonymous/ComfyUI/commit/ffc4b7c30e35eb2773ace52a0b00e0ca5c1f4362 (before spandrel lib was added)

IrfanKheiri commented 1 month ago

same issue

abkcehtnn commented 1 month ago

so everyone is facing the same problem... okay... Im a newbie and would like to know, how do I downgrade Reactor? OR do I have to downgrade comfyui because this issue was caused by an update to comfyui? If anyone knows of a guide, I'd appreciate it if you could give me the URL or something

You should downgrade Comfy to this commit I suppose comfyanonymous/ComfyUI@ffc4b7c (before spandrel lib was added)

Woooow, Thanks!!!

Gourieff commented 1 month ago

The temporary workaround is to revert ComfyUI to the commit https://github.com/comfyanonymous/ComfyUI/commit/ffc4b7c30e35eb2773ace52a0b00e0ca5c1f4362:

Open Console/Terminal inside the "[ComfyUI root]\ComfyUI" dir and run:

  git checkout ffc4b7c

When you want to return back - just switch the branch to master

  git checkout master
abkcehtnn commented 1 month ago

The temporary workaround is to revert ComfyUI to the commit comfyanonymous/ComfyUI@ffc4b7c:

Open Console/Terminal inside the "[ComfyUI root]\ComfyUI" dir and run:

  git checkout ffc4b7c

When you want to return back - just switch the branch to master

  git checkout master

Thank you!

4DeepThought2 commented 1 month ago

Now to remember to swap back to master at some point in the future :) Thanks!

KINGLIFER commented 1 month ago

I didnt post because for some reason he isnt responding to my posts. I respect it just do not know why. https://github.com/Gourieff/comfyui-reactor-node/issues/281

Gourieff commented 1 month ago

I didnt post because for some reason he isnt responding to my posts. I respect it just do not know why. #281

Sorry for that my friend, I have no appropriate answer to your FR yet, I have no idea at the moment how it could be implemented quick and easy without making ReActor too heavy

xueqing0622 commented 1 month ago

same problem ,

KINGLIFER commented 1 month ago

I didnt post because for some reason he isnt responding to my posts. I respect it just do not know why. #281

Sorry for that my friend, I have no appropriate answer to your FR yet, I have no idea at the moment how it could be implemented quick and easy without making ReActor too heavy

Fair enough. I can replicate it but it is a few nodes extra. I get your point.

igrekun commented 4 weeks ago

@Gourieff The changes come from normalization range (0..1) for spandrel -1..1 for the previous patch.

In my stripped down reactor I have solved it like this

face_t = torch.from_numpy(face[:, :, ::-1] / 255.0).permute(2, 0, 1)
face_t = face_t.unsqueeze(0).float().to(device)

if restore_face:
    if isinstance(restorer, ModelBase):
        face_t: torch.Tensor = restorer(face_t) * 2 - 1 # spandrel renormalize
    elif isinstance(restorer, CodeFormer):
        face_t: torch.Tensor = restorer(face_t * 2 - 1, codeformer_weight)[0]
    else:
        raise ValueError("restorer model must be GFPGAN or CodeFormer")

Perhaps you could implement the same switch and renorm the range differently for spandrel models.

Best, Igor

tomgrad commented 3 weeks ago

https://github.com/Gourieff/comfyui-reactor-node/blob/467b50614e00002a9922141c33103a5ffec92d67/nodes.py#L270

Changing this one line does the trick.

output = facerestore_model(cropped_face_t, w=codeformer_weight)[0] if "codeformer" in face_restore_model.lower() else 2*facerestore_model((cropped_face_t+1)/2)[0]-1

We first change the range from (-1,1) to (0,1), do the restoration and go back to (-1,1). But only if the restorer is not codeformer.

Sorry for not doing it by proper PR, I suck at git.

grizwad commented 3 weeks ago

https://github.com/Gourieff/comfyui-reactor-node/commit/5480370d8dadec04ea0d70017843b130ca200c14

Here is a forked fixed version of nodes.py if you don't want to modify it yourself or want to wait for the official fix can confirm it works on latest comfy build. If you decide to update comfy through update all make sure you replace the node file each time as well. Thanks for the fix @tomgrad

Poukpalaova commented 3 weeks ago

https://github.com/Gourieff/comfyui-reactor-node/blob/467b50614e00002a9922141c33103a5ffec92d67/nodes.py#L270

Changing this one line does the trick.

output = facerestore_model(cropped_face_t, w=codeformer_weight)[0] if "codeformer" in face_restore_model.lower() else 2*facerestore_model((cropped_face_t+1)/2)[0]-1

We first change the range from (-1,1) to (0,1), do the restoration and go back to (-1,1). But only if the restorer is not codeformer.

Sorry for not doing it by proper PR, I suck at git.

This fix work like a charme. Many thanks

luisfcosta commented 3 weeks ago

5480370

Here is a forked fixed version of nodes.py if you don't want to modify it yourself or want to wait for the official fix can confirm it works on latest comfy build. If you decide to update comfy through update all make sure you replace the node file each time as well. Thanks for the fix @tomgrad

Hey thanks for the patch! The only thing I notice though, at least in my workflow, is that with this method (as oposed to reverting to ffc4b7c) the face restore node consistently produces blue colored eyes. I think all the colors get a bit more vivid.

grizwad commented 3 weeks ago

5480370 Here is a forked fixed version of nodes.py if you don't want to modify it yourself or want to wait for the official fix can confirm it works on latest comfy build. If you decide to update comfy through update all make sure you replace the node file each time as well. Thanks for the fix @tomgrad

Hey thanks for the patch! The only thing I notice though, at least in my workflow, is that with this method (as oposed to reverting to ffc4b7c) the face restore node consistently produces blue colored eyes. I think all the colors get a bit more vivid.

Yea I can see some of that in my pictures (over 400) that I have created since implementing it, however I have no idea what part of the coding would do with that, would need to be worked on by the developer, there is a slight underlying hint of blue being added to some of the pics where brown eyes turn out to be more hazel or green eyes turn out to be more blue. But the blur is gone lol.

KINGLIFER commented 3 weeks ago

5480370 Here is a forked fixed version of nodes.py if you don't want to modify it yourself or want to wait for the official fix can confirm it works on latest comfy build. If you decide to update comfy through update all make sure you replace the node file each time as well. Thanks for the fix @tomgrad

Hey thanks for the patch! The only thing I notice though, at least in my workflow, is that with this method (as oposed to reverting to ffc4b7c) the face restore node consistently produces blue colored eyes. I think all the colors get a bit more vivid.

Yea I can see some of that in my pictures (over 400) that I have created since implementing it, however I have no idea what part of the coding would do with that, would need to be worked on by the developer, there is a slight underlying hint of blue being added to some of the pics where brown eyes turn out to be more hazel or green eyes turn out to be more blue. But the blur is gone lol.

I would love to speak with you off site if possible. I would love to network with you with some of the work I have made. We are all busy so I am not asking for you to do any work. Just wanted to keep like minded users in my contact list.

XTRMsavage commented 3 weeks ago

https://github.com/Gourieff/comfyui-reactor-node/blob/467b50614e00002a9922141c33103a5ffec92d67/nodes.py#L270

Changing this one line does the trick.

output = facerestore_model(cropped_face_t, w=codeformer_weight)[0] if "codeformer" in face_restore_model.lower() else 2*facerestore_model((cropped_face_t+1)/2)[0]-1

We first change the range from (-1,1) to (0,1), do the restoration and go back to (-1,1). But only if the restorer is not codeformer.

Sorry for not doing it by proper PR, I suck at git.

How do I download this file ?

Thee-Meridan commented 3 weeks ago

"The Fix" does not satisfy or make whole :(

The colors are blown out as if you had CFG dialed up to a high number. I will try to mess with numbers, but this wasn't necessary in the past, of course.

tomgrad commented 3 weeks ago

I've checked the min-max ranges of the variables cropped_face_t and output (near the above-mentioned code line) and found something interesting. When restoring with GFPGAN, the ranges of both tensors are (-1,1) (after the fix). But with CF, I get different values for the output tensor. For example, (-0.99, 1.29) with weight=0.5 and (-1.03, 1.42) with weight=1. One of the values is always outside the (-1,1) range. So, the next line with tensor2img does the scaling differently for different restoration models. That is probably why you see some color shift (I don't; I'm a bit colorblind).

EDIT: Also, the output shapes from these two models are different. CF output is unsqueezed (1, 3, 512, 512) compared to (3, 512, 512) from GFPGAN. It probably has nothing to do with the problem, but it's another hint that the models are incompatible.

Gourieff commented 3 weeks ago

So guys, it should work fine now with this fix https://github.com/Gourieff/comfyui-reactor-node/commit/a7ae66912f80e8ccd97bb83bf83ab8187b077287

ILoveMoistCakes commented 2 weeks ago

So guys, it should work fine now with this fix a7ae669

Hi, how do you apply this fix? Because I uninstalled and reinstalled the node and still ran into the issue of "comfy_extras.chainner_models is deprecated and has been replaced by the spandrel library"

Gourieff commented 2 weeks ago

So guys, it should work fine now with this fix a7ae669

Hi, how do you apply this fix? Because I uninstalled and reinstalled the node and still ran into the issue of "comfy_extras.chainner_models is deprecated and has been replaced by the spandrel library"

Hi, 0.5.0 beta4 doesn't use "comfy_extras.chainner_models" any more, how did you reinstall ReActor? Via ComfyUI Manager or manually?

ILoveMoistCakes commented 2 weeks ago

Hi, how do you apply this fix? Because I uninstalled and reinstalled the node and still ran into the issue of "comfy_extras.chainner_models is deprecated and has been replaced by the spandrel library"

Hi, 0.5.0 beta4 doesn't use "comfy_extras.chainner_models" any more, how did you reinstall ReActor? Via ComfyUI Manager or manually?

I used the Manager to uninstall and reinstall, should I have done it manually instead?

XTRMsavage commented 2 weeks ago

Hi, how do you apply this fix? Because I uninstalled and reinstalled the node and still ran into the issue of "comfy_extras.chainner_models is deprecated and has been replaced by the spandrel library"

Hi, 0.5.0 beta4 doesn't use "comfy_extras.chainner_models" any more, how did you reinstall ReActor? Via ComfyUI Manager or manually?

I used the Manager to uninstall and reinstall, should I have done it manually instead?

Go to the link "So` guys, it should work fine now with this fix a7ae669" and download the files, then go to Reactor node folder inside comfy custom nodes and replace the original files with the new ones, restart and it should work.

ILoveMoistCakes commented 2 weeks ago

I used the Manager to uninstall and reinstall, should I have done it manually instead?

Go to the link "So` guys, it should work fine now with this fix a7ae669" and download the files, then go to Reactor node folder inside comfy custom nodes and replace the original files with the new ones, restart and it should work.

I don't see the option to just download those files, would going to the main page and download through zip work?

KINGLIFER commented 2 weeks ago

On a fresh install Comfy I saw new models downloaded for ReActor however it did not do that for a previous how to force a pull?

Gourieff commented 2 weeks ago

On a fresh install Comfy I saw new models downloaded for ReActor however it did not do that for a previous how to force a pull?

You can pick them from here https://huggingface.co/datasets/Gourieff/ReActor/tree/main/models/facerestore_models

XTRMsavage commented 2 weeks ago

I used the Manager to uninstall and reinstall, should I have done it manually instead?

Go to the link "So` guys, it should work fine now with this fix a7ae669" and download the files, then go to Reactor node folder inside comfy custom nodes and replace the original files with the new ones, restart and it should work.

I don't see the option to just download those files, would going to the main page and download through zip work?

Click the three dots on top right, then select view file, then once you go to that page, click download raw file.

ILoveMoistCakes commented 2 weeks ago

I don't see the option to just download those files, would going to the main page and download through zip work?

Click the three dots on top right, then select view file, then once you go to that page, click download raw file.

The issue still persists, I guess I'll just use the previous branch for now, thank you for replying o/

deadman3000 commented 2 weeks ago

I get the error too. I have reactor installed and running. I replaced all the 'fixed' .py files in the /comfyui-reactor-node/ folders. Still no joy. I don't get messed up generations like OP but this began after I tried using someone elses workflow and me trying to get it running involved installing reactor and a couple of other nodes plus forcefully installing insight face swap and some other things. I fixed everything to get working but now get this error about deprecated spandrel.

grizwad commented 2 weeks ago

I get the error too. I have reactor installed and running. I replaced all the 'fixed' .py files in the /comfyui-reactor-node/ folders. Still no joy. I don't get messed up generations like OP but this began after I tried using someone elses workflow and me trying to get it running involved installing reactor and a couple of other nodes plus forcefully installing insight face swap and some other things. I fixed everything to get working but now get this error about deprecated spandrel.

download https://github.com/Gourieff/sd-webui-extensions-updater/blob/main/update.bat and put it in your comfyui\custom_nodes folder and run it then restart comfyui once everything has been updated....

KINGLIFER commented 1 week ago

I didnt post because for some reason he isnt responding to my posts. I respect it just do not know why. #281

Sorry for that my friend, I have no appropriate answer to your FR yet, I have no idea at the moment how it could be implemented quick and easy without making ReActor too heavy

How about this. Is it possible to make a node that has a male and a female set of images like this and in the background it renders your saved safetensors into the faces you want and outputs them separately. The purpose is the node can be attached directly to ipadapters. 4 angles