Bing-su / adetailer

Auto detecting, masking and inpainting with detection model.
GNU Affero General Public License v3.0
4.15k stars 317 forks source link

[Bug]: Adetailer passing two times with one request in API #485

Closed raphaelreisb closed 6 months ago

raphaelreisb commented 9 months ago

I'm sending the following JSON:

{ "prompt": " ,masterpiece, best quality, 8k, best composition, highres,dragon ball, blmlong, aqua hair, blunt bangs, long hair, playboy bunny, rabbit ears, black pantyhose, red bowtie, wrist cuffs, black leotard, large breasts, <lora:bulma_v1:0.9>, ", "negative_prompt": "nsfw, FastNegativeV2", "steps": 20, "sampler_index": "DPM++ 2M Karras", "width": 512, "height": 768, "cfg_scale": 7, "seed": -1, "batch_size": 1, "alwayson_scripts": { "ADetailer": { "args": [ { "ad_model": "face_yolov8n.pt", "ad_negative_prompt": "", "ad_confidence": 0.3, "ad_mask_min_ratio": 0, "ad_mask_max_ratio": 1, "ad_dilate_erode": 32, "ad_x_offset": 0, "ad_y_offset": 0, "ad_mask_merge_invert": "None", "ad_mask_blur": 4, "ad_denoising_strength": 0.6, "ad_inpaint_only_masked": true, "ad_inpaint_only_masked_padding": 0, "ad_use_inpaint_width_height": false, "ad_inpaint_width": 512, "ad_inpaint_height": 512, "ad_use_steps": false, "ad_steps": 15, "ad_use_cfg_scale": false, "ad_cfg_scale": 7, "ad_restore_face": false, "ad_controlnet_model": "None", "ad_controlnet_weight": 1, "ad_controlnet_guidance_start": 0, "ad_controlnet_guidance_end": 1 } ] } } }

And for some reason the Face detection and model execution is happening twice, with different steps:

image

This also occurs passing only the model as arg:

"ad_model": "face_yolov8n.pt"

This is not occurring when using Adetailer via the WebUI, only when requested via the API

Screenshots

No response

Console logs, from start to end.

Python 3.10.9 | packaged by conda-forge | (main, Feb  2 2023, 20:20:04) [GCC 11.3.0]
Version: v1.7.0
Commit hash: cf2772fab0af5573da775e7437e6acdca424f26e
Launching Web UI with arguments: --xformers --opt-channelslast --api --port 35000 --listen --enable-insecure-extension-access
[-] ADetailer initialized. version: 24.1.1, num models: 9
CivitAI Browser+: Aria2 RPC started
ControlNet preprocessor location: /home/ubuntu/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/downloads
2024-01-22 23:31:06,066 - ControlNet - INFO - ControlNet v1.1.433
2024-01-22 23:31:06,193 - ControlNet - INFO - ControlNet v1.1.433
Loading weights [ef49fbb25f] from /home/ubuntu/stable-diffusion-webui/models/Stable-diffusion/anyloraCheckpoint_bakedvaeBlessedFp16.safetensors
2024-01-22 23:31:07,074 - ControlNet - INFO - ControlNet UI callback registered.
Running on local URL:  http://0.0.0.0:35000

To create a public link, set `share=True` in `launch()`.
Startup time: 10.0s (prepare environment: 1.9s, import torch: 2.3s, import gradio: 0.8s, setup paths: 1.2s, initialize shared: 0.2s, other imports: 0.6s, load scripts: 1.7s, create ui: 0.9s, gradio launch: 0.2s).
Creating model from config: /home/ubuntu/stable-diffusion-webui/configs/v1-inference.yaml
Applying attention optimization: xformers... done.
Model loaded in 3.4s (load weights from disk: 1.2s, create model: 0.4s, apply weights to model: 1.6s).
100%|███████████████████████████████████████████████████████████████████████████████████| 20/20 [00:06<00:00,  3.07it/s]
Total progress: 100%|███████████████████████████████████████████████████████████████████| 20/20 [00:04<00:00,  4.48it/s]
0: 640x448 1 face, 48.1ms
Speed: 2.1ms preprocess, 48.1ms inference, 5.1ms postprocess per image at shape (1, 3, 640, 448)
100%|███████████████████████████████████████████████████████████████████████████████████| 13/13 [00:02<00:00,  4.47it/s]

0: 640x448 1 face, 5.1ms
Speed: 1.7ms preprocess, 5.1ms inference, 0.9ms postprocess per image at shape (1, 3, 640, 448)
100%|█████████████████████████████████████████████████████████████████████████████████████| 9/9 [00:02<00:00,  4.48it/s]
Total progress: 100%|███████████████████████████████████████████████████████████████████| 20/20 [00:14<00:00,  1.34it/s]
100%|███████████████████████████████████████████████████████████████████████████████████| 20/20 [00:04<00:00,  4.45it/s]
Total progress: 100%|███████████████████████████████████████████████████████████████████| 20/20 [00:04<00:00,  4.45it/s]
0: 640x448 1 face, 5.1ms
Speed: 1.7ms preprocess, 5.1ms inference, 0.9ms postprocess per image at shape (1, 3, 640, 448)
100%|███████████████████████████████████████████████████████████████████████████████████| 13/13 [00:02<00:00,  4.44it/s]

0: 640x448 1 face, 5.1ms
Speed: 1.6ms preprocess, 5.1ms inference, 1.0ms postprocess per image at shape (1, 3, 640, 448)
100%|█████████████████████████████████████████████████████████████████████████████████████| 9/9 [00:02<00:00,  4.44it/s]
Total progress: 100%|███████████████████████████████████████████████████████████████████| 20/20 [00:12<00:00,  1.63it/s]
Total progress: 100%|███████████████████████████████████████████████████████████████████| 20/20 [00:12<00:00,  4.45it/s]

List of installed extensions

No response

iladrien-hub commented 9 months ago

It's the same for me.

I provide an empty array of arguments - everything is fine, nothing happens. When passing an array of length N, Adetailer is executed N+1 times.

For example, my standard request looks something like this:

{
    "alwayson_scripts": {
        "ADetailer": {
            "args": [
                {
                    "ad_mask_k_largest": 1,
                    "ad_model": "face_yolov8n.pt",
                    "ad_denoising_strength": 0.45,
                    "ad_use_checkpoint": true,
                    "ad_checkpoint": "animerge_v23.safetensors [815ec91b56]",
                    "ad_use_inpaint_width_height": true,
                    "ad_inpaint_width": 768,
                    "ad_inpaint_height": 768
                },
                {
                    "ad_mask_k_largest": 1,
                    "ad_model": "face_yolov8n.pt",
                    "ad_denoising_strength": 0.35,
                    "ad_prompt": "(best quality, masterpiece, perfect face, ultra realistic, perfect skin), red eyes, smile",
                    "ad_use_checkpoint": true,
                    "ad_checkpoint": "animerge_v23.safetensors [815ec91b56]",
                    "ad_use_inpaint_width_height": true,
                    "ad_inpaint_width": 768,
                    "ad_inpaint_height": 768
                }
            ]
        }
    }
}

However, during the generation, a third Adetailer appears, which I did not ask for:

ADetailer model: face_yolov8n.pt, ADetailer confidence: 0.3, ADetailer mask only top k largest: 1, ADetailer dilate erode: 4, ADetailer mask blur: 4, ADetailer denoising strength: 0.45, ADetailer inpaint only masked: True, ADetailer inpaint padding: 32, ADetailer use inpaint width height: True, ADetailer inpaint width: 768, ADetailer inpaint height: 768, ADetailer use separate checkpoint: True, ADetailer checkpoint: animerge_v23.safetensors [815ec91b56], 
ADetailer model 2nd: face_yolov8n.pt, ADetailer prompt 2nd: "(best quality, masterpiece, perfect face, ultra realistic, perfect skin), red eyes, smile", ADetailer confidence 2nd: 0.3, ADetailer mask only top k largest 2nd: 1, ADetailer dilate erode 2nd: 4, ADetailer mask blur 2nd: 4, ADetailer denoising strength 2nd: 0.35, ADetailer inpaint only masked 2nd: True, ADetailer inpaint padding 2nd: 32, ADetailer use inpaint width height 2nd: True, ADetailer inpaint width 2nd: 768, ADetailer inpaint height 2nd: 768, ADetailer use separate checkpoint 2nd: True, ADetailer checkpoint 2nd: animerge_v23.safetensors [815ec91b56], 
ADetailer model 3rd: face_yolov8n.pt, ADetailer confidence 3rd: 0.3, ADetailer dilate erode 3rd: 4, ADetailer mask blur 3rd: 4, ADetailer denoising strength 3rd: 0.4, ADetailer inpaint only masked 3rd: True, ADetailer inpaint padding 3rd: 32, 
ADetailer version: 24.1.2
raphaelreisb commented 9 months ago

I downgraded to version 23.11.0 and it is working perfectly, without the "double execution". I'll stay on this version until they fix the current one, I recommend you do the same :)

bigmover commented 8 months ago

I downgraded to version 23.11.0 and it is working perfectly, without the "double execution". I'll stay on this version until they fix the current one, I recommend you do the same :)

The bug is solved now or figure out where the problem is? I also came to it when I update the extension.

bigmover commented 8 months ago

I downgraded to version 23.11.0 and it is working perfectly, without the "double execution". I'll stay on this version until they fix the current one, I recommend you do the same :)

Would you mind to figure out that which commit id version 23.11.0 refers to?

iladrien-hub commented 8 months ago

I downgraded to version 23.11.0 and it is working perfectly, without the "double execution". I'll stay on this version until they fix the current one, I recommend you do the same :)

Would you mind to figure out that which commit id version 23.11.0 refers to?

https://github.com/Bing-su/adetailer/commit/6b41b3db0fe22af60b8b35d0939380b141bf3eb3

Axelleromar commented 7 months ago

Has this not been fixed yet?

wildwindfeng commented 7 months ago

I found the possible reason that caused by omitted the beggining "true, false" for "ad_enable" and "skip_img2img" parameters of API call. Althrough the wiki instructed these two initial parameters can be removed, but if you do, there would be always have "face" model loaded by default.