Update README.md
Browse files
README.md
CHANGED
|
@@ -4,6 +4,56 @@ tags:
|
|
| 4 |
- pytorch_model_hub_mixin
|
| 5 |
---
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
- pytorch_model_hub_mixin
|
| 5 |
---
|
| 6 |
|
| 7 |
+
# Model Card: MRI Brain Tumor Classification (ResNet-18)
|
| 8 |
+
|
| 9 |
+
## Model Details
|
| 10 |
+
- **Model Name**: `MRIResnet`
|
| 11 |
+
- **Architecture**: ResNet-18-based model for MRI brain tumor classification
|
| 12 |
+
- **Dataset**: [Brain Tumor MRI Dataset](https://www.kaggle.com/datasets/masoudnickparvar/brain-tumor-mri-dataset)
|
| 13 |
+
- **Batch Size**: 32
|
| 14 |
+
- **Loss Function**: CrossEntropy Loss
|
| 15 |
+
- **Optimizer**: Adam (learning rate = 1e-3)
|
| 16 |
+
- **Transfer Learning**: Yes (pretrained ResNet-18 with modified layers)
|
| 17 |
+
|
| 18 |
+
## Model Architecture
|
| 19 |
+
This model is based on **ResNet-18**, a widely used convolutional neural network, and has been adapted for **MRI-based brain tumor classification**.
|
| 20 |
+
|
| 21 |
+
### **Modifications**
|
| 22 |
+
- **Input Channel Adaptation**: The first convolutional layer is modified to accept single-channel (grayscale) MRI scans.
|
| 23 |
+
- **Classifier Head**: The fully connected (FC) layer is replaced to output 4 classes (assuming 4 tumor categories).
|
| 24 |
+
- **Transfer Learning**:
|
| 25 |
+
- **Frozen Layers**: All pre-trained weights are frozen except for the modified layers.
|
| 26 |
+
- **Trainable Layers**:
|
| 27 |
+
- First convolutional layer (`conv1`)
|
| 28 |
+
- Fully connected classification layer (`fc`)
|
| 29 |
+
|
| 30 |
+
## Implementation
|
| 31 |
+
### **Model Definition**
|
| 32 |
+
```python
|
| 33 |
+
import torch
|
| 34 |
+
import torch.nn as nn
|
| 35 |
+
from torchvision.models import resnet18
|
| 36 |
+
|
| 37 |
+
class MRIResnet(nn.Module, PyTorchModelHubMixin):
|
| 38 |
+
def __init__(self):
|
| 39 |
+
super().__init__()
|
| 40 |
+
self.base_model = resnet18(weights=True)
|
| 41 |
+
self.base_model.conv1 = nn.Conv2d(
|
| 42 |
+
1, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False
|
| 43 |
+
)
|
| 44 |
+
self.base_model.fc = nn.Linear(512, 4)
|
| 45 |
+
|
| 46 |
+
# Freeze all layers except the modified ones
|
| 47 |
+
for param in self.base_model.parameters():
|
| 48 |
+
param.requires_grad = False
|
| 49 |
+
|
| 50 |
+
for param in self.base_model.conv1.parameters():
|
| 51 |
+
param.requires_grad = True
|
| 52 |
+
for param in self.base_model.fc.parameters():
|
| 53 |
+
param.requires_grad = True
|
| 54 |
+
|
| 55 |
+
def forward(self, x):
|
| 56 |
+
return self.base_model(x)
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
|