from PIL import Image
import torch
from torchvision import transforms
from transformers import AutoModelForImageSegmentation
# load model
device = 'cuda'if torch.cuda.is_available() else'cpu'
model = AutoModelForImageSegmentation.from_pretrained('briaai/VRMBG-2.0', trust_remote_code=True).eval().half().to(device)
model = torch.compile(model, dynamic=False, backend="inductor")
# Data settings
image_size = (1024, 1024)
transform_image = transforms.Compose([
transforms.Resize(image_size),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
# load inputs
image_prev_frame_path = ""# fill path
image_current_frame_path = ""# fill path
image_prev_frame = Image.open(image_prev_frame_path)
image_current_frame = Image.open(image_current_frame_path)
input_frames = torch.cat([transform_image(image_prev_frame), transform_image(image_current_frame)], dim=0)
input_frames = input_frames.unsqueeze(0).to(device).half()
# Predictionwith torch.no_grad():
preds = model(input_frames).cpu()
pred = preds[0].squeeze()
pred_pil = transforms.ToPILImage()(pred)
mask = pred_pil.resize(image_current_frame.size)
# save result
image_current_frame.putalpha(mask)
image_current_frame.save("image_current_frame_no_background.png")
Runs of briaai VRMBG-2.0 on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About VRMBG-2.0 huggingface.co Model
VRMBG-2.0 huggingface.co
VRMBG-2.0 huggingface.co is an AI model on huggingface.co that provides VRMBG-2.0's model effect (), which can be used instantly with this briaai VRMBG-2.0 model. huggingface.co supports a free trial of the VRMBG-2.0 model, and also provides paid use of the VRMBG-2.0. Support call VRMBG-2.0 model through api, including Node.js, Python, http.
VRMBG-2.0 huggingface.co is an online trial and call api platform, which integrates VRMBG-2.0's modeling effects, including api services, and provides a free online trial of VRMBG-2.0, you can try VRMBG-2.0 online for free by clicking the link below.
briaai VRMBG-2.0 online free url in huggingface.co:
VRMBG-2.0 is an open source model from GitHub that offers a free installation service, and any user can find VRMBG-2.0 on GitHub to install. At the same time, huggingface.co provides the effect of VRMBG-2.0 install, users can directly use VRMBG-2.0 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.