nyuuzyou/aircraft-images
Updated • 644 • 2
How to use t1an-xyz/plane-classifier with timm:
import timm
model = timm.create_model("hf-hub:t1an-xyz/plane-classifier", pretrained=True)Fine-tuned MobileNetV4 (mobilenetv4_conv_medium) classifying 16 commercial aircraft families from planespotting photos and camera crops.
Trained on the nyuuzyou/aircraft-images dataset with heavy field corruptions (blur, crops, noise, contrast, weather shift) to make predictions robust to phone photos and landing approaches.
import torch
import timm
from torchvision import transforms
from PIL import Image
from huggingface_hub import hf_hub_download
REPO_ID = "t1an-xyz/plane-classifier"
# 1. Download checkpoint from Hugging Face
ckpt_path = hf_hub_download(repo_id=REPO_ID, filename="plane_classifier_checkpoint.pt")
ckpt = torch.load(ckpt_path, map_location="cpu", weights_only=False)
classes = ckpt["classes"]
model_name = ckpt["model_name"]
img_size = ckpt.get("img_size", (256, 256))
norm_mean = ckpt.get("norm_mean", (0.485, 0.456, 0.406))
norm_std = ckpt.get("norm_std", (0.229, 0.224, 0.225))
# 2. Reconstruct timm model & load weights
model = timm.create_model(model_name, pretrained=False, num_classes=len(classes))
model.load_state_dict(ckpt["state_dict"])
model.eval()
# 3. Preprocess image
preprocess = transforms.Compose([
transforms.Resize(img_size),
transforms.ToTensor(),
transforms.Normalize(mean=norm_mean, std=norm_std),
])
img = Image.open("plane.jpg").convert("RGB")
input_tensor = preprocess(img).unsqueeze(0)
# 4. Predict
with torch.no_grad():
logits = model(input_tensor)
probs = torch.softmax(logits, dim=1)[0]
top3_indices = torch.topk(probs, k=3).indices.tolist()
for idx in top3_indices:
print(f"{classes[idx]}: {probs[idx]:.2%}")
Base model
timm/mobilenetv4_conv_medium.e500_r256_in1k