Views
No views yet
1from transformers import AutoImageProcessor, SegformerForSemanticSegmentation
2import torch, torch.nn.functional as F
3from PIL import Image
4import numpy as np
5
6repo = "GlobalWheat/GWFSS_model_v1.0"
7processor = AutoImageProcessor.from_pretrained(repo)
8model = SegformerForSemanticSegmentation.from_pretrained(repo).eval()
9
10img = Image.open("example.jpg").convert("RGB")
11inputs = processor(images=img, return_tensors="pt")
12with torch.no_grad():
13 logits = model(**inputs).logits
14 up = F.interpolate(logits, size=(img.height, img.width), mode="bilinear", align_corners=False)
15pred = up.argmax(1)[0].cpu().numpy() # (H, W) class IDs