Interpause / auto-sd-krita

AUTOMATIC1111 webUI + Krita Plugin with superb Inpainting
MIT License
88 stars 4 forks source link

when selection is present ZerroDivision error #8

Closed sould3mon closed 2 years ago

sould3mon commented 2 years ago

when selection is present everything breaks txt2img img2img etc without it it works like you showed on youtube.

version 5.1.1 (updated from 5.0.2 to see if it was because of outdated version) to produce i just need to have any selection present and cllick start. error:

---start of paste--- ZeroDivisionError Python 3.8.1: F:\Apps\Krita (x64)\bin\krita.exe Sat Oct 8 23:31:46 2022

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py in cb() 468 def cb(): 469 self.update_config() 470 self.try_fix_aspect_ratio() 471 self.apply_img2img(mode=1) 472 self.set_status(STATE_INPAINT) self = self.try_fix_aspect_ratio = <bound method Script.try_fix_aspect_ratio of >

C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py in try_fix_aspect_ratio(self=) 278 if self.selection is not None and self.cfg("fix_aspect_ratio", bool): 279 ratio = self.width / self.height 280 final_ratio = self.find_final_aspect_ratio() 281 282 delta = abs(final_ratio - ratio) final_ratio undefined self = self.find_final_aspect_ratio = <bound method Script.find_final_aspect_ratio of >

C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py in find_final_aspect_ratio(self=) 270 width, height = rnd(ratio, max_size), max_size 271 272 return width / height 273 274 def try_fix_aspect_ratio(self): width = 0 height = 0 ZeroDivisionError: division by zero cause = None class = <class 'ZeroDivisionError'> context = None delattr = <method-wrapper 'delattr' of ZeroDivisionError object> dict = {} dir = doc = 'Second argument to a division or modulo operation was zero.' eq = <method-wrapper 'eq' of ZeroDivisionError object> format = ge = <method-wrapper 'ge' of ZeroDivisionError object> getattribute = <method-wrapper 'getattribute' of ZeroDivisionError object> gt = <method-wrapper 'gt' of ZeroDivisionError object> hash = <method-wrapper 'hash' of ZeroDivisionError object> init = <method-wrapper 'init' of ZeroDivisionError object> init_subclass = <built-in method init_subclass of type object> le = <method-wrapper 'le' of ZeroDivisionError object> lt = <method-wrapper 'lt' of ZeroDivisionError object> ne = <method-wrapper 'ne' of ZeroDivisionError object> new = reduce = reduce_ex = <built-in method reduce_ex of ZeroDivisionError object> repr = <method-wrapper 'repr' of ZeroDivisionError object> setattr = <method-wrapper 'setattr' of ZeroDivisionError object> setstate = sizeof = str = <method-wrapper 'str' of ZeroDivisionError object> subclasshook = __suppress_context = False traceback__ = args = ('division by zero',) with_traceback =

The above is a description of an error in a Python program. Here is the original traceback:

Traceback (most recent call last): File "C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py", line 470, in cb self.try_fix_aspect_ratio() File "C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py", line 280, in try_fix_aspect_ratio final_ratio = self.find_final_aspect_ratio() File "C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py", line 272, in find_final_aspect_ratio return width / height ZeroDivisionError: division by zero

---end of paste---

sould3mon commented 2 years ago

for full disclosure. i did just copy the venv from the stable-diffusion-webui directory. tested it in powershell with torch.cuda.is_available() and typed python launch.py

Interpause commented 2 years ago

The error occurs when the selection box has an extremely large aspect ratio, causing the zero division in the logic that attempts to round it to a stride of 64. https://github.com/Interpause/auto-sd-krita/commit/0a86677e86fa7a3cc5f2114ee63c0ef0495502b5 should workaround the issue but result in the box being inaccurate for weird selections.

Check if your base size/max size are sensible, i.e. 512 and 768 respectively. The plugin scales the selection box to have one dimension match base size if possible, the other be under max size, and the dimensions being a stride of 64.

sould3mon commented 2 years ago

mask issue got fixed 💯. but this one still persists for me for all types of selections held shift while selecting tried larger /smaller then base size

tried: on large image with various selection sizes around the base size new 512x512 image and 128x128 selection box made sure only 1 selection box was present when having multiple documents open

settings are default (512, 768)

error changed to: 282 def try_fix_aspect_ratio(self): width = 64 height = 0

edit: inpaint works fine if i just deselect everything though and have mask layer active

---full error--- ZeroDivisionError Python 3.8.1: F:\Apps\Krita (x64)\bin\krita.exe Sun Oct 9 12:28:23 2022

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py in cb() 476 def cb(): 477 self.update_config() 478 self.try_fix_aspect_ratio() 479 self.apply_img2img(mode=1) 480 self.set_status(STATE_INPAINT) self = self.try_fix_aspect_ratio = <bound method Script.try_fix_aspect_ratio of >

C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py in try_fix_aspect_ratio(self=) 286 if self.selection is not None and self.cfg("fix_aspect_ratio", bool): 287 ratio = self.width / self.height 288 final_ratio = self.find_final_aspect_ratio() 289 290 delta = abs(final_ratio - ratio) final_ratio undefined self = self.find_final_aspect_ratio = <bound method Script.find_final_aspect_ratio of >

C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py in find_final_aspect_ratio(self=) 278 width, height = rnd(ratio, max_size), max_size 279 280 return width / height 281 282 def try_fix_aspect_ratio(self): width = 64 height = 0 ZeroDivisionError: division by zero cause = None class = <class 'ZeroDivisionError'> context = None delattr = <method-wrapper 'delattr' of ZeroDivisionError object> dict = {} dir = doc = 'Second argument to a division or modulo operation was zero.' eq = <method-wrapper 'eq' of ZeroDivisionError object> format = ge = <method-wrapper 'ge' of ZeroDivisionError object> getattribute = <method-wrapper 'getattribute' of ZeroDivisionError object> gt = <method-wrapper 'gt' of ZeroDivisionError object> hash = <method-wrapper 'hash' of ZeroDivisionError object> init = <method-wrapper 'init' of ZeroDivisionError object> init_subclass = <built-in method init_subclass of type object> le = <method-wrapper 'le' of ZeroDivisionError object> lt = <method-wrapper 'lt' of ZeroDivisionError object> ne = <method-wrapper 'ne' of ZeroDivisionError object> new = reduce = reduce_ex = <built-in method reduce_ex of ZeroDivisionError object> repr = <method-wrapper 'repr' of ZeroDivisionError object> setattr = <method-wrapper 'setattr' of ZeroDivisionError object> setstate = sizeof = str = <method-wrapper 'str' of ZeroDivisionError object> subclasshook = __suppress_context = False traceback__ = args = ('division by zero',) with_traceback =

The above is a description of an error in a Python program. Here is the original traceback:

Traceback (most recent call last): File "C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py", line 478, in cb self.try_fix_aspect_ratio() File "C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py", line 288, in try_fix_aspect_ratio final_ratio = self.find_final_aspect_ratio() File "C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py", line 280, in find_final_aspect_ratio return width / height ZeroDivisionError: division by zero

Interpause commented 2 years ago

Did you replace the existing krita_diff folder in the pykrita folder after updating the code? Part of the workaround was just ignoring the selection box if the width/height was less than 1.

That said, based on what you tried, it seems very weird the selection height would be 0. Could you send some screenshots of what you are doing so I can try to reproduce the error? Thanks

sould3mon commented 2 years ago

yes i did forget that at first though. also tried disabling plugin restart enable restart for good measure and restart of the server.

i am uploading a short video since i think that be more usefull then couple screenshots www.youtube.com/watch?v=5UEyQmN5dRs

@Interpause video is should be up in hd now showing various actions that with selection present it fails show that the mask problem is fixed so it's running the updated code and lines in the error changed with +8 wich matches the commit amount

just tried settings>reset all settings but no change

sould3mon commented 2 years ago

now with an non equal selection box i get a diffrent error i din't notice

also tried adjusting you script to run parts of selection in scripter window so far i got to where line 280 returns

` ...

return line 280

ans = width / height print(ans,width,height) ` ---output--- 204 202 1.0 512 512

--error with selection differing by 2 pixels same as below except ratio value-- delta_rev undefined builtinabs = final_ratio = 0.0 ratio = 1.00990099009901

--new error with large difference in ratio-- ZeroDivisionError Python 3.8.1: F:\Apps\Krita (x64)\bin\krita.exe Sun Oct 9 19:27:46 2022

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py in cb() 439 def cb(): 440 self.update_config() 441 self.try_fix_aspect_ratio() 442 self.apply_txt2img() 443 self.create_mask_layer_workaround() self = self.try_fix_aspect_ratio = <bound method Script.try_fix_aspect_ratio of >

C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py in try_fix_aspect_ratio(self=) 289 290 delta = abs(final_ratio - ratio) 291 delta_rev = abs(1 / final_ratio - 1 / ratio) 292 x_limit = math.ceil(delta self.width) 293 y_limit = math.ceil(delta_rev self.height) delta_rev undefined builtinabs = final_ratio = 0.0 ratio = 1.7983193277310925 ZeroDivisionError: float division by zero cause = None class = <class 'ZeroDivisionError'> context = None delattr = <method-wrapper 'delattr' of ZeroDivisionError object> dict = {} dir = doc = 'Second argument to a division or modulo operation was zero.' eq = <method-wrapper 'eq' of ZeroDivisionError object> format = ge = <method-wrapper 'ge' of ZeroDivisionError object> getattribute = <method-wrapper 'getattribute' of ZeroDivisionError object> gt = <method-wrapper 'gt' of ZeroDivisionError object> hash = <method-wrapper 'hash' of ZeroDivisionError object> init = <method-wrapper 'init' of ZeroDivisionError object> init_subclass = <built-in method init_subclass of type object> le = <method-wrapper 'le' of ZeroDivisionError object> lt = <method-wrapper 'lt' of ZeroDivisionError object> ne = <method-wrapper 'ne' of ZeroDivisionError object> new = reduce = reduce_ex = <built-in method reduce_ex of ZeroDivisionError object> repr = <method-wrapper 'repr' of ZeroDivisionError object> setattr = <method-wrapper 'setattr' of ZeroDivisionError object> setstate = sizeof = str = <method-wrapper 'str' of ZeroDivisionError object> subclasshook = __suppress_context = False traceback__ = args = ('float division by zero',) with_traceback =

The above is a description of an error in a Python program. Here is the original traceback:

Traceback (most recent call last): File "C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py", line 441, in cb self.try_fix_aspect_ratio() File "C:\Users\Admin\AppData\Roaming\krita\pykrita\krita_diff\script.py", line 291, in try_fix_aspect_ratio delta_rev = abs(1 / final_ratio - 1 / ratio) ZeroDivisionError: float division by zero

Interpause commented 2 years ago

oh crap i noticed what was wrong. sh*t the plugin wouldn't have worked for any new user.

Interpause commented 2 years ago

Okay so if you're curious. The original plugin set the model base size and max size per tab. However, I decided that the setting should be shared amongst all tabs. However, I seem to have failed to rename one of them. So on completely new installs, the config value wouldn't exist, but surprisingly returns 0 instead of erroring out. Anyways, I verified that all access to the settings actually exist now so it should not happen.

I was so close to thinking this was just a problem with your computer lol. I probably should have tried installing in a virtual machine or something.

Interpause commented 2 years ago

Hopefully, the number of people who gave up on using this plugin because of this bug is less than 1...

sould3mon commented 2 years ago

so far everything seem to be working. oof that's a nasty type of bug to track down.

i think the biggest hurdle for the plugin is getting a duplicate setup for stable diffusion wich is is a 6gb install but i think it's worth it.

would be sad if after all that people are still to lazy to drop a bug report

Interpause commented 2 years ago

I don't actually duplicate the setup. For me, if I want to use new features of AUTO's webui, I gotta update this repo lol.

Also it aint a 6GB install if you symlink all the models and use the same venv for both.

Maybe I should write an installation guide based on the assumption they already have AUTO's fork. For example, they could use the same venv/conda env, or simply patch AUTO's fork with the changes in my fork.

sould3mon commented 2 years ago

that would be a nice option i just copied the venv and symlinked models since i din't want to mess with the working copy. and on windows at least seems to fine. din't have to mess with the copy of venv at all, used to be that it would break stuff.