Instructions to use OzzyGT/ben2_custom_blocks with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use OzzyGT/ben2_custom_blocks with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("OzzyGT/ben2_custom_blocks", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - BEN2
How to use OzzyGT/ben2_custom_blocks with BEN2:
import requests from PIL import Image from ben2 import AutoModel url = "https://huggingface.co/datasets/mishig/sample_images/resolve/main/teapot.jpg" image = Image.open(requests.get(url, stream=True).raw) model = AutoModel.from_pretrained("OzzyGT/ben2_custom_blocks") model.to("cuda").eval() foreground = model.inference(image) - Notebooks
- Google Colab
- Kaggle
BEN2 Modular Diffusers
Modular Diffusers blocks for BEN2 (Background Erase Network 2) by Prama LLC: remove an image's background as a soft alpha matte that keeps hair and fine edges. The blocks ship the model code and load the weights from OzzyGT/ben2_diffusers.
Usage
import torch
from diffusers import ModularPipelineBlocks
blocks = ModularPipelineBlocks.from_pretrained("OzzyGT/ben2_custom_blocks", trust_remote_code=True)
pipe = blocks.init_pipeline()
pipe.load_components(dtype=torch.float32)
pipe.to("cuda")
state = pipe(image="photo.jpg")
state.get("images")[0].save("cut_out.png") # RGBA
state.get("matte").save("matte.png") # the alpha matte alone
image is a path or a PIL image. On CUDA the model runs in float16 autocast, as the original does.
Licensing
The blocks are Apache-2.0. ben2_model.py and matte.py are adapted from
BEN2, MIT: its notice is in LICENSE-BEN2. The weights are MIT
too, see the model repository.
- Downloads last month
- 42
Model tree for OzzyGT/ben2_custom_blocks
Base model
PramaLLC/BEN2