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

Closed
ShylockGao opened this issue Jan 15, 2024 · 17 comments
Closed

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

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

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

@God-damnit-all
Copy link

God-damnit-all 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
@Suvoo
Copy link

Suvoo commented Jun 13, 2024

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

Suvoo commented Jun 13, 2024

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

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 Jul 15, 2024
Copy link

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

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 30, 2024
@manindertaggar
Copy link

@Suvoo You are getting that error because sam_prompt is a mandatory field.
See sam.py, Line 145
Screenshot 2024-08-01 at 7 35 19 PM

Try passing the input_labels and data as follows, should work.

input = Image.open(input_path)

output = remove(input,
                session=new_session("sam"),
                sam_prompt=[{"type": "point", "data": [10, 10], "label": 0}])
output.save(output_path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests