MobileNetV3-Large — Diabetic Retinopathy Detection
Fine-tuned MobileNetV3-Large on the Kaggle Diabetic Retinopathy Detection dataset.
Classes
| ID | Label |
|---|---|
| 0 | No DR |
| 1 | Mild |
| 2 | Moderate |
| 3 | Severe |
| 4 | Proliferative DR |
Training
- Base model: MobileNetV3-Large (ImageNet pretrained)
- Optimizer: AdamW (lr=5e-5)
- Loss: Weighted CrossEntropyLoss + Label Smoothing
- Augmentation: Mixup, Affine, RandomErasing, ColorJitter
- Epochs: up to 20 with early stopping
Usage
import torch
import torch.nn as nn
from torchvision import models, transforms
from PIL import Image
from huggingface_hub import hf_hub_download
# Load model
model = models.mobilenet_v3_large(weights=None)
model.classifier[3] = nn.Linear(model.classifier[3].in_features, 5)
path = hf_hub_download(repo_id="YOUR_USERNAME/mobilenetv3-diabetic-retinopathy",
filename="pytorch_model.bin")
model.load_state_dict(torch.load(path, map_location="cpu"))
model.eval()
# Predict
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
img = Image.open("retinal_image.jpg").convert("RGB")
with torch.no_grad():
out = model(transform(img).unsqueeze(0))
pred = out.argmax(1).item()
labels = ["No DR", "Mild", "Moderate", "Severe", "Proliferative DR"]
print(f"Prediction: {labels[pred]}")