Views
No views yet
| Property | Value |
|---|---|
| Architecture | efficientnet_b4 |
| Input size | 380×380 |
| Classes | 14 |
| Format | PyTorch checkpoint (.pth) |
1import torch, timm, yaml
2from PIL import Image
3import albumentations as A
4from albumentations.pytorch import ToTensorV2
5import numpy as np
6
7# Load config
8with open("config.yaml") as f:
9 cfg = yaml.safe_load(f)
10
11# Build model
12model = timm.create_model(
13 cfg["model_name"], pretrained=False,
14 num_classes=cfg["num_classes"], drop_rate=cfg["drop_rate"]
15)
16ckpt = torch.load("best_model.pth", map_location="cpu", weights_only=False)
17model.load_state_dict(ckpt["model_state_dict"])
18model.eval()
19
20# Preprocess
21tf = A.Compose([
22 A.Resize(418, 418, interpolation=2),
23 A.CenterCrop(380, 380),
24 A.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
25 ToTensorV2(),
26])
27img = np.array(Image.open("car.jpg").convert("RGB"))
28tensor = tf(image=img)["image"].unsqueeze(0) # [1, 3, H, W]
29
30# Predict
31with torch.no_grad():
32 probs = torch.softmax(model(tensor), dim=1)[0]
33top = probs.argsort(descending=True)[:3]
34classes = ['beige', 'black', 'blue', 'brown', 'gold', 'green', 'grey', 'orange', 'pink', 'purple', 'red', 'silver', 'white', 'yellow']
35for i in top:
36 print(f"{classes[i]}: {probs[i]:.2%}")tan is merged into beige during training; there is no separate tan class.torch.onnx.export(...).