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

Closed
opened 2024-02-17 22:07:04 +01:00 by ali0une · 21 comments
ali0une commented 2024-02-17 22:07:04 +01:00 (Migrated from github.com)

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):

  • OS: Debian 12
  • Browser Firefox
  • Version 122.0.1

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

**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](https://github.com/lllyasviel/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" 7. 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):** - OS: Debian 12 - Browser Firefox - Version 122.0.1 **Additional context** Works 100% in [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui).
aarony1993 commented 2024-02-18 12:53:41 +01:00 (Migrated from github.com)

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

Same here in Automatic1111 [v1.8.0-RC-4-gc7808825](https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/c7808825b12cc5591012b50d93f27e4bce99ec5c)
DDanDee commented 2024-02-27 20:47:05 +01:00 (Migrated from github.com)

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

Exactly the same. The only difference is the OS is Win 10 for me
buzzz3d commented 2024-02-28 20:37:33 +01:00 (Migrated from github.com)

Only happens in img2img for me

Only happens in img2img for me
ali0une commented 2024-03-02 09:08:59 +01:00 (Migrated from github.com)

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

issue on stable-diffusion-webui-forge [FaceSwapLab support #274](https://github.com/lllyasviel/stable-diffusion-webui-forge/issues/274)
AI-Ilikeit commented 2024-03-02 16:47:54 +01:00 (Migrated from github.com)

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

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 2024-03-02 19:10:20 +01:00 (Migrated from github.com)

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.

> 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)](https://github.com/lllyasviel/stable-diffusion-webui-forge/issues/274#issuecomment-1974829006) 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 2024-03-02 21:48:09 +01:00 (Migrated from github.com)

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

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 2024-03-02 22:30:05 +01:00 (Migrated from github.com)

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.

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 2024-03-02 22:34:34 +01:00 (Migrated from github.com)

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

> 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 2024-03-02 22:45:22 +01:00 (Migrated from github.com)

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.

> > 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 2024-03-07 18:38:30 +01:00 (Migrated from github.com)

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

Check my alternative solution in another thread of the same topic -> #178 Works for me on a1111 1.8.0
ali0une commented 2024-03-07 19:12:00 +01:00 (Migrated from github.com)

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.")
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 2024-03-07 19:13:12 +01:00 (Migrated from github.com)

fixed for now!

fixed for now!
ali0une commented 2024-03-10 09:22:01 +01:00 (Migrated from github.com)

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'>

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 2024-03-10 09:27:28 +01:00 (Migrated from github.com)

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
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 2024-03-10 16:10:04 +01:00 (Migrated from github.com)

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

for me doesnt work ... after edit the file, same issue ... hopfully wait for an update ;)
ali0une commented 2024-03-10 20:39:52 +01:00 (Migrated from github.com)

@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
@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 2024-07-10 05:35:33 +02:00 (Migrated from github.com)

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.

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 2024-07-10 09:40:16 +02:00 (Migrated from github.com)

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

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
JonSingleton commented 2024-08-13 23:50:02 +02:00 (Migrated from github.com)

looks like an update changed processing.py (stablediffusionfolder\modules\processing.py) and changed apply_overlay to accept 3 arguments and faceswaplabs hasn't been updated to use the new function in img2img (though it's updated elsewhere).

Rather than going through to see how to set up the args properly I just swapped in the old apply_overlay right under the new one in stablediffusionfolder\modules\processing.py and changed it to apply_overlay_legacy and then in extensions\sd-webui-faceswaplab\scripts\faceswaplab_utils\imgutils.py I modified it to reference the new _legacy function.

Under the apply_overlay function (around line 90, pasted this
`def apply_overlay_legacy(image, paste_loc, index, overlays):
if overlays is None or index >= len(overlays):
return image

overlay = overlays[index]

if paste_loc is not None:
    x, y, w, h = paste_loc
    base_image = Image.new('RGBA', (overlay.width, overlay.height))
    image = images.resize_image(1, image, w, h)
    base_image.paste(image, (x, y))
    image = base_image

image = image.convert('RGBA')
image.alpha_composite(overlay)
image = image.convert('RGB')

return image`

Then modified extensions\sd-webui-faceswaplab\scripts\faceswaplab_utils\imgutils.py line 224 to this:
img = processing.apply_overlay_legacy(img, p.paste_to, batch_index, p.overlay_images)

ymmv but seems to work for me.

looks like an update changed processing.py (stablediffusionfolder\modules\processing.py) and changed apply_overlay to accept 3 arguments and faceswaplabs hasn't been updated to use the new function in img2img (though it's updated elsewhere). Rather than going through to see how to set up the args properly I just swapped in the old apply_overlay right under the new one in stablediffusionfolder\modules\processing.py and changed it to apply_overlay_legacy and then in extensions\sd-webui-faceswaplab\scripts\faceswaplab_utils\imgutils.py I modified it to reference the new _legacy function. Under the apply_overlay function (around line 90, pasted this `def apply_overlay_legacy(image, paste_loc, index, overlays): if overlays is None or index >= len(overlays): return image overlay = overlays[index] if paste_loc is not None: x, y, w, h = paste_loc base_image = Image.new('RGBA', (overlay.width, overlay.height)) image = images.resize_image(1, image, w, h) base_image.paste(image, (x, y)) image = base_image image = image.convert('RGBA') image.alpha_composite(overlay) image = image.convert('RGB') return image` Then modified extensions\sd-webui-faceswaplab\scripts\faceswaplab_utils\imgutils.py line 224 to this: ` img = processing.apply_overlay_legacy(img, p.paste_to, batch_index, p.overlay_images) ` ymmv but seems to work for me.
wittywolk commented 2025-04-05 02:53:07 +02:00 (Migrated from github.com)

@JonSingleton solution works; just be careful with the spacing - his code block got broken in the comment.

https://pastebin.com/8EaZvpTr - it should look like this, at least I think so because it works

@JonSingleton solution works; just be careful with the spacing - his code block got broken in the comment. https://pastebin.com/8EaZvpTr - it should look like this, at least I think so because it works
Sign in to join this conversation.