Image Segmentation
Transformers
PyTorch
ONNX
Safetensors
Transformers.js
SegformerForSemanticSegmentation
remove background
background
background-removal
Pytorch
vision
legal liability
custom_code
Instructions to use udman99/aina-bg-rmv with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use udman99/aina-bg-rmv with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="udman99/aina-bg-rmv", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForImageSegmentation model = AutoModelForImageSegmentation.from_pretrained("udman99/aina-bg-rmv", trust_remote_code=True, device_map="auto") - Transformers.js
How to use udman99/aina-bg-rmv with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('image-segmentation', 'udman99/aina-bg-rmv'); - Notebooks
- Google Colab
- Kaggle
File size: 828 Bytes
dbf18a7 88a852d dbf18a7 d3934ac dbf18a7 1c04212 9fdfc4a dbf18a7 88a852d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | from typing import Dict, List, Any
from transformers import pipeline
from PIL import Image
import base64
from io import BytesIO
class EndpointHandler():
def __init__(self, path="."):
# Initialize the image segmentation pipeline
self.pipe = pipeline("image-segmentation", model=path, trust_remote_code=True)
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
# Extract the image path from the input data
image_path = data.pop("inputs",data)
# Perform image segmentation
pillow_mask = self.pipe(image_path, return_mask=True) # outputs a pillow mask
pillow_image = self.pipe(image_path) # outputs the segmented image
# Return the result as a list of dictionaries
return [{"image": pillow_image, "mask": pillow_mask}] |