Views
No views yet
kaggle_tumor_2dcnn_best.pth)| Metric | Value |
|---|---|
| Accuracy | 93.95% |
| Precision | 0.94 |
| Recall | 0.94 |
| F1 Score | 0.94 |
| Class | Accuracy |
|---|---|
| Glioma | 98.1% |
| Meningioma | 83.9% |
| No Tumor | 98.5% |
| Pituitary | 94.3% |
ixi_3dcnn_best.pth)1git clone https://github.com/Meidverse/COMMRI.git
2cd COMMRI
3
4# Install dependencies
5pip install -r requirements.txt
6
7# Run inference
8python -c "
9import torch
10from scripts.train_tumor import TumorCNN
11
12model = TumorCNN(4)
13model.load_state_dict(torch.load('kaggle_tumor_2dcnn_best.pth'))
14model.eval()
15print('Model loaded!')
16"1from huggingface_hub import hf_hub_download
2
3# Download model
4model_path = hf_hub_download(
5 repo_id="Nikshey/mri-brain-classification",
6 filename="kaggle_tumor_2dcnn_best.pth"
7)
8
9# Load with PyTorch
10import torch
11model = torch.load(model_path)1import torch
2import torch.nn as nn
3from torchvision import transforms
4from PIL import Image
5
6class TumorCNN(nn.Module):
7 def __init__(self, num_classes=4):
8 super().__init__()
9 self.features = nn.Sequential(
10 nn.Conv2d(3, 64, 3, padding=1), nn.BatchNorm2d(64), nn.ReLU(),
11 nn.Conv2d(64, 64, 3, padding=1), nn.BatchNorm2d(64), nn.ReLU(),
12 nn.MaxPool2d(2), nn.Dropout2d(0.25),
13 nn.Conv2d(64, 128, 3, padding=1), nn.BatchNorm2d(128), nn.ReLU(),
14 nn.Conv2d(128, 128, 3, padding=1), nn.BatchNorm2d(128), nn.ReLU(),
15 nn.MaxPool2d(2), nn.Dropout2d(0.25),
16 nn.Conv2d(128, 256, 3, padding=1), nn.BatchNorm2d(256), nn.ReLU(),
17 nn.Conv2d(256, 256, 3, padding=1), nn.BatchNorm2d(256), nn.ReLU(),
18 nn.MaxPool2d(2), nn.Dropout2d(0.25),
19 nn.Conv2d(256, 512, 3, padding=1), nn.BatchNorm2d(512), nn.ReLU(),
20 nn.Conv2d(512, 512, 3, padding=1), nn.BatchNorm2d(512), nn.ReLU(),
21 nn.AdaptiveAvgPool2d(1),
22 )
23 self.classifier = nn.Sequential(
24 nn.Flatten(), nn.Linear(512, 256), nn.ReLU(), nn.Dropout(0.5),
25 nn.Linear(256, 128), nn.ReLU(), nn.Dropout(0.3), nn.Linear(128, num_classes),
26 )
27 def forward(self, x):
28 return self.classifier(self.features(x))
29
30# Load model
31model = TumorCNN(4)
32model.load_state_dict(torch.load("kaggle_tumor_2dcnn_best.pth", map_location="cpu"))
33model.eval()
34
35# Preprocess and predict
36transform = transforms.Compose([
37 transforms.Resize((224, 224)),
38 transforms.ToTensor(),
39 transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
40])
41
42image = transform(Image.open("brain_mri.jpg").convert("RGB")).unsqueeze(0)
43pred = model(image).argmax(1).item()
44
45classes = ['glioma', 'meningioma', 'notumor', 'pituitary']
46print(f"Prediction: {classes[pred]}")1# Train tumor classifier
2mojo run scripts/train_tumor.mojo
3
4# Train 3D brain model
5mojo run scripts/train_advanced.mojo
6
7# Evaluate
8mojo run scripts/evaluate_tumor.mojo1@misc{commri2024,
2 author = {Meidverse},
3 title = {COM-MRI: Brain Tumor Classification with Mojo},
4 year = {2024},
5 publisher = {GitHub},
6 url = {https://github.com/Meidverse/COMMRI}
7}