Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR - Failed to swap face in postprocess method : apply_overlay() takes 3 positional arguments but 4 were given #178

Open
Fobbek opened this issue Mar 2, 2024 · 20 comments

Comments

@Fobbek
Copy link

Fobbek commented Mar 2, 2024

Getting this error when doing a basic faceswap: Not sure if there was an update to SD or a1111 but this same action worked a couple days ago.

2024-03-02 11:56:33,232 - FaceSwapLab - INFO - blend all faces together
2024-03-02 11:56:33,267 - FaceSwapLab - INFO - loading face Max.safetensors
2024-03-02 11:56:33,267 - FaceSwapLab - INFO - Int Gender : 0
2024-03-02 11:56:33,267 - FaceSwapLab - INFO - Process face 0
2024-03-02 11:56:33,275 - FaceSwapLab - INFO - Source Gender 0
2024-03-02 11:56:33,275 - FaceSwapLab - INFO - Target faces count : 1
2024-03-02 11:56:33,275 - FaceSwapLab - INFO - swap face 0
2024-03-02 11:56:34,283 - FaceSwapLab - INFO - ********************************************************************************
2024-03-02 11:56:34,323 - FaceSwapLab - INFO - Inswapper
2024-03-02 11:56:34,323 - FaceSwapLab - INFO - ********************************************************************************
2024-03-02 11:56:34,403 - FaceSwapLab - INFO - Finished processing image, return 1 images
2024-03-02 11:56:34,403 - FaceSwapLab - INFO - 1 images swapped
2024-03-02 11:56:34,403 - FaceSwapLab - ERROR - Failed to swap face in postprocess method : apply_overlay() takes 3 positional arguments but 4 were given
Traceback (most recent call last):
File "C:\a1111\stable-diffusion-webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab.py", line 201, in postprocess
swp_img = imgutils.apply_mask(swp_img, p, batch_index)
File "C:\a1111\stable-diffusion-webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab_utils\imgutils.py", line 224, in apply_mask
img = processing.apply_overlay(img, p.paste_to, batch_index, p.overlay_images)
TypeError: apply_overlay() takes 3 positional arguments but 4 were given

@sanora87
Copy link

sanora87 commented Mar 2, 2024

I've been messing with the settings since it popped up on me yesterday.
It seems to only occur when you have "Swap in generated image" ticked in i2i.

@cMoTp10
Copy link

cMoTp10 commented Mar 3, 2024

Massive failure, everyone is waiting for a solution.

There is a malfunction in i2i. If you uncheck:

  • Swap in source image (blended face)
  • Swap in generated image

But in a separate FaceSwapLab tab on the main panel, it works fine, but it's inconvenient.

@antorio
Copy link

antorio commented Mar 4, 2024

The error has to do with the updated processing.py modules in a1111.

In your faceswaplab's extension folder, find imgutils.py inside /faceswaplab_utils/ folder

go to line 224 or where it says:
img = processing.apply_overlay(img, p.paste_to, batch_index, p.overlay_images)

change it to:
if p.overlay_images and batch_index < len(p.overlay_images):
selected_overlay = p.overlay_images[batch_index]
img = processing.apply_overlay(img, p.paste_to, selected_overlay)
else:
return img
logger.debug("No overlay selected or overlay list is empty.")

See if it helps.


If anybody has another solution, please share

@cMoTp10
Copy link

cMoTp10 commented Mar 4, 2024

faceswaplab

This solution did not help. It gave an error and turned off the faceswaplab module.

@sanora87
Copy link

sanora87 commented Mar 5, 2024

Same. Get this error text

*** Error loading script: faceswaplab.py
Traceback (most recent call last):
File "C:\stable diffusion\webui\modules\scripts.py", line 527, in load_scripts
script_module = script_loading.load_module(scriptfile.path)
File "C:\stable diffusion\webui\modules\script_loading.py", line 10, in load_module
module_spec.loader.exec_module(module)
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab.py", line 10, in
from scripts.faceswaplab_api import faceswaplab_api
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab_api\faceswaplab_api.py", line 12, in
from scripts.faceswaplab_swapping import swapper
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab_swapping\swapper.py", line 21, in
from scripts.faceswaplab_swapping import upscaled_inswapper
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab_swapping\upscaled_inswapper.py", line 15, in
from scripts.faceswaplab_utils.imgutils import cv2_to_pil, pil_to_cv2
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab_utils\imgutils.py", line 225
selected_overlay = p.overlay_images[batch_index]
^
IndentationError: unindent does not match any outer indentation level #

Worth a shot though

@coder168
Copy link

coder168 commented Mar 7, 2024

The error has to do with the updated processing.py modules in a1111.

In your faceswaplab's extension folder, find imgutils.py inside /faceswaplab_utils/ folder

go to line 224 or where it says: img = processing.apply_overlay(img, p.paste_to, batch_index, p.overlay_images)

change it to: if p.overlay_images and batch_index < len(p.overlay_images): selected_overlay = p.overlay_images[batch_index] img = processing.apply_overlay(img, p.paste_to, selected_overlay) else: return img logger.debug("No overlay selected or overlay list is empty.")

See if it helps.

If anybody has another solution, please share

antorio's solution works for me.
I had the exactly same issue - After upgrade A1111 to v1.8.0, faecswaplab just throws the fore-mentioned error message and stop working under img2img.
I have manually applied the code changes as Antorio suggested, it works fine on v1.8.0 of A1111.
Antorio, THANKS!

@antorio
Copy link

antorio commented Mar 7, 2024

@sanora87 @cMoTp10 ,
make sure you write it in the right python indentation format. Don't just paste it down.
Screen Shot 2024-03-08 at 00 31 03

@cMoTp10
Copy link

cMoTp10 commented Mar 7, 2024

@sanora87 @cMoTp10 ,
make sure you write it in the right python indentation format. Don't just paste it down.

My friend, thank you very much. My problem really was in the indent.

I brought the code back to normal and everything worked out. You really helped me out. I am grateful!
imgutils py - Visual Studio Code_240307210658

@ali0une
Copy link

ali0une commented Mar 7, 2024

Many thanks @antorio!

@sanora87
Copy link

sanora87 commented Mar 8, 2024

i2i works now with that @antorio! Text2image is broke now but I'll survive without it. I don't think I used it much anyways.

Here's that error code if you wanted to see it regardless

2024-03-07 20:14:59,319 - FaceSwapLab - ERROR - Failed to post-process 'NoneType' object has no attribute 'copy'
Traceback (most recent call last):
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab_postprocessing\postprocessing.py", line 26, in enhance_image
result_image = upscale_img(result_image, pp_options)
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab_postprocessing\upscaling.py", line 13, in upscale_img
original_image: PILImage = image.copy()
AttributeError: 'NoneType' object has no attribute 'copy'
2024-03-07 20:14:59,321 - FaceSwapLab - INFO - Add swp image to processed
2024-03-07 20:14:59,321 - FaceSwapLab - ERROR - Failed to swap face in postprocess method : 'NoneType' object has no attribute 'height'
Traceback (most recent call last):
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab.py", line 216, in postprocess
save_image(
File "C:\stable diffusion\webui\modules\images.py", line 611, in save_image
if (image.height > 65535 or image.width > 65535) and extension.lower() in ("jpg", "jpeg") or (image.height > 16383 or image.width > 16383) and extension.lower() == "webp":
AttributeError: 'NoneType' object has no attribute 'height'

@ncandelier
Copy link

Hello,

i2i works now with that @antorio! Text2image is broke now but I'll survive without it. I don't think I used it much anyways.

Here's that error code if you wanted to see it regardless

2024-03-07 20:14:59,319 - FaceSwapLab - ERROR - Failed to post-process 'NoneType' object has no attribute 'copy'
Traceback (most recent call last):
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab_postprocessing\postprocessing.py", line 26, in enhance_image
result_image = upscale_img(result_image, pp_options)
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab_postprocessing\upscaling.py", line 13, in upscale_img
original_image: PILImage = image.copy()
AttributeError: 'NoneType' object has no attribute 'copy'
2024-03-07 20:14:59,321 - FaceSwapLab - INFO - Add swp image to processed
2024-03-07 20:14:59,321 - FaceSwapLab - ERROR - Failed to swap face in postprocess method : 'NoneType' object has no attribute 'height'
Traceback (most recent call last):
File "C:\stable diffusion\webui\extensions\sd-webui-faceswaplab\scripts\faceswaplab.py", line 216, in postprocess
save_image(
File "C:\stable diffusion\webui\modules\images.py", line 611, in save_image
if (image.height > 65535 or image.width > 65535) and extension.lower() in ("jpg", "jpeg") or (image.height > 16383 or image.width > 16383) and extension.lower() == "webp":
AttributeError: 'NoneType' object has no attribute 'height'

Facing this issue also in txt2img, hope there will be a fix soon.

Thanks

@jet3004
Copy link

jet3004 commented Mar 12, 2024

Thank you all! Took me forever to find this fix but glad it was posted. Hope T2I is fixed soon!

@ali0une
Copy link

ali0une commented Mar 12, 2024

@jet3004 look this issue 171 with the code below it fixed faceswaplab in both txt2img and img2img
/whatever/stable-diffusion-webui/extensions/sd-webui-faceswaplab/scripts/faceswaplab_utils/imgutils.py edited and at line 224 code is like this now :

#        img = processing.apply_overlay(img, p.paste_to, batch_index, p.overlay_images)
#        if p.color_corrections is not None and batch_index < len(p.color_corrections):
#            img = processing.apply_color_correction(
#                p.color_corrections[batch_index], img
#            )
#    return img
        if p.overlay_images and batch_index < len(p.overlay_images):
          selected_overlay = p.overlay_images[batch_index]
          img = processing.apply_overlay(img, p.paste_to, selected_overlay)
        else:
          return img
          logger.debug("No overlay selected or overlay list is empty.")

        if p.color_corrections is not None and batch_index < len(p.color_corrections):
            img = processing.apply_color_correction(
                p.color_corrections[batch_index], img
            )
    return img

@NotherGithubAccount
Copy link

FWIW, I came here with the same problem - first time user. Then found Reactor does exactly what I need and works. It's available as a direct install from the A1111 extensions menu.

@antorio
Copy link

antorio commented Mar 14, 2024

FWIW, I came here with the same problem - first time user. Then found Reactor does exactly what I need and works. It's available as a direct install from the A1111 extensions menu.

IMO, in context of face similarity with source images, Reactor doesn't render nearly as good as faceswaplab.

@jaesimio
Copy link

jaesimio commented Mar 19, 2024

@antorio @ncandelier, @jet3004,

The return value of processing.apply_overlay() differs between sd-webui:v1.7.0 and sd-webui:v1.8.0.

Therefore, we need to make the following changes:

        if p.overlay_images and batch_index < len(p.overlay_images):
            selected_overlay = p.overlay_images[batch_index]
            img, _ = processing.apply_overlay(img, p.paste_to, selected_overlay)
#                ^
#                this
        else:
            logger.debug("No overlay selected or overlay list is empty.")
            return img

Now img2img(inpaint) and txt2img is work.


apply_overlay() function's return value in v1.7.0:

return image

apply_overlay() function's return value in v1.8.0:

return image, original_denoised_image

The error has to do with the updated processing.py modules in a1111.

In your faceswaplab's extension folder, find imgutils.py inside /faceswaplab_utils/ folder

go to line 224 or where it says: img = processing.apply_overlay(img, p.paste_to, batch_index, p.overlay_images)

change it to: if p.overlay_images and batch_index < len(p.overlay_images): selected_overlay = p.overlay_images[batch_index] img = processing.apply_overlay(img, p.paste_to, selected_overlay) else: return img logger.debug("No overlay selected or overlay list is empty.")

See if it helps.

If anybody has another solution, please share

@TylerBizz
Copy link

The error has to do with the updated processing.py modules in a1111.

In your faceswaplab's extension folder, find imgutils.py inside /faceswaplab_utils/ folder

go to line 224 or where it says: img = processing.apply_overlay(img, p.paste_to, batch_index, p.overlay_images)

change it to: if p.overlay_images and batch_index < len(p.overlay_images): selected_overlay = p.overlay_images[batch_index] img = processing.apply_overlay(img, p.paste_to, selected_overlay) else: return img logger.debug("No overlay selected or overlay list is empty.")

See if it helps.

If anybody has another solution, please share

Thank you - this worked for me.

@qq294922436
Copy link

3Q

amartailor01 added a commit to amartailor01/stable-diffusion-webui-stable-horde that referenced this issue Apr 16, 2024
Edited code as per fix here:
glucauze/sd-webui-faceswaplab#178
Issue with code due to update in auto1111, extension not updated as archived.
Code not identical to fix in issue linked, some manual work done, to ffully test.
@ayahanda
Copy link

ayahanda commented Jun 18, 2024

hi , i have this error .. using latest A1111 v1.9

i already change code from antorio . still not fix

edit : ok working now , i forget to follow python code format .
cant just copy paste , have to follow code format to make it working

@teamjla
Copy link

teamjla commented Jun 24, 2024

Hi There, I have the same problem on Sd v1.9.4. Below is what i have changed. Still having an issue. please help as I dont want to use reactor :)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests