ResNet-50 — Intel Image Classification
Model CNN hasil fine-tuning ResNet-50 (pra-terlatih ImageNet) untuk mengklasifikasikan gambar pemandangan ke dalam 6 kelas: buildings, forest, glacier, mountain, sea, street.
Dataset
Intel Image Classification (Kaggle) — sekitar 14 ribu gambar latih (dibagi 85% train / 15% validasi) dan 3 ribu gambar uji, ukuran 150×150.
Pelatihan
- Backbone: ResNet-50 (
IMAGENET1K_V2), head: Dropout(0.3) + Linear - Augmentasi: horizontal flip, rotasi ±15°, random resized crop, color jitter
- Loss: CrossEntropy (label smoothing 0.1)
- Optimizer: AdamW (lr backbone 1e-4, head 1e-3), Cosine Annealing, early stopping
Hasil
| Metrik | Nilai |
|---|---|
| Akurasi test | 93.67% |
Cara Menggunakan
import torch, torch.nn as nn
from torchvision import models, transforms
from huggingface_hub import hf_hub_download
from PIL import Image
path = hf_hub_download(repo_id="aleadi09/resnet50-intel-scene-classification", filename="resnet50_intel_scenes.pth")
ckpt = torch.load(path, map_location="cpu")
classes = ckpt["class_names"]
model = models.resnet50(weights=None)
model.fc = nn.Sequential(nn.Dropout(0.3), nn.Linear(model.fc.in_features, len(classes)))
model.load_state_dict(ckpt["model_state_dict"])
model.eval()
tf = transforms.Compose([
transforms.Resize((150, 150)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])
x = tf(Image.open("gambar.jpg").convert("RGB")).unsqueeze(0)
probs = torch.softmax(model(x), dim=1)[0]
print(classes[probs.argmax()], f"{probs.max().item()*100:.2f}%")