Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ShylockGao opened this issue Jan 15, 2024 · 12 comments
Open

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

ShylockGao opened this issue Jan 15, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@ShylockGao
Copy link

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 ShylockGao added the bug Something isn't working label Jan 15, 2024
@zhengxiongli08
Copy link

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

@ShylockGao
Copy link
Author

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

not solved

@AbakirH
Copy link

AbakirH commented Jan 25, 2024

Does anyone know why this is happening?

@Loewen-Hob
Copy link

I have the same problem. Have you solved it?

@jalsop24
Copy link
Contributor

jalsop24 commented Feb 2, 2024

I think it stems from the default being wrong here -

prompt = kwargs.get("sam_prompt", "{}")

This is also relevant to #577

@ImportTaste
Copy link

ImportTaste commented Feb 4, 2024

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
Copy link

yuxi-liu-wired commented Feb 26, 2024

I got the same error on the HTTP server.

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

@hanqingL-bjtu
Copy link

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
Copy link

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
Copy link

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

Copy link

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

@github-actions github-actions bot added the stale label May 19, 2024
@fuaneng
Copy link

fuaneng commented May 30, 2024

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)

@github-actions github-actions bot removed the stale label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests