CoolFace
Modelpublic

Purino/mobilenetv2-brain-mri-tumor

sourceHugging Faceupdated 16d agoView on Hugging Face
0likes17downloads
Model Card

MobileNetV2 brain MRI classifier

Full-image four-class classification: glioma (0), meningioma (1), no tumor (2), pituitary (3). ImageNet V2 initialization, FP16 DDP fine-tuning, and an all-data refit.

Dataset and cleaning

Ahmed Sorour's MRI for Brain Tumor with Bounding Boxes. Consult the source card for upstream datasets, attribution and usage terms. No dataset or model-weight license is inferred here. Source images are not redistributed. Class folders supervise classification and YOLO annotations cross-check labels. Boxes are not inputs and this model does not localize tumors. Readability, tiny/constant images, exact duplicates and label conflicts are checked; see cleaning_report.json. Missing or defective geometry alone is retained for classification when the class is clear.

Training and evaluation

See training_config.json and training.py. Use class-weighted cross entropy, AdamW, two warmup epochs and cosine decay. All layers train; BatchNorm running statistics are fixed. RGB images are letterboxed to the config size and ImageNet-normalized. Mild training-only affine and brightness/contrast augmentation; no flips.

Internal validation macro-F1 selects the epoch count. The split groups exact duplicate copies and identical filenames, but is not patient-independent. Patient overlap and near-duplicates may inflate scores. selectionmetrics.json evaluates ONLY selectionmodel.safetensors, with argmax predictions and class order as above. The final model.safetensors is a fresh fit on all cleaned data and has NO independent test scores. It must not inherit the selection checkpoint's reported performance.

Usage

Download model.safetensors, config.json and inference.py from this repository. Install torch, torchvision, Pillow and safetensors; environment.json records versions.

python
from inference import load_model, predict
model, config = load_model("path/to/downloaded/folder")
print(predict("brain_mri.jpg", model, config))

Research only; not a clinical diagnostic device. Softmax scores are not calibrated clinical probabilities. External patient-independent evaluation is required.

Run results

All-data refit: {"epochs": 17, "images": 3652}

Internal selection checkpoint only:

json
{
  "macro_roc_auc": 0.9978485809380591,
  "accuracy": 0.9712722298221614,
  "balanced_accuracy": 0.9699385865096634,
  "macro_f1": 0.9703439487892163,
  "per_class_recall": {
    "glioma": 0.961352657004831,
    "meningioma": 0.9751243781094527,
    "no_tumor": 0.957983193277311,
    "pituitary": 0.9852941176470589
  },
  "per_class_precision": {
    "glioma": 0.9851485148514851,
    "meningioma": 0.937799043062201,
    "no_tumor": 0.9661016949152542,
    "pituitary": 0.995049504950495
  },
  "confusion_matrix": [
    [
      199,
      8,
      0,
      0
    ],
    [
      1,
      196,
      4,
      0
    ],
    [
      1,
      3,
      114,
      1
    ],
    [
      1,
      2,
      0,
      201
    ]
  ],
  "best_epoch": 17,
  "evaluation_scope": "Internal selection validation only; not an independent test and not an evaluation of final refit weights."
}