rembg icon indicating copy to clipboard operation
rembg copied to clipboard

[BUG] '{}' is not of type 'array' when using sam model.

Open ShylockGao opened this issue 1 year ago • 14 comments

Describe the bug Unable to use the "sam" model in cli. rembg i -m sam -x '{ "sam_prompt": [{"type": "point", "data": [724, 740], "label": 1}] }' .\1305696_1704870215425_1705054411.png xxx.png Getting error: '{}' is not of type 'array'

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 rembg i -m sam -x '{ "sam_prompt": [{"type": "point", "data": [724, 740], "label": 1}] }' .\1305696_1704870215425_1705054411.png xxx.png

OS Version: window 11

Rembg version: v2.0.53

ShylockGao avatar Jan 15 '24 09:01 ShylockGao

Hi, Gao. Have you solved this problem yet? I think I have the same problem with you.

zhengxiongli08 avatar Jan 19 '24 05:01 zhengxiongli08

Hi, Gao. Have you solved this problem yet? I think I have the same problem with you.

not solved

ShylockGao avatar Jan 23 '24 07:01 ShylockGao

Does anyone know why this is happening?

AbakirH avatar Jan 25 '24 16:01 AbakirH

I have the same problem. Have you solved it?

Loewen-Hob avatar Jan 28 '24 09:01 Loewen-Hob

I think it stems from the default being wrong here - https://github.com/danielgatis/rembg/blob/0dcdb080ae083de57084c38e93fb210534c5c693/rembg/sessions/sam.py#L153

This is also relevant to #577

jalsop24 avatar Feb 02 '24 11:02 jalsop24

This is a character escaping issue. If you are running this from the cmd prompt, it should look like this:

rembg i -m sam -x "{ \"sam_prompt\": [{\"type\": \"point\", \"data\": [724, 740], \"label\": 1}] }" .\1305696_1704870215425_1705054411.png xxx.png

If you're running from PowerShell 5.1, it should look like this:

rembg i -m sam -x '{ \"sam_prompt\": [{\"type\": \"point\", \"data\": [724, 740], \"label\": 1}] }' .\1305696_1704870215425_1705054411.png xxx.png

If you're running from PowerShell 7.4, it should look like this:

rembg i -m sam -x '{ "sam_prompt": [{"type": "point", "data": [724, 740], "label": 1}] }' .\1305696_1704870215425_1705054411.png xxx.png

God-damnit-all avatar Feb 04 '24 16:02 God-damnit-all

I got the same error on the HTTP server.

How to solve this when using it interactively on the HTTP server?

yuxi-liu-wired avatar Feb 26 '24 23:02 yuxi-liu-wired

The error reporting location should be located in Link Text It means there is a problem with the json format input of your prompt.

hanqingL-bjtu avatar Mar 11 '24 09:03 hanqingL-bjtu

Hello, is anybody help me "how to to use SAM model with library usage".

I am trying to handle as following code line but I am getting error.

bg_cleaned_image = remove(data=my_image, session=rembg.new_session("sam", sam_prompt=[{"type": "point", "data": [724, 740], "label": 1}])

Error

raise error
jsonschema.exceptions.ValidationError: '{}' is not of type 'array'

Failed validating 'type' in schema:
                                       'type': 'array'},
                              'type': {'type': 'string'}},
               'type': 'object'},
     'type': 'array'}

On instance:
    '{}'

kerberosargos avatar Mar 27 '24 07:03 kerberosargos

Hello, is anybody help me "how to to use SAM model with library usage".

I am trying to handle as following code line but I am getting error.

bg_cleaned_image = remove(data=my_image, session=rembg.new_session("sam", sam_prompt=[{"type": "point", "data": [724, 740], "label": 1}])

Error

raise error
jsonschema.exceptions.ValidationError: '{}' is not of type 'array'

Failed validating 'type' in schema:
                                       'type': 'array'},
                              'type': {'type': 'string'}},
               'type': 'object'},
     'type': 'array'}

On instance:
    '{}'

Hello, Try with sam_prompt outside of the session argument. For me it works with the following code :

session_rmbg = new_session(model_name="sam") input ect... output = remove(input, session=session_rmbg, sam_prompt=[{"type": 'point', "data": [1600, 2400], "label": 1}])

aloeb-gh avatar Apr 18 '24 14:04 aloeb-gh

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

github-actions[bot] avatar May 19 '24 01:05 github-actions[bot]