danielgatis / rembg

Rembg is a tool to remove images background
MIT License
15.46k stars 1.76k forks source link

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

Open ShylockGao opened 5 months ago

ShylockGao commented 5 months ago

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

zhengxiongli08 commented 5 months ago

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

ShylockGao commented 5 months ago

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

not solved

AbakirH commented 5 months ago

Does anyone know why this is happening?

Loewen-Hob commented 5 months ago

I have the same problem. Have you solved it?

jalsop24 commented 5 months ago

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

Copy-link commented 5 months ago

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
yuxi-liu-wired commented 4 months ago

I got the same error on the HTTP server.

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

hanqingL-bjtu commented 4 months ago

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

kerberosargos commented 3 months ago

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:
    '{}'
aloeb-gh commented 2 months ago

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}])

github-actions[bot] commented 1 month ago

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

fuaneng commented 1 month ago

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: '{}'

这里的 prompt={} 应该改为一个数组

from rembg import remove

prompt = [{'type': 'label', 'data': [0.5, 0.5], 'label': 1}] output = remove(input, prompt=prompt)

Suvoo commented 4 weeks ago

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

Did you find a solution? I am unable to run "sam" in a python file as well? Like the library approach also failed @kerberosargos @aloeb-gh

Suvoo commented 4 weeks ago

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}])

I am getting the same issue, but I feel prompt is not the problem here :

input = Image.open(input_path)
model_name = "sam"
session = new_session(model_name)
output = remove(input, session=session)
output.save(output_path)

reproduces the same error