Files changed (1) hide show
  1. README.md +260 -0
README.md ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ library_name: pytorch
6
+ pipeline_tag: image-classification
7
+ datasets:
8
+ - nsr51324/Oral_Diseases
9
+ metrics:
10
+ - accuracy
11
+ - precision
12
+ - recall
13
+ - f1
14
+ base_model:
15
+ - resnet50
16
+ tags:
17
+ - image-classification
18
+ - computer-vision
19
+ - medical-imaging
20
+ - dentistry
21
+ - oral-health
22
+ - resnet50
23
+ - transfer-learning
24
+ - pytorch
25
+ - deep-learning
26
+ ---
27
+
28
+ # 🦷 Oral Diseases Image Classification
29
+
30
+ A **ResNet50-based deep learning model** fine-tuned to classify **six common oral diseases** from intraoral images. This repository contains the best-performing model from a benchmark of four convolutional neural network architectures trained and evaluated under identical conditions.
31
+
32
+ πŸ† **Best Model:** ResNet50
33
+
34
+ βœ… **Accuracy:** **94.77%**
35
+
36
+ 🎯 **Macro F1-Score:** **0.9411**
37
+
38
+ 🧠 **Framework:** PyTorch
39
+
40
+ ---
41
+
42
+ # Model Overview
43
+
44
+ The model classifies the following six oral conditions:
45
+
46
+ - Calculus
47
+ - Caries
48
+ - Gingivitis
49
+ - Ulcers
50
+ - Tooth Discoloration
51
+ - Hypodontia
52
+
53
+ The final model was obtained using **transfer learning** with an ImageNet-pretrained ResNet50 and fine-tuned using a two-stage training strategy.
54
+
55
+ ---
56
+
57
+ # Benchmark Results
58
+
59
+ | Rank | Model | Trainable Parameters | Accuracy | Macro F1 |
60
+ |------|--------|--------------------:|---------:|----------:|
61
+ | πŸ₯‡ | ResNet50 | 23,520,326 | **94.77%** | **0.9411** |
62
+ | πŸ₯ˆ | DenseNet121 | 6,960,006 | 94.51% | 0.9351 |
63
+ | πŸ₯‰ | EfficientNet-B0 | 4,015,234 | 94.17% | 0.9335 |
64
+ | 4 | Scratch CNN | 11,179,590 | 83.45% | 0.8236 |
65
+
66
+ ---
67
+
68
+ # Repository Structure
69
+
70
+ ```
71
+ checkpoints/
72
+ │── best_model.pth
73
+
74
+ notebooks/
75
+ │── oral-disseases-image-classification.ipynb
76
+
77
+ outputs/
78
+ │── models_comparison.csv
79
+ │── resnet50_confusion_matrix.png
80
+ │── resnet50_history.png
81
+ │── densenet121_confusion_matrix.png
82
+ │── densenet121_history.png
83
+ │── efficientnet_b0_confusion_matrix.png
84
+ │── efficientnet_b0_history.png
85
+ │── scratch_cnn_confusion_matrix.png
86
+ │── scratch_cnn_history.png
87
+
88
+ Gradio.py
89
+ README.md
90
+ ```
91
+
92
+ ---
93
+
94
+ # Download
95
+
96
+ ## Model Weights
97
+
98
+ The trained checkpoint is available in:
99
+
100
+ ```
101
+ checkpoints/best_model.pth
102
+ ```
103
+
104
+ or can be downloaded directly from this repository.
105
+
106
+ ---
107
+
108
+ ## Dataset
109
+
110
+ Training dataset:
111
+
112
+ https://huggingface.co/datasets/nsr51324/Oral_Diseases
113
+
114
+ Original source:
115
+
116
+ Oral Diseases Dataset (Kaggle)
117
+
118
+ ---
119
+
120
+ # How to Load the Model
121
+
122
+ ```python
123
+ from huggingface_hub import hf_hub_download
124
+ import torch
125
+
126
+ weights_path = hf_hub_download(
127
+ repo_id="nsr51324/Oral_Diseases_Image_Classification",
128
+ filename="checkpoints/best_model.pth"
129
+ )
130
+
131
+ checkpoint = torch.load(weights_path, map_location="cpu")
132
+ class_names = checkpoint["class_names"]
133
+ ```
134
+
135
+ ---
136
+
137
+ # Inference
138
+
139
+ ```python
140
+ import torch
141
+ import torch.nn as nn
142
+ from torchvision.models import resnet50
143
+ from torchvision import transforms
144
+ from PIL import Image
145
+
146
+ model = resnet50(weights=None)
147
+
148
+ model.fc = nn.Sequential(
149
+ nn.Dropout(0.3),
150
+ nn.Linear(model.fc.in_features, len(class_names))
151
+ )
152
+
153
+ model.load_state_dict(checkpoint["state_dict"])
154
+ model.eval()
155
+
156
+ transform = transforms.Compose([
157
+ transforms.Resize((224,224)),
158
+ transforms.ToTensor(),
159
+ transforms.Normalize(
160
+ [0.485,0.456,0.406],
161
+ [0.229,0.224,0.225]
162
+ )
163
+ ])
164
+
165
+ image = Image.open("sample.jpg").convert("RGB")
166
+ tensor = transform(image).unsqueeze(0)
167
+
168
+ with torch.no_grad():
169
+ probabilities = torch.softmax(model(tensor), dim=1)[0]
170
+
171
+ prediction = class_names[probabilities.argmax().item()]
172
+
173
+ print(prediction)
174
+ ```
175
+
176
+ ---
177
+
178
+ # Interactive Demo
179
+
180
+ A standalone Gradio application is included.
181
+
182
+ Run:
183
+
184
+ ```bash
185
+ pip install torch torchvision gradio pillow huggingface_hub
186
+
187
+ python Gradio.py
188
+ ```
189
+
190
+ ---
191
+
192
+ # Training Details
193
+
194
+ | Item | Value |
195
+ |------|-------|
196
+ | Image Size | 224 Γ— 224 |
197
+ | Batch Size | 32 |
198
+ | Epochs | Up to 30 |
199
+ | Optimizer | Adam |
200
+ | Early Stopping | Yes |
201
+ | Weight Decay | 1e-4 |
202
+ | Label Smoothing | 0.1 |
203
+ | Dropout | 0.4 |
204
+
205
+ Training consisted of two stages:
206
+
207
+ 1. Freeze the ResNet50 backbone and train the classifier head.
208
+ 2. Unfreeze the backbone and fine-tune the entire network.
209
+
210
+ ---
211
+
212
+ # Data Augmentation
213
+
214
+ The following augmentations were applied during training:
215
+
216
+ - Random Resized Crop
217
+ - Horizontal Flip
218
+ - Rotation
219
+ - Color Jitter
220
+ - Random Erasing
221
+
222
+ ---
223
+
224
+ # Evaluation
225
+
226
+ The repository includes:
227
+
228
+ - Confusion matrices
229
+ - Training history
230
+ - Classification metrics
231
+ - Model comparison
232
+ - CSV benchmark results
233
+
234
+ See the **outputs/** directory for complete evaluation results.
235
+
236
+ ---
237
+
238
+ # Intended Use
239
+
240
+ This model is intended for **research, educational purposes, and AI experimentation**.
241
+
242
+ It is **not** a certified medical device and **must not** be used as a substitute for professional clinical diagnosis.
243
+
244
+ ---
245
+
246
+ # License
247
+
248
+ This project is released under the **MIT License**.
249
+
250
+ Please refer to the dataset license before commercial use.
251
+
252
+ ---
253
+
254
+ # Author
255
+
256
+ **Nasr Mohamed**
257
+
258
+ AI Engineer
259
+
260
+ πŸ€— https://huggingface.co/nsr51324