Views
No views yet
1from transformers import Mask2FormerForUniversalSegmentation, Mask2FormerImageProcessor
2import torch
3from PIL import Image
4
5# Load model and processor
6model = Mask2FormerForUniversalSegmentation.from_pretrained("{your-username}/mask2former-segmentation")
7processor = Mask2FormerImageProcessor.from_pretrained("{your-username}/mask2former-segmentation")
8
9# Prepare image
10image = Image.open("your_image.jpg")
11inputs = processor(images=image, return_tensors="pt")
12
13# Make prediction
14with torch.no_grad():
15 outputs = model(**inputs)
16
17# Process outputs for visualization
18# (see example code in model repository)