Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
tags:
|
6 |
+
- image-classification
|
7 |
+
- medical-imaging
|
8 |
+
- diabetic-retinopathy
|
9 |
+
- resnet
|
10 |
+
- sih-2025
|
11 |
+
---
|
12 |
+
|
13 |
+
Fine-Tuned ResNet50 for Diabetic Retinopathy Grading
|
14 |
+
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.
|
15 |
+
|
16 |
+
This model was trained as a prototype for the Smart India Hackathon (SIH) 2025.
|
17 |
+
|
18 |
+
Model Details
|
19 |
+
Model Architecture: ResNet50
|
20 |
+
|
21 |
+
Pre-trained on: ImageNet-1K (V1)
|
22 |
+
|
23 |
+
Fine-tuned on: IDRiD (Indian Diabetic Retinopathy Image Dataset)
|
24 |
+
|
25 |
+
Task: Image Classification
|
26 |
+
|
27 |
+
Classes (5):
|
28 |
+
|
29 |
+
Grade 0: No DR
|
30 |
+
|
31 |
+
Grade 1: Mild
|
32 |
+
|
33 |
+
Grade 2: Moderate
|
34 |
+
|
35 |
+
Grade 3: Severe
|
36 |
+
|
37 |
+
Grade 4: Proliferative DR
|
38 |
+
|
39 |
+
How to Use
|
40 |
+
To use this model, you need to have torch and torchvision installed.
|
41 |
+
|
42 |
+
import torch
|
43 |
+
import torchvision
|
44 |
+
from torchvision import models, transforms
|
45 |
+
from PIL import Image
|
46 |
+
|
47 |
+
# 1. Define the model architecture
|
48 |
+
model = models.resnet50(weights=None)
|
49 |
+
num_ftrs = model.fc.in_features
|
50 |
+
model.fc = torch.nn.Linear(num_ftrs, 5) # 5 classes
|
51 |
+
|
52 |
+
# 2. Load the fine-tuned weights from the Hub
|
53 |
+
weights_path = hf_hub_download(repo_id="Arko007/Diabetic-Retinopathy", filename="resnet50_finetuned_retinopathy.pth")
|
54 |
+
model.load_state_dict(torch.load(weights_path, map_location='cpu'))
|
55 |
+
model.eval()
|
56 |
+
|
57 |
+
# 3. Create the same data transform used for validation/testing
|
58 |
+
transform = transforms.Compose([
|
59 |
+
transforms.Resize((224, 224)),
|
60 |
+
transforms.ToTensor(),
|
61 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
62 |
+
])
|
63 |
+
|
64 |
+
# 4. Load an image and make a prediction
|
65 |
+
# Make sure to replace 'path/to/your/image.jpg'
|
66 |
+
img = Image.open('path/to/your/image.jpg').convert('RGB')
|
67 |
+
img_t = transform(img)
|
68 |
+
batch_t = torch.unsqueeze(img_t, 0)
|
69 |
+
|
70 |
+
with torch.no_grad():
|
71 |
+
output = model(batch_t)
|
72 |
+
_, predicted_idx = torch.max(output, 1)
|
73 |
+
|
74 |
+
class_names = ['No DR', 'Mild', 'Moderate', 'Severe', 'Proliferative DR']
|
75 |
+
print(f"Prediction: {class_names[predicted_idx.item()]}")
|
76 |
+
|
77 |
+
|
78 |
+
Evaluation Results
|
79 |
+
The model was evaluated on a held-out test set from the IDRiD dataset.
|
80 |
+
|
81 |
+
Confusion Matrix:
|
82 |
+
|
83 |
+
(Upload your confusion_matrix_resnet50.png file here)
|
84 |
+
|
85 |
+
Classification Report:
|
86 |
+
|
87 |
+
[PASTE THE CLASSIFICATION REPORT FROM YOUR TRAINING SCRIPT'S FINAL OUTPUT HERE]
|
88 |
+
|
89 |
+
Training Procedure
|
90 |
+
The model was trained on an NVIDIA A100 GPU using a two-phase transfer learning strategy:
|
91 |
+
|
92 |
+
Head Training: The pre-trained ResNet50 backbone was frozen, and only the new classification head was trained for 15 epochs.
|
93 |
+
|
94 |
+
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.
|
95 |
+
|
96 |
+
Key hyperparameters:
|
97 |
+
|
98 |
+
Image Size: 224x224
|
99 |
+
|
100 |
+
Batch Size: 128
|
101 |
+
|
102 |
+
Optimizer: Adam
|
103 |
+
|
104 |
+
Loss Function: Cross-Entropy Loss with class weights to handle imbalance.
|