glucauze / sd-webui-faceswaplab

Extended faceswap extension for StableDiffusion web-ui with multiple faceswaps, inpainting, checkpoints, ....
https://glucauze.github.io/sd-webui-faceswaplab/
GNU Affero General Public License v3.0
707 stars 92 forks source link

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

Closed ali0une closed 4 months ago

ali0une commented 4 months ago

Please remember that the bug report section is not a forum. Before submitting a bug, ensure you have read the FAQ thoroughly. This helps us maintain an efficient bug tracking process. Thank you for your understanding and cooperation. Use the discussion section for anything else.

Describe the bug Using stable-diffusion-webui-forge face is not swapped and error in the title is shown in the terminal :

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 "/whatever/stable-diffusion-webui-forge/extensions/sd-webui-faceswaplab/scripts/faceswaplab.py", line 201, in postprocess
    swp_img = imgutils.apply_mask(swp_img, p, batch_index)
  File "/whatever/stable-diffusion-webui-forge/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

To Reproduce Steps to reproduce the behavior:

  1. install stable-diffusion-webui-forge
  2. install extension
  3. use extension : add an image of any face, enable, check "Swap in generated image",
  4. in "Post-Processing & Advanced Mask Options" select "Codeformer", Upscaler LDSR, check Use improved segmented mask (use pastenet to mask only the face) + Use color corrections + sharpen face,
  5. in "Post-Inpainting (After swapping)" set Denoising strenght; select Inpainting Sampler, select sd model (experimental) "Current"
  6. face is not swapped, error in the title shown in the terminal.

Expected behavior face is swapped, no error.

Screenshots none

Desktop (please complete the following information):

Additional context Works 100% in stable-diffusion-webui.

aarony1993 commented 4 months ago

Same here in Automatic1111 v1.8.0-RC-4-gc7808825

DDanDee commented 4 months ago

Exactly the same. The only difference is the OS is Win 10 for me

buzzz3d commented 4 months ago

Only happens in img2img for me

ali0une commented 4 months ago

issue on stable-diffusion-webui-forge FaceSwapLab support #274

AI-Ilikeit commented 4 months ago

i did get this to work by checking swap in source face (blended face) and removing the next checkbox.

https://github.com/lllyasviel/stable-diffusion-webui-forge/issues/274#issuecomment-1974829006

ChrisTello commented 4 months ago

i did get this to work by checking swap in source face (blended face) and removing the next checkbox.

lllyasviel/stable-diffusion-webui-forge#274 (comment)

yeah this works but that isnt the problem, i think they are trying to use the other option which switches the face after the generation.

ncandelier commented 4 months ago

Facing the same issue with img2img after recent update today

Traceback (most recent call last): File "D:\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 "D:\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 commented 4 months ago

After messing with all the settings over and over again, it only happens when you have "Swap in generated image" ticked in i2i. I don't know anything about programming so I'm hoping someone or the dev fixes this soon.

ncandelier commented 4 months ago

After messing with all the settings over and over again, it only happens when you have "Swap in generated image" ticked in i2i. I don't know anything about programming so I'm hoping someone or the dev fixes this soon.

yes, you need to check the first option "Swap in source image (blended face)" to make it work, but rendering is a bit different

sanora87 commented 4 months ago

After messing with all the settings over and over again, it only happens when you have "Swap in generated image" ticked in i2i. I don't know anything about programming so I'm hoping someone or the dev fixes this soon.

yes, you need to check the first option "Swap in source image (blended face)" to make it work, but rendering is a bit different

Rendering is different but, from what I've noticed, is terribly inaccurate compared to just using the "swap in generated image" tick. A couple days ago it worked fine - now not so much.

In the interim, I've just been using the dedicated faceswaplab tab. My work flow has changed to "finish everything but that" and then just do the rest from there.

antorio commented 4 months ago

Check my alternative solution in another thread of the same topic -> #178 Works for me on a1111 1.8.0

ali0une commented 4 months ago

Many thanks @antorio looks like it just works!

changes in /whatever/stable-diffusion-webui/extensions/sd-webui-faceswaplab/scripts/faceswaplab_utils/imgutils.py

#        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.")
ali0une commented 4 months ago

fixed for now!

ali0une commented 4 months ago

The fix above only works in the img2img tab. in txt2txt tab faceswaplab is still broken.

2024-03-10 09:13:42,621 - FaceSwapLab - INFO - Try to use model : /whatever/stable-diffusion-webui/models/faceswaplab/inswapper_128.onnx
2024-03-10 09:13:42,624 - FaceSwapLab - INFO - Load analysis model det_size=(640, 640), det_thresh=0.5, providers = ['CPUExecutionProvider'], will take some time. (> 30s)
Loading (640, 640) analysis model (first time is slow): 100%|████████████████████████████████████| 1/1 [00:00<00:00,  2.78model/s]
2024-03-10 09:13:42,984 - FaceSwapLab - INFO - ("Applied providers: ['CPUExecutionProvider'], with options: "
 "{'CPUExecutionProvider': {}}\n"
 'find model: '
 '/whatever/stable-diffusion-webui/models/faceswaplab/analysers/models/buffalo_l/1k3d68.onnx '
 "landmark_3d_68 ['None', 3, 192, 192] 0.0 1.0\n"
 "Applied providers: ['CPUExecutionProvider'], with options: "
 "{'CPUExecutionProvider': {}}\n"
 'find model: '
 '/whatever/stable-diffusion-webui/models/faceswaplab/analysers/models/buffalo_l/2d106det.onnx '
 "landmark_2d_106 ['None', 3, 192, 192] 0.0 1.0\n"
 "Applied providers: ['CPUExecutionProvider'], with options: "
 "{'CPUExecutionProvider': {}}\n"
 'find model: '
 '/whatever/stable-diffusion-webui/models/faceswaplab/analysers/models/buffalo_l/det_10g.onnx '
 "detection [1, 3, '?', '?'] 127.5 128.0\n"
 "Applied providers: ['CPUExecutionProvider'], with options: "
 "{'CPUExecutionProvider': {}}\n"
 'find model: '
 '/whatever/stable-diffusion-webui/models/faceswaplab/analysers/models/buffalo_l/genderage.onnx '
 "genderage ['None', 3, 96, 96] 0.0 1.0\n"
 "Applied providers: ['CPUExecutionProvider'], with options: "
 "{'CPUExecutionProvider': {}}\n"
 'find model: '
 '/whatever/stable-diffusion-webui/models/faceswaplab/analysers/models/buffalo_l/w600k_r50.onnx '
 "recognition ['None', 3, 112, 112] 127.5 127.5\n"
 'set det-size: (640, 640)\n')
2024-03-10 09:13:43,183 - FaceSwapLab - INFO - blend all faces together
2024-03-10 09:13:43,393 - FaceSwapLab - INFO - Int Gender : 0
2024-03-10 09:13:43,393 - FaceSwapLab - INFO - Process face 0
2024-03-10 09:13:43,394 - FaceSwapLab - INFO - Source Gender 0
Loading swap model: 100%|████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.09model/s]
2024-03-10 09:13:43,874 - FaceSwapLab - INFO - ("Applied providers: ['CPUExecutionProvider'], with options: "
 "{'CPUExecutionProvider': {}}\n"
 'inswapper-shape: [1, 3, 128, 128]\n')
2024-03-10 09:13:43,874 - FaceSwapLab - INFO - Target faces count : 1
2024-03-10 09:13:43,874 - FaceSwapLab - INFO - swap face 0
2024-03-10 09:13:44,327 - FaceSwapLab - INFO - ********************************************************************************
2024-03-10 09:13:44,327 - FaceSwapLab - INFO - Inswapper
2024-03-10 09:13:44,329 - FaceSwapLab - INFO - Upscale with LDSR scale = 4
Loading model from /whatever/stable-diffusion-webui/models/LDSR/model.ckpt
LatentDiffusionV1: Running in eps-prediction mode
Keeping EMAs of 308.
Applying attention optimization: xformers... done.
Down sample rate is 1 from 4 / 4 (Not downsampling)
Plotting: Switched to EMA weights
Sampling with eta = 1.0; steps: 100
Data shape for DDIM sampling is (1, 3, 128, 128), eta 1.0
Running DDIM Sampling with 100 timesteps
DDIM Sampler: 100%|█████████████████████████████████████████████████████████████████████████████| 100/100 [00:05<00:00, 19.56it/s]
Plotting: Restored training weights
2024-03-10 09:13:53,058 - FaceSwapLab - INFO - Restore face with CodeFormer
2024-03-10 09:13:54,377 - FaceSwapLab - INFO - sharpen
2024-03-10 09:13:54,378 - FaceSwapLab - INFO - color correction
2024-03-10 09:13:54,566 - FaceSwapLab - INFO - improved_mask
2024-03-10 09:13:54,821 - FaceSwapLab - INFO - ********************************************************************************
2024-03-10 09:13:54,844 - FaceSwapLab - INFO - Inpainting face
Sampler : DPM++ 3M SDE Karras
inpainting_denoising_strength : 0.16
inpainting_steps : 32

2024-03-10 09:13:54,844 - FaceSwapLab - INFO - send faces to image to image
2024-03-10 09:13:54,859 - FaceSwapLab - INFO - Denoising prompt : Portrait of a woman
2024-03-10 09:13:54,859 - FaceSwapLab - INFO - Denoising strenght : 0.16
100%|███████████████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:04<00:00,  1.21it/s]
2024-03-10 09:14:02,567 - FaceSwapLab - INFO - Finished processing image, return 1 images                                         
2024-03-10 09:14:02,567 - FaceSwapLab - INFO - 1 images swapped
2024-03-10 09:14:02,567 - FaceSwapLab - INFO - Add swp image to processed
Total progress: 38it [00:44,  1.17s/it]
Traceback (most recent call last):s/it]
  File "/whatever/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "/whatever/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1434, in process_api
    data = self.postprocess_data(fn_index, result["prediction"], state)
  File "/whatever/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1335, in postprocess_data
    prediction_value = block.postprocess(prediction_value)
  File "/whatever/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/components/gallery.py", line 205, in postprocess
    raise ValueError(f"Cannot process type as image: {type(img)}")
ValueError: Cannot process type as image: <class 'NoneType'>
ncandelier commented 4 months ago

Fixed for me in Txt2img also in imgutils.py check the line ident and just quote this line :

# img = processing.apply_overlay(img, p.paste_to, batch_index, p.overlay_images)

Your code should look like :

#        img = processing.apply_overlay(img, p.paste_to, batch_index, p.overlay_images)
        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
kalle07 commented 4 months ago

for me doesnt work ... after edit the file, same issue ... hopfully wait for an update ;)

ali0une commented 4 months ago

@ncandelier many thanks! Works in txtimg and img2img now.

/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
thesneakyk0ala commented 1 day ago

Hey, I am still having this issue in July 2024 using auto 1111. I just installed a few days ago from the install from URL. Was there ever a definitive solution? I know that it was marked completed, but I still have it.

2024-07-09 23:29:53,819 - 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 "D:\Stable Diffusion\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 "D:\Stable Diffusion\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

It works most of the time in txt2img, but this is a dissapointing bug as img to img with inpainting is useful.

kalle07 commented 1 day ago

use sd-webui-reactor .. all working fine (same base programmig) https://github.com/Gourieff/sd-webui-reactor

read my article for even better faces ;)

https://civitai.com/articles/5002/face-swap-with-adetailer-and-reactor