How to specify the rembg model

2.6k Views Asked by At

I'm using rembg's model to extract images. It uses the default model. However, I want to use Python code to specify other rembg models to extract images

Rembg prompts that rembg - m can be used, but I want to use python code

2

There are 2 best solutions below

1
Mayank On

#import new_session

from rembg.bg import remove, new_session

#create a new session by passing name of the model from one of the following

#["u2net", "u2netp", "u2net_human_seg", "u2net_cloth_seg", "silueta"]

my_session = new_session("u2net_human_seg")

#set session to your custom session

remove(frame, session=my_session)

0
Mark On

Add -m + model name on the end of command.

For example: rembg p org new -m isnet-general-use.