Views
No views yet
facebook/maskformer-swin-tiny-coco0: Background1: Normal2: Abnormal1from transformers import MaskFormerForInstanceSegmentation, MaskFormerImageProcessor
2import torch
3from PIL import Image
4
5processor = MaskFormerImageProcessor.from_pretrained("Dreamy0/GermiNet-instance-segmentation-maskformer")
6model = MaskFormerForInstanceSegmentation.from_pretrained("Dreamy0/GermiNet-instance-segmentation-maskformer")
7model.eval()
8
9image = Image.open("path/to/image.jpg")
10inputs = processor(images=image, return_tensors="pt")
11with torch.no_grad():
12 outputs = model(**inputs)
13 results = processor.post_process_instance_segmentation(outputs, target_sizes=[(image.height, image.width)])[0]
14 for score, label, mask in zip(results["scores"], results["labels"], results["masks"]):
15 if score > 0.5 and label in [1, 2]:
16 print(f"Label: {label} ({model.config.id2label[label]}), Score: {score:.3f}, Mask shape: {mask.shape}")