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