stable-diffusion-webui
stable-diffusion-webui copied to clipboard
[Bug]: API Error: /sdapi/v1/img2img returns error as 'str' object has no attribute 'convert'"
Is there an existing issue for this?
- [X] I have searched the existing issues and checked the recent builds/commits
What happened?
I followed the steps to run img2img through swagger AP, but face this issue 'str' object has no attribute 'convert'".
{
"init_images": [
"
error: { "error": "AttributeError", "detail": "", "body": "", "errors": "'str' object has no attribute 'convert'" }
console: API error: POST: https://9205563b314e0ba6a2.gradio.live/sdapi/v1/img2img {'error': 'AttributeError', 'detail': '', 'body': '', 'errors': "'str' object has no attribute 'convert'"} Traceback (most recent call last): File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 94, in receive return self.receive_nowait() File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 89, in receive_nowait raise WouldBlock anyio.WouldBlock
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 78, in call_next message = await recv_stream.receive() File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 114, in receive raise EndOfStream anyio.EndOfStream
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/ubuntu/stable-diffusion-webui/modules/api/api.py", line 145, in exception_handling return await call_next(request) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next raise app_exc File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 108, in call response = await self.dispatch_func(request, call_next) File "/home/ubuntu/stable-diffusion-webui/modules/api/api.py", line 110, in log_and_time res: Response = await call_next(req) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next raise app_exc File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 24, in call await responder(scope, receive, send) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 44, in call await self.app(scope, receive, self.send_with_gzip) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in call raise exc File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in call await self.app(scope, receive, sender) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call raise e File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call await self.app(scope, receive, send) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 718, in call await route.handle(scope, receive, send) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle await self.app(scope, receive, send) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app response = await func(request) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 237, in app raw_response = await run_endpoint_function( File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 165, in run_endpoint_function return await run_in_threadpool(dependant.call, **values) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/concurrency.py", line 41, in run_in_threadpool return await anyio.to_thread.run_sync(func, *args) File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/to_thread.py", line 31, in run_sync return await get_asynclib().run_sync_in_worker_thread( File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread return await future File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 867, in run result = context.run(func, *args) File "/home/ubuntu/stable-diffusion-webui/modules/api/api.py", line 376, in img2imgapi processed = process_images(p) File "/home/ubuntu/stable-diffusion-webui/modules/processing.py", line 503, in process_images res = process_images_inner(p) File "/home/ubuntu/stable-diffusion-webui/modules/processing.py", line 594, in process_images_inner p.init(p.all_prompts, p.all_seeds, p.all_subseeds) File "/home/ubuntu/stable-diffusion-webui/modules/processing.py", line 977, in init image_mask = image_mask.convert('L') AttributeError: 'str' object has no attribute 'convert'
Steps to reproduce the problem
- start websh
ubuntu@ip- Textual inversion embeddings loaded(0): Model loaded in 4.8s (load weights from disk: 0.3s, create model: 0.8s, apply weights to model: 1.2s, apply half(): 0.7s, load VAE: 1.1s, move model to device: 0.6s). Running on local URL: http://127.0.0.1:7860 Running on public URL: https://9205563b314e0ba6a2.gradio.live
This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces Startup time: 15.2s (import torch: 1.0s, import gradio: 0.9s, import ldm: 0.6s, other imports: 0.7s, load scripts: 0.4s, load SD checkpoint: 5.0s, create ui: 0.2s, gradio launch: 6.2s, scripts app_started_callback: 0.1s). 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:07<00:00, 1.44s/it] API error: POST: https://9205563b314e0ba6a2.gradio.live/sdapi/v1/img2img {'error': 'HTTPException', 'detail': 'Invalid encoded image', 'body': '', 'errors': ''} API error: POST: https://9205563b314e0ba6a2.gradio.live/sdapi/v1/img2img {'error': 'HTTPException', 'detail': 'Sampler not found', 'body': '', 'errors': ''} API error: POST: https://9205563b314e0ba6a2.gradio.live/sdapi/v1/img2img {'error': 'AttributeError', 'detail': '', 'body': '', 'errors': "'str' object has no attribute 'convert'"}
- Use swagger to issue img2img generation using base64 img
What should have happened?
Should have generated img
Commit where the problem happens
np
What platforms do you use to access the UI ?
No response
What browsers do you use to access the UI ?
No response
Command Line Arguments
attached
List of extensions
none
Console logs
attached
Additional information
No response
Followed the suggestion given in https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/9467 added mask field with empty quotes
Can some one share correct mask parameter format or sample working config for img2img feature
Followed the suggestion given in #9467 added mask field with empty quotes
Delete the variable named "mask". When "mask" exists, it will attempt to encode the masked image and then throw an error.
removing "mask": "" from payload object fixed it.
Followed the suggestion given in #9467 added mask field with empty quotes
Delete the variable named "mask". When "mask" exists, it will attempt to encode the masked image and then throw an error.
I have a similar problem when doing img2img with a mask for inpaint. I thought that is due to the API has not process the input str (a base64 encoded image for my case), but i found that it actually has decoded the str back to image in api.py line 396 and then updated the variable "mask". This should have passed to the next step in processing.py but seems not successful.
Is anybody working on a fix for this?
Removing the mask parameter is only solving the problem for those who don't need the mask, but I have not found any way to pass an actual mask at this time
Same issue guys. Receiving "'str' object has no attribute 'convert'" while trying to pass mask for Img2img API.
It turns out, that if host SD locally and make API request - everything works fine, but when host API SD somewhere, then this error occurs.
Followed the suggestion given in #9467 added mask field with empty quotes
Delete the variable named "mask". When "mask" exists, it will attempt to encode the masked image and then throw an error.
I have a similar problem when doing img2img with a mask for inpaint. I thought that is due to the API has not process the input str (a base64 encoded image for my case), but i found that it actually has decoded the str back to image in api.py line 396 and then updated the variable "mask". This should have passed to the next step in processing.py but seems not successful.
Guys @CCJetWing, @mgschwan, I was wondering if you had any progress on solving this for yourself? Stuck with this for already 6 days..
Has this issue been resolved yet? I also have this issue, even if the image is converted to base64, it is still this error
yes, workaround works for me.
On Wed, Apr 17, 2024 at 1:58 PM ffhelly @.***> wrote:
Has this issue been resolved yet?
— Reply to this email directly, view it on GitHub https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/9779#issuecomment-2060694881, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABT2UTXDXAFVDVIE572U7S3Y5YXBTAVCNFSM6AAAAAAXGX76ACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRQGY4TIOBYGE . You are receiving this because you authored the thread.Message ID: @.***>
Followed the suggestion given in #9467 added mask field with empty quotes
Delete the variable named "mask". When "mask" exists, it will attempt to encode the masked image and then throw an error.
I have a similar problem when doing img2img with a mask for inpaint. I thought that is due to the API has not process the input str (a base64 encoded image for my case), but i found that it actually has decoded the str back to image in api.py line 396 and then updated the variable "mask". This should have passed to the next step in processing.py but seems not successful.
Guys @CCJetWing, @mgschwan, I was wondering if you had any progress on solving this for yourself? Stuck with this for already 6 days..
I've moved my whole process tom comfyui because last time I checked it ( which was some February release ) it was stil not working.
yes, workaround works for me. … On Wed, Apr 17, 2024 at 1:58 PM ffhelly @.> wrote: Has this issue been resolved yet? — Reply to this email directly, view it on GitHub <#9779 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABT2UTXDXAFVDVIE572U7S3Y5YXBTAVCNFSM6AAAAAAXGX76ACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRQGY4TIOBYGE . You are receiving this because you authored the thread.Message ID: @.>
If you are not relying on the mask then yes you can remove it and it won't throw an error, but if you need the mask then this won't help
on modules/processing.py self.latent_mask if self.latent_mask is not None else image_mask
on server latent_mask = "" is str so throw this error modify: latent_mask = self.latent_mask if self.latent_mask is not None and self.latent_mask!="" else image_mask it's work
Has anyone had one success with this? I can confirm that providing (what I believe is) a proper base64 image for "mask" still causes the bug: 'str' object has no attribute 'convert'
I can confirm that @quanwuji 's workaround works.
It seems that maybe different comparisons of type "mask is None" / "mask is not None" fail in situations with empty strings, since an empty string is obviously not a valid mask, yet it evaluates as "not None".