brain-tumor-cnn / README.md
larrikin-coder's picture
updated version
ebf0a45 verified
metadata
license: mit
datasets:
  - brain-mri-dataset
metrics:
  - accuracy
  - auc
model-index:
  - name: CNN Brain Tumor Classifier
    results:
      - task:
          type: image-classification
        dataset:
          name: Brain MRI Dataset
          type: brain-mri-dataset
        metrics:
          - name: Accuracy
            type: accuracy
            value: 0.9
          - name: AUC
            type: auc
            value: 0.9

🧠 CNN Brain Tumor Classifier

Model Description

This repository contains a Convolutional Neural Network (CNN) built with TensorFlow/Keras for classifying brain MRI scans.
The model can distinguish between three types of brain tumors and healthy scans.

⚠️ Disclaimer: This model is provided for educational and research purposes only.
It is not a medical diagnostic tool and should not be used in clinical practice.


Classes

The model predicts one of the following four categories:

  • Glioma
  • Meningioma
  • Pituitary tumor
  • No tumor (healthy)

Training Details

  • Framework: TensorFlow / Keras
  • Architecture: Custom CNN
  • Input size: 224 × 224 RGB MRI images
  • Loss function: categorical_crossentropy
  • Optimizer: Adam
  • Epochs: 10
  • Metrics: Accuracy, AUC

Dataset

  • Source: Public brain MRI dataset (glioma, meningioma, pituitary, no tumor)
  • Preprocessing:
    • Images resized to 224 × 224
    • Normalized to [0, 1] range
    • Augmentation (rotation, flipping, zoom) applied during training

Evaluation Results

Metric Value
Training Accuracy ~96%
Validation Accuracy ~85–90%
AUC (training) ~0.90

(values may vary depending on train/validation split)


Usage

Installation

pip install tensorflow huggingface_hub
from tensorflow.keras.models import load_model
from huggingface_hub import hf_hub_download
import numpy as np
from tensorflow.keras.preprocessing import image

# Download model file from Hugging Face Hub
model_path = hf_hub_download(
    repo_id="larrikin-coder/brain-tumor-cnn",  # replace with your repo
    filename="cnn_model.h5"
)

# Load model
model = load_model(model_path)

# Preprocess an image
img = image.load_img("test_mri.jpg", target_size=(224, 224))
img_array = image.img_to_array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)

# Predict
pred = model.predict(img_array)
class_names = ["glioma", "meningioma", "pituitary", "no_tumor"]
print("Prediction:", class_names[np.argmax(pred)])

@misc{larrikin-coder2025, title={CNN Brain Tumor Classifier}, author={Larrikin Coder}, year={2025}, howpublished={\url{https://huggingface.co/larrikin-coder/brain-tumor-cnn}} }