danielgatis / rembg

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

sam prompting issue. Couldn't even replicate the examples #554

Closed osmancakir closed 3 months ago

osmancakir commented 6 months ago

Describe the bug

I tried to do background subtraction following the examples in the readme file. But I don't get the same results.

To Reproduce run below command adter installing rembg cli rembg i -m sam -x '{ "sam_prompt": [{"type": "point", "data": [724, 740], "label": 1}] }' examples/car-2.jpg examples/car-2_sam.png

expecting to see the examples/cars-2.out.png

but got:

car-2_sam

Can anyone tell me what am I doing wrong?

OS Version: iOS 22

Rembg version: v2.0.21

Additional context Add any other context about the problem here.

ae9is commented 6 months ago

The image is 1000x667, and the prompt point was [724,740], so the model selected the segment at the bottom of the image.

Try this instead:

rembg i -m sam -x '{ "sam_prompt": [{"type": "rectangle", "data": [115, 225, 900, 570], "label": 1}] }' examples/car-2.jpg examples/car-2_sam.png
osmancakir commented 6 months ago

The image is 1000x667, and the prompt point was [724,740], so the model selected the segment at the bottom of the image.

Try this instead:

rembg i -m sam -x '{ "sam_prompt": [{"type": "rectangle", "data": [115, 225, 900, 570], "label": 1}] }' examples/car-2.jpg examples/car-2_sam.png

Do you know a way to automate this. I would like to use SAM for human portrait matting. Or can you give me an example easy to understand how to write my own prompts for Sam for human portrait matting. thank you for the answer btw.

ae9is commented 6 months ago

Glad I could help! Was figuring out SAM prompting in this tool the other day myself, and had to check the source (ref: https://github.com/danielgatis/rembg/blob/main/rembg/sessions/sam.py#L42)

Here's a hands-on example of prompting from the official SAM repo: https://github.com/facebookresearch/segment-anything/blob/main/notebooks/predictor_example.ipynb

github-actions[bot] commented 5 months ago

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

Loewen-Hob commented 5 months ago

Hi! I'm also trying to use SAM for portrait keying, and I'm a bit out of luck at the moment. looking forward to replying and exchanging ideas!

ae9is commented 5 months ago

@Loewen-Hob If you really want to use SAM (over u2net) without point/box prompts, you can use text prompting instead (for ex.). Feel free to check out: https://github.com/IDEA-Research/Grounded-Segment-Anything. That project links out to many demos; you can also prompt using scribbles, reference images, voice.... Anyways, your timing is funny, because I also just released a tool that's basically Grounded-SAM but a bit easier for me to use: https://github.com/ae9is/ezsam. YMMV

But all this is quite off topic, and perhaps this issue could be closed? @osmancakir There's no bug in Rembg here, and it works great for what it was designed to do.

Loewen-Hob commented 5 months ago

@ae9is Okay okay thank you very much!

osmancakir commented 5 months ago

@ae9is sure, thanks for the answer ☺️ I just wanted to compare the capabilities of each model. Later I also found ModNet, for people interested, I think it is even a bit better.

github-actions[bot] commented 4 months ago

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

github-actions[bot] commented 3 months ago

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