NiksheyYadav commited on
Commit
6ae5507
·
1 Parent(s): 4dcd42a

Update README with GitHub repo links

Browse files
Files changed (1) hide show
  1. README.md +88 -16
README.md CHANGED
@@ -21,14 +21,17 @@ library_name: pytorch
21
 
22
  # MRI Brain Tumor Classification Models
23
 
24
- This repository contains trained deep learning models for MRI brain scan classification, developed using Mojo and PyTorch.
 
 
 
 
 
25
 
26
  ## Models
27
 
28
  ### 1. Brain Tumor 2D CNN (`kaggle_tumor_2dcnn_best.pth`)
29
 
30
- **Task:** Multi-class brain tumor classification from MRI slices
31
-
32
  | Metric | Value |
33
  |--------|-------|
34
  | **Accuracy** | 93.95% |
@@ -36,28 +39,65 @@ This repository contains trained deep learning models for MRI brain scan classif
36
  | **Recall** | 0.94 |
37
  | **F1 Score** | 0.94 |
38
 
39
- **Classes:**
40
- - `glioma` - 98.1% accuracy
41
- - `meningioma` - 83.9% accuracy
42
- - `notumor` - 98.5% accuracy
43
- - `pituitary` - 94.3% accuracy
44
-
45
- **Architecture:** 2D CNN with 4 convolutional blocks, 4.85M parameters
46
 
47
  ### 2. IXI 3D Brain CNN (`ixi_3dcnn_best.pth`)
48
 
49
- **Task:** 3D brain MRI volume classification
50
- **Architecture:** 3D CNN with 4 Conv3D blocks, 1.2M parameters
51
 
52
  ## Quick Start
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  ```python
55
  import torch
56
  import torch.nn as nn
57
  from torchvision import transforms
58
  from PIL import Image
59
 
60
- # Define model
61
  class TumorCNN(nn.Module):
62
  def __init__(self, num_classes=4):
63
  super().__init__()
@@ -82,11 +122,12 @@ class TumorCNN(nn.Module):
82
  def forward(self, x):
83
  return self.classifier(self.features(x))
84
 
85
- # Load and predict
86
  model = TumorCNN(4)
87
  model.load_state_dict(torch.load("kaggle_tumor_2dcnn_best.pth", map_location="cpu"))
88
  model.eval()
89
 
 
90
  transform = transforms.Compose([
91
  transforms.Resize((224, 224)),
92
  transforms.ToTensor(),
@@ -95,14 +136,45 @@ transform = transforms.Compose([
95
 
96
  image = transform(Image.open("brain_mri.jpg").convert("RGB")).unsqueeze(0)
97
  pred = model(image).argmax(1).item()
 
98
  classes = ['glioma', 'meningioma', 'notumor', 'pituitary']
99
  print(f"Prediction: {classes[pred]}")
100
  ```
101
 
102
  ## Training
103
 
104
- Built with Mojo 🔥 on NVIDIA RTX 4090
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  ## License
107
 
108
- MIT
 
 
 
 
 
 
 
 
21
 
22
  # MRI Brain Tumor Classification Models
23
 
24
+ [![GitHub](https://img.shields.io/badge/GitHub-COMMRI-blue?logo=github)](https://github.com/Meidverse/COMMRI)
25
+ [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
26
+
27
+ This repository contains trained deep learning models for MRI brain scan classification, developed using **Mojo 🔥** and **PyTorch**.
28
+
29
+ **Full source code and training scripts:** [github.com/Meidverse/COMMRI](https://github.com/Meidverse/COMMRI)
30
 
31
  ## Models
32
 
33
  ### 1. Brain Tumor 2D CNN (`kaggle_tumor_2dcnn_best.pth`)
34
 
 
 
35
  | Metric | Value |
36
  |--------|-------|
37
  | **Accuracy** | 93.95% |
 
39
  | **Recall** | 0.94 |
40
  | **F1 Score** | 0.94 |
41
 
42
+ **Per-Class Performance:**
43
+ | Class | Accuracy |
44
+ |-------|----------|
45
+ | Glioma | 98.1% |
46
+ | Meningioma | 83.9% |
47
+ | No Tumor | 98.5% |
48
+ | Pituitary | 94.3% |
49
 
50
  ### 2. IXI 3D Brain CNN (`ixi_3dcnn_best.pth`)
51
 
52
+ 3D CNN for brain volume classification from NIfTI files.
 
53
 
54
  ## Quick Start
55
 
56
+ ### Option 1: Clone from GitHub (Recommended)
57
+
58
+ ```bash
59
+ git clone https://github.com/Meidverse/COMMRI.git
60
+ cd COMMRI
61
+
62
+ # Install dependencies
63
+ pip install -r requirements.txt
64
+
65
+ # Run inference
66
+ python -c "
67
+ import torch
68
+ from scripts.train_tumor import TumorCNN
69
+
70
+ model = TumorCNN(4)
71
+ model.load_state_dict(torch.load('kaggle_tumor_2dcnn_best.pth'))
72
+ model.eval()
73
+ print('Model loaded!')
74
+ "
75
+ ```
76
+
77
+ ### Option 2: Download from Hugging Face
78
+
79
+ ```python
80
+ from huggingface_hub import hf_hub_download
81
+
82
+ # Download model
83
+ model_path = hf_hub_download(
84
+ repo_id="Nikshey/mri-brain-classification",
85
+ filename="kaggle_tumor_2dcnn_best.pth"
86
+ )
87
+
88
+ # Load with PyTorch
89
+ import torch
90
+ model = torch.load(model_path)
91
+ ```
92
+
93
+ ## Inference Example
94
+
95
  ```python
96
  import torch
97
  import torch.nn as nn
98
  from torchvision import transforms
99
  from PIL import Image
100
 
 
101
  class TumorCNN(nn.Module):
102
  def __init__(self, num_classes=4):
103
  super().__init__()
 
122
  def forward(self, x):
123
  return self.classifier(self.features(x))
124
 
125
+ # Load model
126
  model = TumorCNN(4)
127
  model.load_state_dict(torch.load("kaggle_tumor_2dcnn_best.pth", map_location="cpu"))
128
  model.eval()
129
 
130
+ # Preprocess and predict
131
  transform = transforms.Compose([
132
  transforms.Resize((224, 224)),
133
  transforms.ToTensor(),
 
136
 
137
  image = transform(Image.open("brain_mri.jpg").convert("RGB")).unsqueeze(0)
138
  pred = model(image).argmax(1).item()
139
+
140
  classes = ['glioma', 'meningioma', 'notumor', 'pituitary']
141
  print(f"Prediction: {classes[pred]}")
142
  ```
143
 
144
  ## Training
145
 
146
+ Train your own models using the scripts in the [GitHub repo](https://github.com/Meidverse/COMMRI):
147
+
148
+ ```bash
149
+ # Train tumor classifier
150
+ mojo run scripts/train_tumor.mojo
151
+
152
+ # Train 3D brain model
153
+ mojo run scripts/train_advanced.mojo
154
+
155
+ # Evaluate
156
+ mojo run scripts/evaluate_tumor.mojo
157
+ ```
158
+
159
+ ## Citation
160
+
161
+ ```bibtex
162
+ @misc{commri2024,
163
+ author = {Meidverse},
164
+ title = {COM-MRI: Brain Tumor Classification with Mojo},
165
+ year = {2024},
166
+ publisher = {GitHub},
167
+ url = {https://github.com/Meidverse/COMMRI}
168
+ }
169
+ ```
170
 
171
  ## License
172
 
173
+ MIT License - See [LICENSE](https://github.com/Meidverse/COMMRI/blob/main/LICENSE)
174
+
175
+ ## Acknowledgments
176
+
177
+ - [Kaggle Brain Tumor MRI Dataset](https://www.kaggle.com/datasets/masoudnickparvar/brain-tumor-mri-dataset)
178
+ - [IXI Dataset](https://brain-development.org/ixi-dataset/)
179
+ - Built with [Mojo 🔥](https://www.modular.com/mojo) and PyTorch
180
+ - Trained on NVIDIA RTX 4090