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
Download handler.py from udman99/aina-bg-rmv: direct link, hf CLI and curl.
- Browser
- Download file 828 Bytes
-
https://huggingface.co/udman99/aina-bg-rmv/resolve/main/handler.py
- Command line
-
hf download hf://udman99/aina-bg-rmv/handler.py
-
curl -L -o handler.py https://huggingface.co/udman99/aina-bg-rmv/resolve/main/handler.py
828 Bytes
| 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}] |