PIL.UnidentifiedImageError: cannot identify image file
songshen06 opened this issue · comments
Hello , guys
File "C:\Users\stabdiff\stable-diffusion-webui\modules\api\api.py", line 62, in decode_base64_to_image
image = Image.open(BytesIO(base64.b64decode(encoding)))
File "C:\Users\stabdiff\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 3283, in open
raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file
don't know why they can not decode the image .
Env:
latest automatic1111 and Mikubill/sd-webui-controlnet
What I already did ?
-
I added some print to make sure the file path is right, the file is existing.
-
make sure the python package installtion is right
-
manually use webui controlnet works good
some body has same issue ?
same on my side
The issue resides on extensions-builtin\sd-webui-controlnet\scripts\controlnet.py
[I'm using vlad-diffusion, but should be similar path in a1111, minus the -builtin from extensions]
The Issue
When setting up image and mask into nparray... the mask is typically empty. However, it is an empty string, and hence controlnet tries to parse the empty string... So the solution is to check if the incoming mask is a string and is not empty!
The Fix
I'll put a pull request into controlnet. But in the meantime you can do this yourself. In the script you can replace this:
if isinstance(result['mask'], str):
result['mask'] = external_code.to_base64_nparray(result['mask'])
elif result['mask'] is None:
result['mask'] = np.zeros_like(result['image'], dtype=np.uint8)
with
if isinstance(result['mask'], str):
if result['mask']:
result['mask'] = external_code.to_base64_nparray(result['mask'])
else:
result['mask'] = np.zeros_like(result['image'], dtype=np.uint8)
elif result['mask'] is None:
result['mask'] = np.zeros_like(result['image'], dtype=np.uint8)