CoolFace
Modelpublic

Koushim/vit-brain-mri-classifier

sourceHugging Facemitupdated 1y agoView on Hugging Face
2likes9downloads
Model Card

๐Ÿง  Brain Tumor Classification Using Vision Transformer (ViT)

This repository contains a fine-tuned Vision Transformer (ViT) model trained on a large collection of MRI scans for brain tumor classification. The model classifies MRI images into one of three categories:

  • โ€”Glioma
  • โ€”Meningioma
  • โ€”Tumor (General)

The dataset used includes over 75,000 color-enhanced MRI images, making this model highly capable for research and educational applications in brain tumor detection.


๐Ÿ“Š Dataset Information

Note: This dataset is publicly available for non-commercial research use. The model does not include the dataset itself.

๐Ÿง  Model Architecture

  • โ€”Model Type: Vision Transformer (ViT-B/16)
  • โ€”Framework: PyTorch + timm
  • โ€”Input Shape: 224x224 RGB
  • โ€”Number of Classes: 3
  • โ€”Loss Function: CrossEntropyLoss
  • โ€”Optimizer: AdamW

๐Ÿ Training Pipeline Summary

  1. 1.Image Preprocessing:
  2. 2.Resize to 224x224
  3. 3.Normalization using ImageNet stats
  4. 4.Augmentations: Horizontal/Vertical Flip, ShiftScaleRotate, BrightnessContrast, etc.
  1. 1.DataLoader:
  2. 2.Stratified Split (Train/Val/Test)
  3. 3.PyTorch Dataset and DataLoader classes
  1. 1.Model:
  2. 2.Loaded ViT using timm.create_model('vit_base_patch16_224', pretrained=True)
  3. 3.Modified the classifier head to match 3 output classes
  1. 1.Training:
  2. 2.Trained using mixed precision (torch.cuda.amp)
  3. 3.Tracked using tqdm
  1. 1.Saving:
  2. 2.Model saved as pytorch_model.bin
  3. 3.Configuration saved as config.json

๐Ÿ” Intended Use

This model is designed for:

  • โ€”Educational purposes (deep learning and medical imaging)
  • โ€”Research in brain tumor classification using transformers
  • โ€”Demonstrating the power of ViT on colorized medical datasets

โš ๏ธ Not intended for clinical use or deployment without regulatory approval and further validation.


๐Ÿš€ Inference Example (Python)

python
from timm import create_model
import torch
from torchvision import transforms
from PIL import Image

# Load model
model = create_model('vit_base_patch16_224', pretrained=False, num_classes=3)
model.load_state_dict(torch.load("pytorch_model.bin"))
model.eval()

# Transform
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.5]*3, std=[0.5]*3),
])

# Inference
image = Image.open("example_mri.jpg").convert("RGB")
tensor = transform(image).unsqueeze(0)
output = model(tensor)
pred = torch.argmax(output, dim=1)
print("Predicted class:", pred.item())