hako-mikan / sd-webui-regional-prompter

set prompt to divided region
GNU Affero General Public License v3.0
1.58k stars 133 forks source link

API mask upload not working #336

Closed Dutch77 closed 4 months ago

Dutch77 commented 4 months ago

Describe the bug I want to use txt2img with regional prompter mask mode, but mask cannot be loaded. These are data sent to the api:

[
  true,
  true,
  'Mask',
  'Columns',
  'Mask',
  'Prompt',
  '1,1',
  '0',
  true,
  false,
  false,
  'Attention',
  false,
  '0',
  '0',
  '0',
  '/workspace/stable-diffusion-webui/mask.png',
  '0',
  '0',
  false
]

Produces error

stable-diffusion-webui-stable-diffusion-webui-1  | *** Error running process: /workspace/stable-diffusion-webui/extensions/sd-webui-regional-prompter/scripts/rp.py
stable-diffusion-webui-stable-diffusion-webui-1  |     Traceback (most recent call last):
stable-diffusion-webui-stable-diffusion-webui-1  |       File "/workspace/stable-diffusion-webui/modules/scripts.py", line 825, in process
stable-diffusion-webui-stable-diffusion-webui-1  |         script.process(p, *script_args)
stable-diffusion-webui-stable-diffusion-webui-1  |       File "/workspace/stable-diffusion-webui/extensions/sd-webui-regional-prompter/scripts/rp.py", line 452, in process
stable-diffusion-webui-stable-diffusion-webui-1  |         savepresets("lastrun",rp_selected_tab, mmode, xmode, pmode, aratios,bratios,
stable-diffusion-webui-stable-diffusion-webui-1  |       File "/workspace/stable-diffusion-webui/extensions/sd-webui-regional-prompter/scripts/rp.py", line 932, in savepresets
stable-diffusion-webui-stable-diffusion-webui-1  |         settings = saveblob(settings)
stable-diffusion-webui-stable-diffusion-webui-1  |       File "/workspace/stable-diffusion-webui/extensions/sd-webui-regional-prompter/scripts/rp.py", line 906, in saveblob
stable-diffusion-webui-stable-diffusion-webui-1  |         x = x.save(preset[0], preset)
stable-diffusion-webui-stable-diffusion-webui-1  |       File "/workspace/stable-diffusion-webui/extensions/sd-webui-regional-prompter/scripts/rp.py", line 845, in save
stable-diffusion-webui-stable-diffusion-webui-1  |         save_mask(self.img, self.makepath(name))
stable-diffusion-webui-stable-diffusion-webui-1  |       File "/workspace/stable-diffusion-webui/extensions/sd-webui-regional-prompter/scripts/regions.py", line 604, in save_mask
stable-diffusion-webui-stable-diffusion-webui-1  |         img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
stable-diffusion-webui-stable-diffusion-webui-1  |     cv2.error: OpenCV(4.10.0) :-1: error: (-5:Bad argument) in function 'cvtColor'
stable-diffusion-webui-stable-diffusion-webui-1  |     > Overload resolution failed:
stable-diffusion-webui-stable-diffusion-webui-1  |     >  - src is not a numpy array, neither a scalar
stable-diffusion-webui-stable-diffusion-webui-1  |     >  - Expected Ptr<cv::UMat> for argument 'src'

Tried with example mask from this project. For some reason it's unable to extract mask.

Please if you're going to fix it would be great if it could accept a mask in base64, so it wouldn't have to be uploaded to a disk in advance - that would be super cool feature.

Thanks

Environment version: v1.9.4  •  python: 3.10.12  •  torch: 2.1.0+cu121  •  xformers: 0.0.22.post7  •  gradio: 3.41.2  •  checkpoint: d6a48d3e20

Other Enabled Extensions

LDSR            
Lora            
ScuNET          
SwinIR          
canvas-zoom-and-pan         
extra-options-section           
hypertile           
mobile          
postprocessing-for-training         
prompt-bracket-checker          
soft-inpainting         
sd-dynamic-prompts
sd-webui-controlnet
sd-webui-reactor
sd-webui-regional-prompter
sd-webui-segment-anything
stable-diffusion-webui-rembg
Dutch77 commented 4 months ago

Ok. I figured it out. I was exporting my png file in photopea and I had disabled option don't use palletes. Apparently PIL Image cannot extract channels from such images and it explodes here https://github.com/hako-mikan/sd-webui-regional-prompter/blob/main/scripts/regions.py#L533

We can probably close this but I think this info can be really handy for someone. I lost several hours today because of this.