Dreamy0's picture
Update README.md
129b861 verified
|
raw
history blame
1.26 kB
metadata
license: mit

MaskFormer-Germination

Fine-tuned MaskFormer for germination instance segmentation.

Details

  • Base Model: facebook/maskformer-swin-tiny-coco
  • Classes: Normal (1), Abnormal (2) (mapped to COCO 134-class IDs)
  • Training Data: 18 images, 31+ annotations per image
  • Epochs: 5
  • Final Loss: 1.655
  • Batch Size: 2
  • Learning Rate: 5e-5
  • Steps: 45
  • Runtime: ~26 minutes

Usage

from transformers import MaskFormerForInstanceSegmentation, MaskFormerImageProcessor
import torch
from PIL import Image

processor = MaskFormerImageProcessor.from_pretrained("your-username/maskformer-germination")
model = MaskFormerForInstanceSegmentation.from_pretrained("your-username/maskformer-germination")
model.eval()

image = Image.open("path/to/image.jpg")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
    outputs = model(**inputs)
    results = processor.post_process_instance_segmentation(outputs, target_sizes=[(image.height, image.width)])[0]
    for score, label, mask in zip(results["scores"], results["labels"], results["masks"]):
        if score > 0.5 and label in [1, 2]:
            print(f"Label: {label}, Score: {score:.3f}, Mask shape: {mask.shape}")