coolzilj / Blender-ControlNet

Using ControlNet right in Blender.
MIT License
760 stars 68 forks source link

PIL.UnidentifiedImageError: cannot identify image file #25

Open songshen06 opened 1 year ago

songshen06 commented 1 year ago

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 ?

  1. I added some print to make sure the file path is right, the file is existing.

  2. make sure the python package installtion is right

  3. manually use webui controlnet works good

some body has same issue ?

crowtalons commented 1 year ago

same on my side

ETdoFresh commented 1 year ago

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)