Views
No views yet
| Metric | Value |
|---|---|
| Standard validation accuracy | 0.628 |
| Holdout (leave-one-species-out) validation accuracy | 0.254 |
final_model.pth — PyTorch checkpoint (model weights + metadata)labels.json — class index mapping and metadata1import torch, timm
2from torchvision import transforms
3from PIL import Image
4from huggingface_hub import hf_hub_download
5
6path = hf_hub_download(repo_id="TigranBoyakhchyan/plant-disease-classifier", filename="final_model.pth")
7ckpt = torch.load(path, map_location="cpu", weights_only=False)
8
9model = timm.create_model(ckpt["backbone"], pretrained=False, num_classes=ckpt["num_classes"])
10model.load_state_dict(ckpt["model_state_dict"])
11model.eval()
12
13idx_to_disease = {v: k for k, v in ckpt["disease_to_idx"].items()}
14
15tfm = transforms.Compose([
16 transforms.Resize(256),
17 transforms.CenterCrop(ckpt["img_size"]),
18 transforms.ToTensor(),
19 transforms.Normalize(ckpt["mean"], ckpt["std"]),
20])
21
22img = Image.open("leaf.jpg").convert("RGB")
23x = tfm(img).unsqueeze(0)
24with torch.no_grad():
25 logits = model(x)
26pred = idx_to_disease[logits.argmax(1).item()]
27print(pred)