resnet50-brain-mri-tumor
Torchvision ResNet50 initialized from ResNet50_Weights.IMAGENET1K_V2,
fine-tuned for 4-class image classification. Bounding boxes are not used.
This is a research classifier; it is not clinically validated or intended to make clinical decisions.
Dataset and evaluation protocol
- Dataset: MRI for Brain Tumor with Bounding Boxes.
- Dataset revision:
Kaggle input attached to this run. - Classes in output order:
['glioma', 'meningioma', 'no_tumor', 'pituitary']. - Source folder used for the final held-out test:
val. - Split policy: source holdout preserved after cleaning; new stratified development validation.
- Additional training images excluded for validation group overlap: 0.
- Grouping: image-level; no patient IDs.
- Exact duplicate decoded images removed: 1343; unreadable/small images removed: 0.
- Development images excluded for overlap with holdout groups: 0.
- Best checkpoint selected by validation macro-F1 (tie-break: validation cross entropy), epoch 13.
- Test was evaluated after training and was not used for checkpoint selection, class weights, thresholds or scheduling.
- Exact-pixel deduplication cannot detect all re-encoded/near-duplicate images. Filename grouping is not verified patient metadata; results do not establish performance on unseen patients.
- Counts and metrics refer to the cleaned holdout, which can differ from the original folder counts.
- Brain MRI slices may be correlated within a patient.
- Without verified patient IDs, these results do not establish performance on unseen patients.
| Split | glioma | meningioma | no_tumor | pituitary |
|---|---|---|---|---|
| train | 896 | 816 | 426 | 757 |
| val | 158 | 145 | 75 | 134 |
| test | 136 | 134 | 93 | 136 |
Held-out evaluation
Metrics are fractions, not percentages. Number of evaluated images: 499. Decision rule: argmax; no threshold tuned on test.
| Metric | Value |
|---|---|
| accuracy | 0.969940 |
| balanced_accuracy | 0.967272 |
| macro_precision | 0.972871 |
| macro_recall | 0.967272 |
| macro_f1 | 0.969661 |
| weighted_f1 | 0.969943 |
| log_loss | 0.093758 |
| roc_auc_macro_ovr | 0.999350 |
| average_precision_macro_ovr | 0.998092 |
Accuracy 95% Wilson interval (image-level independence assumption): [0.950999, 0.981700]. The interval may be overconfident if test images are correlated by patient. Average precision is reported as AP, not trapezoidal PR-AUC. ROC-AUC is macro one-vs-rest.
| Class | Support | Precision | Sensitivity | F1 | Specificity | ROC-AUC (OvR) |
|---|---|---|---|---|---|---|
| glioma | 136 | 0.977612 | 0.963235 | 0.970370 | 0.991736 | 0.999453 |
| meningioma | 134 | 0.942857 | 0.985075 | 0.963504 | 0.978082 | 0.999468 |
| no_tumor | 93 | 1.000000 | 0.935484 | 0.966667 | 1.000000 | 0.999047 |
| pituitary | 136 | 0.971014 | 0.985294 | 0.978102 | 0.988981 | 0.999433 |

Training and preprocessing
- Hardware: ['Tesla T4', 'Tesla T4']; 2 DDP workers.
- FP16 automatic mixed precision; channels-last tensors; global batch 64.
- RGB conversion; 256 x 256; letterbox resize.
- No center crop. Normalize with ImageNet mean [0.485, 0.456, 0.406], std [0.229, 0.224, 0.225].
- Rotation +/-10 degrees, translation +/-3%, scale 0.95-1.05; horizontal flip: True.
- Train-only brightness/contrast jitter +/-10%; validation/test have no augmentation.
- Head warmup: 3 epochs, AdamW LR 0.001.
- Full fine-tuning: at most 25 epochs, backbone LR 3e-05, classifier LR 0.0003; warmup + cosine schedule.
- Weight decay 0.0001; label smoothing 0.05; dropout 0.0.
- Class weights:
(N / (K * class_count)) ** 0.5, normalized to mean 1, using training data only. - BatchNorm running statistics frozen; affine parameters fine-tuned in stage two.
- Early stopping patience 7; seed 42; completed 20 epochs.
- Training time measured in this run: 5.02 minutes.
- GPU nondeterminism may cause small differences between runs; speed-first cuDNN benchmark: True.
Usage
This is a torchvision checkpoint, not a Transformers AutoModel checkpoint.
Use the supplied preprocessing on the source MRI image to reproduce training resize and normalization.
Use the supplied preprocessing for reproducible predictions. model(x) returns logits before softmax,
which can also be used to compute CAM gradients; do not wrap CAM computation in inference_mode.
The default inference function below does use inference mode for ordinary classification.
from huggingface_hub import snapshot_download
import importlib.util
folder = snapshot_download("YOUR_USERNAME/resnet50-brain-mri-tumor")
spec = importlib.util.spec_from_file_location("mri_inference", folder + "/inference.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
model, config = module.load_model(folder)
print(module.predict("example.jpg", model, config))
The repository includes model.safetensors, preprocessing configuration, evaluation results,
training/data-processing source, and environment versions. Raw images, Kaggle secrets, patient CSV,
and per-image prediction records are not uploaded. Per-image predictions remain in Kaggle output.
Dataset licenses and upstream pretrained-weight terms apply; no additional model license is
asserted unless explicitly configured by the author.