Arko007's picture
Create README.md
21c28c7 verified
|
raw
history blame
2.86 kB
metadata
license: mit
language:
  - en
tags:
  - image-classification
  - medical-imaging
  - diabetic-retinopathy
  - resnet
  - sih-2025

Fine-Tuned ResNet50 for Diabetic Retinopathy Grading This is a ResNet50 model fine-tuned for the task of Diabetic Retinopathy (DR) grading based on fundus images. The model classifies a given retina scan into one of five severity grades, following the International Clinical Diabetic Retinopathy scale.

This model was trained as a prototype for the Smart India Hackathon (SIH) 2025.

Model Details Model Architecture: ResNet50

Pre-trained on: ImageNet-1K (V1)

Fine-tuned on: IDRiD (Indian Diabetic Retinopathy Image Dataset)

Task: Image Classification

Classes (5):

Grade 0: No DR

Grade 1: Mild

Grade 2: Moderate

Grade 3: Severe

Grade 4: Proliferative DR

How to Use To use this model, you need to have torch and torchvision installed.

import torch import torchvision from torchvision import models, transforms from PIL import Image

1. Define the model architecture

model = models.resnet50(weights=None) num_ftrs = model.fc.in_features model.fc = torch.nn.Linear(num_ftrs, 5) # 5 classes

2. Load the fine-tuned weights from the Hub

weights_path = hf_hub_download(repo_id="Arko007/Diabetic-Retinopathy", filename="resnet50_finetuned_retinopathy.pth") model.load_state_dict(torch.load(weights_path, map_location='cpu')) model.eval()

3. Create the same data transform used for validation/testing

transform = transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) ])

4. Load an image and make a prediction

Make sure to replace 'path/to/your/image.jpg'

img = Image.open('path/to/your/image.jpg').convert('RGB') img_t = transform(img) batch_t = torch.unsqueeze(img_t, 0)

with torch.no_grad(): output = model(batch_t) _, predicted_idx = torch.max(output, 1)

class_names = ['No DR', 'Mild', 'Moderate', 'Severe', 'Proliferative DR'] print(f"Prediction: {class_names[predicted_idx.item()]}")

Evaluation Results The model was evaluated on a held-out test set from the IDRiD dataset.

Confusion Matrix:

(Upload your confusion_matrix_resnet50.png file here)

Classification Report:

[PASTE THE CLASSIFICATION REPORT FROM YOUR TRAINING SCRIPT'S FINAL OUTPUT HERE]

Training Procedure The model was trained on an NVIDIA A100 GPU using a two-phase transfer learning strategy:

Head Training: The pre-trained ResNet50 backbone was frozen, and only the new classification head was trained for 15 epochs.

Fine-Tuning: The entire model was unfrozen and trained for an additional 30 epochs with a much smaller learning rate to fine-tune the deep features.

Key hyperparameters:

Image Size: 224x224

Batch Size: 128

Optimizer: Adam

Loss Function: Cross-Entropy Loss with class weights to handle imbalance.