integrate with transformers

#21

this pr will fix the integration with the transformers library fully

following https://github.com/huggingface/transformers/pull/29262 there is no need to further use the method i used in pr-9

I have fixed the requirements.txt and the README.md 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 https://huggingface.co/briaai/RMBG-1.4/resolve/main/requirements.txt && pip install -qr requirements.txt
pip install -q git+https://github.com/huggingface/transformers.git
from transformers import pipeline
pipe = pipeline("image-segmentation", 
  model="briaai/RMBG-1.4",
  revision ="refs/pr/21", # only when using the pr
  trust_remote_code=True)
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

Sincerely,

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.

Regards,

  • Hafedh Hichri
OriLib changed pull request status to merged

Yay! That's really cool πŸš€

Just small nit but instead of

wget https://huggingface.co/briaai/RMBG-1.4/resolve/main/requirements.txt && pip install -qr requirements.txt

you can do

pip install -qr https://huggingface.co/briaai/RMBG-1.4/resolve/main/requirements.txt

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.

BRIA AI org

@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