integrate with transformers


this pr will fix the integration with the transformers library fully

following there is no need to further use the method i used in pr-9

I have fixed the requirements.txt and the files for future users beforehand so no need to change those.

this is some extra bit of code to test the pr before mergin

wget && pip install -qr requirements.txt
pip install -q git+
from transformers import pipeline
pipe = pipeline("image-segmentation", 
  revision ="refs/pr/21", # only when using the pr
pipe("image_path",out_name="myout.png") # applies mask and saves the extracted image as `myout.png`

after merging this feel free to change and customize the pipeline to your liking.

I also wanted to give a shout-out to @MishaF for being such a friendly person ✨
also friendly pinging @OriLib for review


Hafedh Hichri

since the new release of the transformers library is out I have pinned the version to the requirements.txt file, I also chose to change how to use pipeline to these 2 cases

pipe("image_path") # returns pillow image without background
pipe("image_path", return_mask=True) # returns the mask

I think this is way easier for users to use since they are mostly using the image without background rather than the mask.
as always the readme file has been updated with clear instructions on how to use the model.


  • Hafedh Hichri
OriLib changed pull request status to merged

Yay! That's really cool πŸš€

Just small nit but instead of

wget && pip install -qr requirements.txt

you can do

pip install -qr

which is even cleaner in my opinion.

Also, in the requirements.txt, I would not pin to a specific transformers version but rather to transformers>=4.39.1 instead. Otherwise it might prevent users to install RMBG-1.4 in their environment.


@not-lain again many thanks for your great contribution

@OriLib don't mention it, glad I was able to help out ✨✨

Sign up or log in to comment