anishanish383 commited on
Commit
40d045c
·
verified ·
1 Parent(s): b4bd2b0

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +165 -0
README.md ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - diabetic-retinopathy
4
+ - medical-imaging
5
+ - classification
6
+ - pytorch
7
+ - efficientnet
8
+ - fundus
9
+ - ophthalmology
10
+ license: mit
11
+ library_name: pytorch
12
+ datasets:
13
+ - mariaherrerot/aptos2019
14
+ language:
15
+ - en
16
+ metrics:
17
+ - cohen_kappa
18
+ - accuracy
19
+ - f1
20
+ pipeline_tag: image-classification
21
+ ---
22
+
23
+ # DR Detection — EfficientNet-B4
24
+
25
+ Automated Diabetic Retinopathy (DR) severity grading from retinal fundus images, fine-tuned on APTOS 2019 dataset. This is the **primary model** of a comparative study (vs. ResNet-50 baseline).
26
+
27
+ **Source code:** https://github.com/anish030803/Computer-Vison-
28
+
29
+ ## Model Details
30
+
31
+ - **Architecture:** EfficientNet-B4 (via `timm` — `tf_efficientnet_b4_ns`, NoisyStudent pretrained)
32
+ - **Custom Head:** Global Average Pool → BatchNorm → Dropout(0.4) → Linear(1792→256, ReLU) → Dropout(0.3) → Linear(256→5)
33
+ - **Input:** 380×380 RGB fundus images
34
+ - **Output:** 5-class probabilities
35
+ - **Parameters:** 18M
36
+ - **Preprocessing:** Ben Graham's method (resize → circular crop → Gaussian blur subtraction → normalize)
37
+
38
+ ## Severity Grades
39
+
40
+ | Grade | Label | Description |
41
+ |-------|-------|-------------|
42
+ | 0 | No DR | No visible retinopathy |
43
+ | 1 | Mild NPDR | Microaneurysms only |
44
+ | 2 | Moderate NPDR | More than just microaneurysms |
45
+ | 3 | Severe NPDR | Extensive intraretinal hemorrhages |
46
+ | 4 | Proliferative DR | Neovascularization or vitreous hemorrhage |
47
+
48
+ ## Performance
49
+
50
+ **5-Fold Stratified Cross-Validation** (10% held-out test set):
51
+
52
+ | Metric | Mean ± Std | Held-Out Test |
53
+ |--------|-----------|---------------|
54
+ | **Quadratic Weighted Kappa (QWK)** | **0.8187 ± 0.0253** | **0.8076** |
55
+ | Accuracy | 0.7355 ± 0.0270 | 0.7361 |
56
+ | Macro F1 | 0.5849 ± 0.0326 | — |
57
+ | Severe DR Recall | 0.5847 ± 0.0522 | 0.5714 |
58
+ | Proliferative DR Recall | 0.4318 ± 0.0844 | 0.4091 |
59
+
60
+ **vs. ResNet-50 baseline:** EfficientNet-B4 improves QWK by ~0.06 (0.7281 → 0.7884 single run, 0.8187 in 5-fold CV).
61
+
62
+ ## Training
63
+
64
+ - **Hardware:** NVIDIA A100 80GB (Northeastern Explorer HPC)
65
+ - **Mixed precision:** BF16
66
+ - **Two-phase strategy:**
67
+ - **Phase 1 (warmup):** Frozen backbone, train classification head only, 20 epochs, LR=1e-3 with linear warmup → cosine annealing
68
+ - **Phase 2 (fine-tuning):** Top 30-50% of backbone unfrozen, 25 epochs, LR=1e-5 with cosine annealing + warm restarts
69
+ - **Loss:** Class-weighted cross-entropy with label smoothing (0.1) — class weights auto-computed from inverse frequency
70
+ - **Augmentation:** Horizontal/vertical flips, rotation ±36°, zoom 90-110%, brightness/contrast ±10%, MixUp (α=0.2)
71
+ - **Regularization:** Dropout, weight decay (1e-4), gradient clipping (max norm 1.0), early stopping (patience=5-7 on val_qwk)
72
+ - **Optimizer:** AdamW (β=[0.9, 0.999])
73
+
74
+ ## Dataset
75
+
76
+ **APTOS 2019 Blindness Detection** (Kaggle):
77
+ - Original: 3,662 training images
78
+ - After cleaning: **2,681 images**
79
+ - Class distribution: 49% No DR, 10% Mild, 28% Moderate, 5% Severe, 8% Proliferative
80
+ - Imbalance ratio: 9.5x
81
+
82
+ Cleaning pipeline (5 passes): file integrity, duplicates (pHash hamming < 3), quality (sharpness/brightness/contrast 2nd percentile cutoffs), resolution (min 256x256), label verification.
83
+
84
+ ## Usage
85
+
86
+ ```python
87
+ import torch
88
+ import cv2
89
+ import numpy as np
90
+ import torch.nn.functional as F
91
+ from huggingface_hub import hf_hub_download
92
+
93
+ # Download checkpoint
94
+ ckpt_path = hf_hub_download(repo_id="anishanish383/dr-detection-efficientnet-b4", filename="best.pt")
95
+
96
+ # Load model (requires source code from https://github.com/anish030803/Computer-Vison-)
97
+ from src.models.efficientnet import build_efficientnet
98
+ from src.utils.config import load_config
99
+ from src.utils.checkpoint import load_checkpoint
100
+
101
+ config = load_config("configs/train_efficientnet.yaml")
102
+ model = build_efficientnet(config)
103
+ load_checkpoint(ckpt_path, model)
104
+ model.eval()
105
+
106
+ # Preprocess image
107
+ from src.data.preprocessing import ben_graham_preprocess
108
+ img = cv2.imread("fundus.png")
109
+ preprocessed = ben_graham_preprocess(img, target_size=380)
110
+ mean = np.array([0.485, 0.456, 0.406])
111
+ std = np.array([0.229, 0.224, 0.225])
112
+ normalized = (preprocessed - mean) / std
113
+ tensor = torch.from_numpy(normalized.transpose(2, 0, 1)).float().unsqueeze(0)
114
+
115
+ # Predict
116
+ with torch.no_grad():
117
+ logits = model(tensor)
118
+ probs = F.softmax(logits, dim=-1)[0]
119
+
120
+ class_names = ["No DR", "Mild NPDR", "Moderate NPDR", "Severe NPDR", "Proliferative DR"]
121
+ print(f"Prediction: {class_names[probs.argmax().item()]} ({probs.max().item():.2%})")
122
+ ```
123
+
124
+ ## Limitations
125
+
126
+ ⚠️ **This model is for research and educational use only — not approved for clinical diagnosis.**
127
+
128
+ - **Severe DR Recall (0.58)** and **Proliferative DR Recall (0.43)** are below clinical thresholds (≥0.80). The model misses too many severe/sight-threatening cases.
129
+ - Trained on a single dataset (APTOS 2019, India). Performance may degrade on different populations, camera types, or imaging conditions.
130
+ - Class imbalance (9.5x) makes rare-class detection difficult.
131
+ - Not validated on external datasets (Messidor-2, EyePACS, etc.).
132
+
133
+ **Suitable for:** screening triage, research, educational demos.
134
+ **NOT suitable for:** autonomous clinical diagnosis, replacing ophthalmologist review.
135
+
136
+ ## Citation
137
+
138
+ If you use this model, please cite the original works:
139
+
140
+ ```bibtex
141
+ @article{tan2019efficientnet,
142
+ title={EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks},
143
+ author={Tan, Mingxing and Le, Quoc V},
144
+ journal={ICML},
145
+ year={2019}
146
+ }
147
+
148
+ @misc{aptos2019,
149
+ title={APTOS 2019 Blindness Detection},
150
+ author={Asia Pacific Tele-Ophthalmology Society},
151
+ year={2019},
152
+ publisher={Kaggle}
153
+ }
154
+
155
+ @misc{graham2015,
156
+ title={Kaggle Diabetic Retinopathy Detection Competition Report},
157
+ author={Graham, Ben},
158
+ year={2015},
159
+ publisher={University of Warwick}
160
+ }
161
+ ```
162
+
163
+ ## License
164
+
165
+ MIT