danielgatis / rembg

Rembg is a tool to remove images background
MIT License
15.39k stars 1.75k forks source link

[BUG] jsonschema.exceptions.ValidationError: '{}' is not of type 'array' #615

Closed alan20062006 closed 1 month ago

alan20062006 commented 3 months ago

Describe the bug When switching from isnet-general-use to sam. Encountered the following bug

` File "/Users/XX/opt/anaconda3/envs/genai/lib/python3.11/site-packages/rembg/bg.py", line 257, in remove masks = session.predict(img, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/XX/opt/anaconda3/envs/genai/lib/python3.11/site-packages/rembg/sessions/sam.py", line 169, in predict validate(instance=prompt, schema=schema) File "/Users/XX/opt/anaconda3/envs/genai/lib/python3.11/site-packages/jsonschema/validators.py", line 1312, in validate raise error jsonschema.exceptions.ValidationError: '{}' is not of type 'array'

Failed validating 'type' in schema: {'items': {'properties': {'data': {'items': {'type': 'number'}, 'type': 'array'}, 'label': {'type': 'integer'}, 'type': {'type': 'string'}}, 'type': 'object'}, 'type': 'array'}

On instance: '{}'`

To Reproduce I was using isnet-general-use for a long time and is looking for a better solution so I changed to sam.

Rembg version: v 2.0.53

Additional context Add any other context about the problem here.

loeweh commented 2 months ago

I have the same issue. switching to sam raises the bug

gio-foldai commented 2 months ago

Stumbled on this today. This seems to be a bug in sam.py, where

   prompt = kwargs.get("sam_prompt", "{}")  # here "{}" should be []

But the reason this bug went undiscovered is that you're supposed to tell sam what to segment, passing a prompt, for example:

rembg.remove(img, session=REMBG_SESSION, sam_prompt=[{"type": "point", "data": [0, 0], "label": 1}])
github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 month ago

This issue was closed because it has been inactive for 14 days since being marked as stale.