Bing-su / adetailer

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

[Bug]: Latest commit on dev broke control net #385

Closed Poiuytrezay1 closed 10 months ago

Poiuytrezay1 commented 10 months ago

Describe the bug

Activate control net with adetailer results in error. On a side note, I have no idea why A1111 binds adetailer to the dev branch, but it might be good to change it to main by default (it causes the auto-update to retrieve bugs like this one potentially).

Screenshots

No response

Console logs, from start to end.

adetailer\controlnet_ext\controlnet_ext.py:81 in update_scripts_args

AttributeError: 'StableDiffusionProcessingImg2Img' object has no attribute 'script_args_value'

List of installed extensions

No response

xarathos517 commented 10 months ago

Having what I can only assume is a similar or the same issue on SD.Next, but neither the main nor dev version of the extension seems to fix it. ADetailer works if its controlnet option is set to 'none,' but any other choice from the dropdown gives me an error and causes the ADetailer step to skip entirely.

log.txt

fxwz commented 10 months ago

I don't know if this is the same bug, but something broke in the last couple days for me too. Since then i just get an error when running any controlnet in ADetailer.

Also, I have absolutely no idea what I'm doing, but I was able to get it working with a 1 line "hack". I don't know what we break by doing that, but something will probably be bricked since we are skipping some lines of code.

Anyways, here's the "hack" if anyone wants to try it: You have to edit a file in a text editor. The file is called "external_code.py" and is located in this folder: ...\extensions\sd-webui-controlnet\internal_controlnet\

On line 369 we insert a new line with the statement "return", so the code now looks like this:

...
cn_script_args_diff = 0
return
for script in script_runner.alwayson_scripts:
...

That's it. Like I said it probably breaks something else but I figure I would share it. Haven't noticed any other side effects YET.

edit: only tested in text2img btw

mvanzorn commented 10 months ago

Anyways, here's the "hack" if anyone wants to try it: You have to edit a file in a text editor. The file is called "external_code.py" and is located in this folder: ...\extensions\sd-webui-controlnet\internal_controlnet\

On line 369 we insert a new line with the statement "return", so the code now looks like this:

...
cn_script_args_diff = 0
return
for script in script_runner.alwayson_scripts:
...

That's it. Like I said it probably breaks something else but I figure I would share it. Haven't noticed any other side effects YET.

edit: only tested in text2img btw

Same failures here recently. I have installed Automatic1111 from scratch with nothing but ControlNet and !ADetailer and it bombs every time.

@fxwz - Interesting bypass surgery there :) I tried it on a laptop sporting a GTX 1080 w/8GB RAM. After the hack, Adetailer no longer respected the max models limit setting, and attempted to identify all faces in an image throw a CUDA error: out of memory. But at least with your hack it tried to execute.

The ADetailer error I see every time (prior to trying the hack above): * Error running postprocess_image: D:\Tools\stable-diffusion-webui\extensions\adetailer\scripts!adetailer.py.05s/it] Traceback (most recent call last): File "D:\Tools\stable-diffusion-webui\modules\scripts.py", line 675, in postprocess_image script.postprocess_image(p, pp, script_args) File "D:\Tools\stable-diffusion-webui\extensions\adetailer\adetailer\traceback.py", line 159, in wrapper raise error from None TypeError: ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ System info │ │ ┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ Platform │ Windows-10-10.0.22621-SP0 │ │ │ │ Python │ 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] │ │ │ │ Version │ v1.6.0 │ │ │ │ Commit │ 5ef669de080814067961f28357256e8fe27544f4 │ │ │ │ Commandline │ ['launch.py', '--api', '--xformers', '--no-half-vae', '--medvram', │ │ │ │ │ '--opt-sdp-no-mem-attention', '--disable-nan-check', '--autolaunch', │ │ │ │ │ '--cors-allow-origins=http://127.0.0.1:7860/'] │ │ │ │ Libraries │ {'torch': '2.0.1+cu118', 'torchvision': '0.15.2+cu118', 'ultralytics': '8.0.202', 'mediapipe': │ │ │ │ │ '0.10.7'} │ │ │ └─────────────┴────────────────────────────────────────────────────────────────────────────────────────────────┘ │ │ Inputs │ │ ┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │
│ │ n_iter │ 8 │ │ │ │ batch_size │ 1 │ │ │ │ width │ 1536 │ │ │ │ height │ 768 │ │ │ │ sampler_name │ DPM++ 3M SDE Karras │ │ │ │ enable_hr │ False │ │ │ │ hr_upscaler │ Latent │ │ │ │ checkpoint │ epicphotogasm_x.safetensors [8635af1c8c] │ │ │ │ vae │ Automatic │ │ │ │ unet │ Automatic │ │ │ └─────────────────┴────────────────────────────────────────────────────────────────────────────────────────────┘ │ │ ADetailer │ │ ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ version │ 23.10.1 │ │ │ │ ad_model │ face_yolov8n.pt │ │ │ │ ad_prompt │ │ │ │ │ ad_negative_prompt │ │ │ │ │ ad_controlnet_model │ controlnet11Models_inpaint │ │ │ │ is_api │ False │ │ │ └─────────────────────┴─────────────────────────────┘ │ │ ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ │ │ D:\Tools\stable-diffusion-webui\extensions\adetailer\adetailer\traceback.py:139 in wrapper │ │ │ │ │ │ │ │ 136 │ │ width = width - 4 if width > 4 else None │ │ │ │ 137 │ │ console = Console(file=string, width=width) │ │ │ │ 138 │ │ try: │ │ │ │ ❱ 139 │ │ │ return func(
args,
kwargs) │ │ │ │ 140 │ │ except Exception as e: │ │ │ │ 141 │ │ │ tables = [ │ │ │ │ 142 │ │ │ │ get_table(title, data) │ │ │ │ │ │ │ │ D:\Tools\stable-diffusion-webui\extensions\adetailer\scripts!adetailer.py:732 in │ │ │ │ postprocess_image │ │ │ │ │ │ │ │ 729 │ │ │ for n, args in enumerate(arg_list): │ │ │ │ 730 │ │ │ │ if args.ad_model == "None": │ │ │ │ 731 │ │ │ │ │ continue │ │ │ │ ❱ 732 │ │ │ │ is_processed |= self._postprocess_image_inner(p, pp, args, n=n) │ │ │ │ 733 │ │ │ │ │ │ 734 │ │ if is_processed and not getattr(p, "_ad_skip_img2img", False): │ │ │ │ 735 │ │ │ self.save_image( │ │ │ │ │ │ │ │ D:\Tools\stable-diffusion-webui\extensions\adetailer\scripts!adetailer.py:641 in │ │ │ │ _postprocess_image_inner │ │ │ │ │ │ │ │ 638 │ │ i = p._ad_idx │ │ │ │ 639 │ │ │ │ │ │ 640 │ │ pp.image = self.get_i2i_init_image(p, pp) │ │ │ │ ❱ 641 │ │ i2i = self.get_i2i_p(p, args, pp.image) │ │ │ │ 642 │ │ seed, subseed = self.get_seed(p) │ │ │ │ 643 │ │ ad_prompts, ad_negatives = self.get_prompt(p, args) │ │ │ │ 644 │ │ │ │ │ │ │ │ D:\Tools\stable-diffusion-webui\extensions\adetailer\scripts!adetailer.py:508 in get_i2i_p │ │ │ │ │ │ │ │ 505 │ │ i2i._ad_disabled = True │ │ │ │ 506 │ │ │ │ │ │ 507 │ │ if args.ad_controlnet_model != "None": │ │ │ │ ❱ 508 │ │ │ self.update_controlnet_args(i2i, args) │ │ │ │ 509 │ │ else: │ │ │ │ 510 │ │ │ i2i.control_net_enabled = False │ │ │ │ 511 │ │ │ │ │ │ │ │ D:\Tools\stable-diffusion-webui\extensions\adetailer\scripts!adetailer.py:184 in │ │ │ │ update_controlnet_args │ │ │ │ │ │ │ │ 181 │ │ │ and self.controlnet_ext.cn_available │ │ │ │ 182 │ │ │ and args.ad_controlnet_model != "None" │ │ │ │ 183 │ │ ): │ │ │ │ ❱ 184 │ │ │ self.controlnet_ext.update_scripts_args( │ │ │ │ 185 │ │ │ │ p, │ │ │ │ 186 │ │ │ │ model=args.ad_controlnet_model, │ │ │ │ 187 │ │ │ │ module=args.ad_controlnet_module, │ │ │ │ │ │ │ │ D:\Tools\stable-diffusion-webui\extensions\adetailer\controlnet_ext\controlnet_ext.py:81 in │ │ │ │ update_scripts_args │ │ │ │ │ │ │ │ 78 │ │ │ ) │ │ │ │ 79 │ │ ] │ │ │ │ 80 │ │ │ │ │ │ ❱ 81 │ │ self.external_cn.update_cn_script_in_processing(p, cn_units) │ │ │ │ 82 │ │ │ │ 83 │ │ │ │ 84 def get_cn_model_dirs() -> list[Path]: │ │ │ │ │ │ │ │ D:\Tools\stable-diffusion-webui\extensions\sd-webui-controlnet\internal_controlnet\external_code │ │ │ │ .py:341 in update_cn_script_in_processing │ │ │ │ │ │ │ │ 338 │ │ │ │ │ 339 │ cn_units_type = type(cn_units) if type(cn_units) in (list, tuple) else list │ │ │ │ 340 │ script_args = p.script_args_value │ │ │ │ ❱ 341 │ update_cn_script_in_place(p.scripts, script_args, cn_units) │ │ │ │ 342 │ p.script_args = cn_units_type(script_args) │ │ │ │ 343 │ │ │ │ 344 │ │ │ │ │ │ │ │ D:\Tools\stable-diffusion-webui\extensions\sd-webui-controlnet\internal_controlnet\external_code │ │ │ │ .py:372 in update_cn_script_in_place │ │ │ │ │ │ │ │ 369 │ for script in script_runner.alwayson_scripts: │ │ │ │ 370 │ │ if script is cn_script: │ │ │ │ 371 │ │ │ cn_script_args_diff = len(cn_units) - (cn_script.args_to - cn_script.args_fr │ │ │ │ ❱ 372 │ │ │ script_args[script.args_from:script.args_to] = cn_units │ │ │ │ 373 │ │ │ script.args_to = script.args_from + len(cn_units) │ │ │ │ 374 │ │ else: │ │ │ │ 375 │ │ │ script.args_from += cn_script_args_diff │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ TypeError: 'tuple' object does not support item assignment

fxwz commented 10 months ago

Ah, I only tried it with a single face myself. I was getting the same error as you though, but the other posters error is in a different place in the same class.

If you'd like, you can try this slightly less dirty, but still pretty dirty hack from a guy that has no idea what he is doing 😅

Instead of a single line, this time it's two lines for twice the greatness!

if type(script_args) is tuple:
    return

edit: Same place in the code btw. And if I were a betting man I'd say you'll get the same result, but it might be worth a shot! e^2: @mvanzorn

mvanzorn commented 10 months ago

@fxwz Thanks, will try that.

Shot in the dark: I've compared a system with a mobile 3080RTX mobile (ADetailer works even without your creative modifications) vs. a 2080Ti desktop (ADetailer broken) and a 1080RTX mobile (ADetailer broken). All with identical Automatic1111 setups.

Wonder if the generation of the Nvidia chip has anything to do with it.

Bing-su commented 10 months ago

Updating controlnet will fix this issue.

xarathos517 commented 10 months ago

I've git cloned the latest version of the controlnet extension, and the issue persists. Is there a different way of updating that I'm unaware of?

Bing-su commented 10 months ago

@xarathos517 If your webui version is lower than 1.6.0, you will still get the error.

demib72 commented 10 months ago

Seems SD.Next is running things differently. Use to run just fine, but now I get 'StableDiffusionProcessingImg2Img' object has no attribute 'script_args_value' error. Will make my own issue.