sd-webui-segment-anything icon indicating copy to clipboard operation
sd-webui-segment-anything copied to clipboard

[Bug]: ValueError: too many values to unpack (expected 2)

Open finndev opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits of both this extension and the webui

Have you updated WebUI and this extension to the latest version?

  • [X] I have updated WebUI and this extension to the latest version

Do you understand that you should read the 1st item of https://github.com/continue-revolution/sd-webui-segment-anything#faq if you cannot install GroundingDINO?

  • [X] My problem is not about installing GroundingDINO

Do you understand that you should use the latest ControlNet extension and enable external control if you want SAM extension to control ControlNet?

  • [X] I have updated ControlNet extension and enabled "Allow other script to control this extension"

Do you understand that you should read the 2nd item of https://github.com/continue-revolution/sd-webui-segment-anything#faq if you observe problems like AttributeError bool object has no attribute enabled and TypeError bool object is not subscriptable?

  • [X] My problem is not about such issue, otherwise I have tried changing the extension directory name from sd-webui-segment-anything to a1111-sd-webui-segment-anything

What happened?

When using mask by category and inputting an image, then previewing the masks I receive the following error:

Traceback (most recent call last):
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\gradio\routes.py", line 422, in run_predict
    output = await app.get_blocks().process_api(
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\gradio\blocks.py", line 1323, in process_api
    result = await self.call_function(
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\gradio\blocks.py", line 1051, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "C:\StableDiffusion\stablediffusion\extensions\a1111-sd-webui-segment-anything-master\scripts\sam.py", line 363, in categorical_mask
    outputs, resized_input_image = categorical_mask_image(crop_processor, crop_processor_res, crop_category_input, crop_input_image,
ValueError: too many values to unpack (expected 2)

Steps to reproduce the problem

Use mask by category and input an image

What should have happened?

Generate a mask

Commit where the problem happens

webui: extension:

What browsers do you use to access the UI ?

No response

Command Line Arguments

No

Console logs

Traceback (most recent call last):
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\gradio\routes.py", line 422, in run_predict
    output = await app.get_blocks().process_api(
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\gradio\blocks.py", line 1323, in process_api
    result = await self.call_function(
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\gradio\blocks.py", line 1051, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "C:\StableDiffusion\stablediffusion\python\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "C:\StableDiffusion\stablediffusion\extensions\a1111-sd-webui-segment-anything-master\scripts\sam.py", line 363, in categorical_mask
    outputs, resized_input_image = categorical_mask_image(crop_processor, crop_processor_res, crop_category_input, crop_input_image,
ValueError: too many values to unpack (expected 2)

Additional information

No response

finndev avatar Aug 05 '23 19:08 finndev

same issue

ghost avatar Jan 17 '24 16:01 ghost

I am also facing same issue

Code: import base64 import requests from PIL import Image from io import BytesIO import json

def filename_to_base64(filename): with open(filename, "rb") as fh: return base64.b64encode(fh.read())

img_filename = "abc.jpg"

url = "http://localhost:7860/sam/category-mask"

payload = { "input_image": filename_to_base64(img_filename).decode(), "category": "12", "processor_res": "1024", } #response = requests.post(url, json={"payload": payload}) response = requests.post(url, json={"payload": payload, "autosam_conf": {}}) reply = response.json() #print(reply["msg"]) print(json.dumps(reply))

grid = Image.new('RGBA', (3 * 512, 512)) paste([reply["blended_image"], reply["mask"], reply["masked_image"]], 0) grid.show()

Error: SAM API /sam/category-mask received request Start processing categorical mask *** API error: POST: http://localhost:7860/sam/category-mask {'error': 'ValueError', 'detail': '', 'body': '', 'errors': 'too many values to unpack (expected 2)'} Traceback (most recent call last): File "D:\Forge\system\python\lib\site-packages\anyio\streams\memory.py", line 98, in receive return self.receive_nowait() File "D:\Forge\system\python\lib\site-packages\anyio\streams\memory.py", line 93, in receive_nowait raise WouldBlock anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\base.py", line 78, in call_next
    message = await recv_stream.receive()
  File "D:\Forge\system\python\lib\site-packages\anyio\streams\memory.py", line 118, in receive
    raise EndOfStream
anyio.EndOfStream

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Forge\webui\modules\api\api.py", line 190, in exception_handling
    return await call_next(request)
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\base.py", line 84, in call_next
    raise app_exc
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\base.py", line 70, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\base.py", line 108, in __call__
    response = await self.dispatch_func(request, call_next)
  File "D:\Forge\webui\modules\api\api.py", line 154, in log_and_time
    res: Response = await call_next(req)
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\base.py", line 84, in call_next
    raise app_exc
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\base.py", line 70, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\cors.py", line 84, in __call__
    await self.app(scope, receive, send)
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\gzip.py", line 24, in __call__
    await responder(scope, receive, send)
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\gzip.py", line 44, in __call__
    await self.app(scope, receive, self.send_with_gzip)
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
    raise exc
  File "D:\Forge\system\python\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "D:\Forge\system\python\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
    raise e
  File "D:\Forge\system\python\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "D:\Forge\system\python\lib\site-packages\starlette\routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "D:\Forge\system\python\lib\site-packages\starlette\routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "D:\Forge\system\python\lib\site-packages\starlette\routing.py", line 66, in app
    response = await func(request)
  File "D:\Forge\system\python\lib\site-packages\fastapi\routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "D:\Forge\system\python\lib\site-packages\fastapi\routing.py", line 163, in run_endpoint_function
    return await dependant.call(**values)
  File "D:\Forge\webui\extensions\sd-webui-segment-anything\scripts\api.py", line 207, in api_category_mask
    category_mask_img, category_mask_msg, resized_input_img = categorical_mask(
  File "D:\Forge\webui\extensions\sd-webui-segment-anything\scripts\sam.py", line 363, in categorical_mask
    outputs, resized_input_image = categorical_mask_image(crop_processor, crop_processor_res, crop_category_input, crop_input_image,
ValueError: too many values to unpack (expected 2)

roshanuser avatar Mar 31 '24 07:03 roshanuser