TL;DR
High held-out accuracy did not settle the reliability question. Across four ResNet50V2–RViT variants, Ablation B was the strongest classifier, reaching 99.22% test accuracy, 0.9920 macro-F1, and 10 errors in 1,284 test images. Yet the stronger guided model, Hybrid B, produced the most tumour-centred Grad-CAM++ evidence in the three qualitative cases reported in the FYP.
The central result is therefore a trade-off, not a victory claim: pathology guidance changed where the system appeared to look more clearly than it improved what class it predicted.
| Study fact | Verified value |
|---|---|
| Raw images discovered | 7,023 |
| Exact duplicates removed | 297 |
| Unique images retained | 6,726 |
| Held-out test images | 1,284 |
| Best test accuracy | 99.22% |
| Best macro-F1 | 0.9920 |
| Fewest test errors | 10 |
This is a BSc Artificial Intelligence project, not a peer-reviewed clinical study or a certified medical device. It contains no external hospital validation, tumour-mask evaluation, or formal calibration analysis. The page makes no definitive state-of-the-art or clinical-generalisation claim.
Why Shortcut Learning Matters
A brain MRI classifier can be accurate for the wrong reason. Instead of relying on pathology, a model may exploit background, skull boundaries, annotations, acquisition patterns, or other dataset-specific regularities. This is the shortcut-learning problem: benchmark performance can remain high even when the learned evidence is brittle or clinically irrelevant (Geirhos et al., 2020; Lin et al., 2024).
The risk is particularly important in medical imaging because seemingly minor differences in preprocessing, patient populations, scanners, and dataset construction can create strong non-causal signals. Methodological reviews therefore emphasise leakage control, transparent split policies, held-out evaluation, and external validation (Mongan et al., 2020; Varoquaux & Cheplygina, 2022).
Can pathology-guided CNN–Transformer hybrids maintain strong four-class performance while shifting the evidence pathway toward tumour-related regions?
What was tested
The study compares two guided systems with two same-family ablations:
| Model | CNN pathway | Transformer pathway | Guidance intervention |
|---|---|---|---|
| Hybrid A | ResNet50V2 descriptor | 49 CNN feature tokens | PFD mask guides transformer-facing tokens |
| Ablation A | Matched A-family backbone | Same tokenisation | PFD–GSTE removed |
| Hybrid B | PFD-gated ResNet50V2 descriptor | 196 raw-image patch tokens before optional pooling | PFD gates CNN evidence and guides patch tokens |
| Ablation B | Matched B-family backbone | Same tokenisation | PFD–GSTE removed |
What the work contributes
- A leakage-aware benchmark built after byte-level SHA1 duplicate removal.
- Two pathology-guided ResNet50V2–RViT designs with explicit same-family ablations.
- Branch-specific explainability using Grad-CAM++ and Attention Rollout.
- MC Dropout analysis over 20 stochastic passes.
- Reproducible training, evaluation, visualisation, checkpoints, a browser demo, and reusable PFD–GSTE modules.
These are contributions within the project’s experimental setting. They do not establish that shortcut learning has been eliminated.
- Geirhos, R., Jacobsen, J.-H., Michaelis, C., Zemel, R., Brendel, W., Bethge, M., & Wichmann, F. A. (2020). Shortcut learning in deep neural networks. Nature Machine Intelligence, 2(11), 665–673. 10.1038/s42256-020-00257-z
- Lin, M., Weng, N., Mikolaj, K., Bashir, Z., Svendsen, M. B. S., Tolsgaard, M. G., Christensen, A. N., & Feragen, A. (2024). Shortcut Learning in Medical Image Segmentation. Medical Image Computing and Computer Assisted Intervention – MICCAI 2024, 623–633. 10.1007/978-3-031-72111-3_59
- Mongan, J., Moy, L., & Kahn, C. E. (2020). Checklist for Artificial Intelligence in Medical Imaging (CLAIM): a guide for authors and reviewers. Radiology: Artificial Intelligence, 2(2), e200029. 10.1148/ryai.2020200029
- Varoquaux, G., & Cheplygina, V. (2022). Machine learning for medical imaging: methodological failures and recommendations for the future. Npj Digital Medicine, 5, 48. 10.1038/s41746-022-00592-y
The PFD–GSTE Method
The model family combines a ResNet50V2 convolutional branch with a rotation-aware Vision Transformer branch. Residual CNNs provide strong local feature extraction (He et al., 2016), while Vision Transformers model long-range relationships through token interactions (Dosovitskiy et al., 2021). The transformer design follows rotation-aware ideas where applicable from Krishnan et al. (Krishnan et al., 2024).
The project adds two experimental modules:
- PFDestimates a soft spatial mask.
- GSTEtransfers that spatial preference into the token pathway.
The terminology is project-specific. The design is motivated by pathology-emphasis, hybrid CNN–Transformer, and token-selection literature (Rao et al., 2021; Xia et al., 2020); it should not be read as a claim that an established clinical concept has been reproduced.
Stage 1: soft spatial gating
Let denote the CNN feature map and let be a learned mask head. PFD computes
where is a differentiable spatial gate and denotes broadcast element-wise multiplication.
Plain-language interpretation: the network learns a continuous spatial preference map rather than receiving a manual tumour segmentation mask.
Stage 2: mean-normalised token guidance
The mask is resized to the token grid and normalised to preserve its mean scale:
Variant A applies this mechanism to a fixed CNN feature grid, giving 49 tokens. Variant B begins with raw-image patches, giving 196 tokens, and can use concentration-aware weighted pooling toward a minimum spatial side.
Stage 3: late fusion
The CNN and transformer summaries remain separate until the classifier:
This equation is the late-fusion formulation reported in the FYP.
Two Guided Variants
| Property | Hybrid A | Hybrid B |
|---|---|---|
| Initial transformer tokens | 49 CNN feature tokens | 196 raw-image patch tokens |
| CNN descriptor | Ungated | PFD-gated |
| Guidance reach | Transformer-facing pathway | CNN and transformer pathways |
| Token count | Fixed | Optional concentration-aware pooling |
| Trainable parameters | 26.68M | 26.58M |
Because A and B differ in token source and guidance reach, cross-family comparisons are not clean estimates of one isolated design change. The strongest causal comparisons are Hybrid A versus Ablation A and Hybrid B versus Ablation B.
- Dosovitskiy, A., Beyer, L., Kolesnikov, A., & others. (2021). An Image Is Worth 16x16 Words: Transformers for Image Recognition at Scale. International Conference on Learning Representations. https://openreview.net/forum?id=YicbFdNTTy
- He, K., Zhang, X., Ren, S., & Sun, J. (2016). Identity Mappings in Deep Residual Networks. Computer Vision – ECCV 2016, 630–645. 10.1007/978-3-319-46493-0_38
- Krishnan, P. T., Krishnadoss, P., Khandelwal, M., Gupta, D., Nihaal, A., & Kumar, T. S. (2024). Enhancing brain tumor detection in MRI with a rotation invariant Vision Transformer. Frontiers in Neuroinformatics, 18, 1414925. 10.3389/fninf.2024.1414925
- Rao, Y., Zhao, W., Liu, B., Lu, J., Zhou, J., & Hsieh, C.-J. (2021). DynamicViT: Efficient Vision Transformers with Dynamic Token Sparsification. Advances in Neural Information Processing Systems, 34. https://arxiv.org/abs/2106.02034
- Xia, T., Chartsias, A., & Tsaftaris, S. A. (2020). Pseudo-healthy synthesis with pathology disentanglement and adversarial learning. Medical Image Analysis, 64, 101719. 10.1016/j.media.2020.101719
Leakage-Safe Benchmark
The experiment uses the public four-class Brain Tumor MRI Dataset (Nickparvar, 2021). Before training, every discovered file was read as bytes and hashed with SHA1. Exact duplicate hashes were grouped across the original Kaggle directories.
When an exact duplicate crossed the original Training/Testing boundary, the Testing copy was retained and the Training copy removed. This policy protects the held-out boundary instead of allowing visually identical files to appear on both sides of evaluation.
Fixed split composition
The cleaned Kaggle Training partition was divided into stratified train and validation subsets using an 80/20 split. The cleaned Kaggle Testing partition remained untouched as the held-out test set.
| Split | Glioma | Meningioma | Pituitary | No tumour | Total |
|---|---|---|---|---|---|
| Train | 1,057 | 1,064 | 1,152 | 1,080 | 4,353 |
| Validation | 264 | 267 | 288 | 270 | 1,089 |
| Test | 299 | 304 | 300 | 381 | 1,284 |
Training and Evaluation Protocol
All four variants used the same core optimisation policy:
| Component | Setting |
|---|---|
| Optimiser | AdamW |
| CNN learning rate | |
| Transformer and fusion learning rate | |
| Weight decay | 0.01 |
| Objective | Cross-entropy with label smoothing 0.05 |
| Schedule | Cosine annealing, |
| Batch size | 32 |
| Maximum epochs | 100 |
| CNN warm-up | Frozen for first 5 epochs |
| Early stopping | Validation macro-F1, patience 10 |
| Gradient clipping | 1.0 |
| Random seed | 42 |
Checkpoint selection used validation macro-F1 only. Each chosen checkpoint was then evaluated once on the fixed 1,284-image test set.
B-family training used drop_last=True, whereas A-family training used drop_last=False. cuDNN benchmarking was enabled and strict deterministic execution was not enforced. Exact reruns may therefore vary, and within-family comparisons are the cleanest.
- Nickparvar, M. (2021). Brain Tumor MRI Dataset. Kaggle dataset. https://www.kaggle.com/datasets/masoudnickparvar/brain-tumor-mri-dataset
Results
All four models performed strongly on the fixed held-out set. Guidance, however, did not produce the best classification score.
| Model | Params | Accuracy | Macro-F1 | Loss | Specificity | MCC | Errors | Best epoch | |
|---|---|---|---|---|---|---|---|---|---|
| Hybrid A | 26.68M | 0.9875 | 0.9875 | 0.0803 | 0.9959 | 0.9833 | 0.9833 | 16 | 43 |
| Hybrid B | 26.58M | 0.9852 | 0.9849 | 0.0753 | 0.9952 | 0.9802 | 0.9803 | 19 | 14 |
| Ablation A | 26.68M | 0.9875 | 0.9873 | 0.0847 | 0.9959 | 0.9833 | 0.9834 | 16 | 30 |
| Ablation B | 26.58M | 0.9922 | 0.9920 | 0.0668 | 0.9975 | 0.9896 | 0.9896 | 10 | 42 |
Within-family ablation result
- A-family: Hybrid A and Ablation A tied on accuracy. Hybrid A was higher by 0.0002 in macro-F1 and lower by 0.0044 in test loss.
- B-family: Hybrid B was lower than Ablation B by 0.70 percentage points in accuracy and 0.71 percentage points in macro-F1, with nine additional errors.
Ablation B is the strongest classifier in this evaluation. Any account that presents Hybrid B or PFD–GSTE as the accuracy winner would contradict the reported experiment.
Benchmark context, not a state-of-the-art claim
The report found that this model family compares favourably with the reviewed four-class studies in its chosen benchmark setting. That numerical comparison is not equivalent to a definitive state-of-the-art result: prior papers differ in preprocessing, duplicate handling, split policy, augmentation, checkpoint selection, and reporting detail. External validation and repeated-seed analysis would be required before making stronger generalisation claims (Varoquaux & Cheplygina, 2022).
- Varoquaux, G., & Cheplygina, V. (2022). Machine learning for medical imaging: methodological failures and recommendations for the future. Npj Digital Medicine, 5, 48. 10.1038/s41746-022-00592-y
Evidence Focus
Classification accuracy and localisation quality answer different questions. The report therefore inspects both the CNN branch with Grad-CAM++ (Chattopadhyay et al., 2018) and the transformer branch with Attention Rollout (Abnar & Zuidema, 2020).
This analysis is deliberately qualitative. Saliency maps can be unstable or visually persuasive without being faithful, so they require cautious interpretation and stronger controls than a few attractive examples (Adebayo et al., 2018; Arun et al., 2021).
| Case | Hybrid A | Hybrid B | Ablation A | Ablation B |
|---|---|---|---|---|
| Correct meningioma | GC++ wrong; rollout partially correct | GC++ correct; rollout wrong | GC++ wrong; rollout partially correct | GC++ correct; rollout wrong |
| Challenging glioma | GC++ wrong; rollout wrong | GC++ correct; rollout partially wrong | GC++ correct; rollout partially wrong | GC++ partially wrong; rollout partially wrong |
| Pituitary → meningioma error | GC++ wrong; rollout wrong | GC++ correct; rollout partially correct | GC++ wrong; rollout partially correct | GC++ wrong; rollout partially correct |
By this report-level visual judgement, Hybrid B recorded 3/3 correct Grad-CAM++ localisations; Hybrid A recorded 0/3; Ablation A and Ablation B each recorded 1/3.
The three selected cases provide qualitative support that the stronger Hybrid B intervention can alter evidence focus. They do not demonstrate full-dataset localisation performance, causal faithfulness, or elimination of shortcut learning. There are no ground-truth tumour masks, Dice scores, IoU scores, or pointing-game results.
Uncertainty Analysis
MC Dropout retained dropout at inference while keeping BatchNorm layers in evaluation mode. Predictive statistics were computed over 20 stochastic forward passes (Gal & Ghahramani, 2016).
In the pituitary image misclassified as meningioma by all four models, confidence remained high:
The example exposes an important failure mode: stochastic uncertainty did not prevent a wrong-but-confident subtype prediction.
Expected calibration error, Brier score, reliability diagrams, and external calibration were not reported. MC Dropout variance alone does not demonstrate clinically calibrated confidence (Rajaraman et al., 2022).
- Abnar, S., & Zuidema, W. (2020). Quantifying Attention Flow in Transformers. Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, 4190–4197. 10.18653/v1/2020.acl-main.385
- Adebayo, J., Gilmer, J., Muelly, M., Goodfellow, I., Hardt, M., & Kim, B. (2018). Sanity Checks for Saliency Maps. Advances in Neural Information Processing Systems, 31. https://arxiv.org/abs/1810.03292
- Arun, N., Gaw, N., Singh, P., & others. (2021). Assessing the Trustworthiness of Saliency Maps for Localizing Abnormalities in Medical Imaging. Radiology: Artificial Intelligence, 3(6), e200267. 10.1148/ryai.2021200267
- Chattopadhyay, A., Sarkar, A., Howlader, P., & Balasubramanian, V. N. (2018). Grad-CAM++: Generalized Gradient-Based Visual Explanations for Deep Convolutional Networks. 2018 IEEE Winter Conference on Applications of Computer Vision, 839–847. 10.1109/WACV.2018.00097
- Gal, Y., & Ghahramani, Z. (2016). Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning. Proceedings of the 33rd International Conference on Machine Learning, 48, 1050–1059. https://proceedings.mlr.press/v48/gal16.html
- Rajaraman, S., Ganesan, P., & Antani, S. (2022). Deep learning model calibration for improving performance in class-imbalanced medical image classification tasks. PLOS ONE, 17(1), e0262838. 10.1371/journal.pone.0262838
Limitations
The study’s strongest value is that its boundaries are inspectable.
- No external validation. One aggregated Kaggle benchmark cannot establish robustness across hospitals, scanners, sequences, patient populations, or clinical workflows.
- No ground-truth tumour masks. Localisation is qualitative and case-based; there is no full-test-set overlap metric.
- No formal calibration analysis. Twenty MC Dropout passes provide stochastic summaries, not proof of calibrated uncertainty.
- Architecture and loader differences remain. A and B differ in tokenisation and guidance reach, while their loaders differ in
drop_last. - Single 2D slices. Tumour subtype discrimination may require multi-slice, multi-sequence, volumetric, or histopathological context.
- Single seeded training run per variant. Repeated seeds and confidence intervals are needed to separate stable effects from optimisation variance.
- No clinical claim. The system is an experimental research prototype and must not be used for diagnosis, patient management, or treatment.
The results support a benchmark-level conclusion: guidance may improve qualitative evidence focus without improving the best classification score. They do not establish clinical utility, universal shortcut robustness, or superiority over all published methods.
Evidence Readiness
The public implementation already supports a strong reproducibility record, but a polished website is not a substitute for missing experiments. The table below separates what is verified from the evidence required before each claim can be strengthened.
| Dimension | Verified now | Completion gate |
|---|---|---|
| Research integrity | Exact reported values, negative ablation outcomes, authorship, and limitations are preserved | Keep all claims traceable to report, code, or released artefacts |
| Open artefacts | Public code, checkpoints, model cards, PyPI package, report, and machine-readable article data | Publish this article repository with a versioned release and build check |
| Statistical robustness | One seeded training run per variant | Run at least five matched seeds per variant; report mean, standard deviation, 95% confidence intervals, and paired within-family deltas |
| Fair comparison | Guided variants have same-family ablations | Use the same loader policy, preprocessing manifest, checkpoint rule, and deterministic settings in the repeated-seed rerun |
| Calibration | Twenty-pass MC Dropout summaries for selected examples | Archive validation and test probabilities; report NLL, multiclass Brier score, ECE, reliability diagrams, and validation-fitted temperature scaling |
| External generalisation | A five-image external meningioma sample exists only as a qualitative demo | Evaluate a provenance-audited external cohort with compatible labels and no overlap with the development benchmark |
| XAI validation | Grad-CAM++ and Attention Rollout are reviewed on three selected cases | Evaluate a preregistered masked subset with Dice, IoU, pointing-game or localisation-error metrics plus saliency sanity checks |
| Clinical evidence | None claimed | Independent clinical governance, representative cohorts, and prospective validation would be required before any clinical claim |
The completion gates are an experimental roadmap, not unreported results. Confidence intervals, calibration scores, external-cohort performance, and mask-based localisation metrics will be added only after their underlying predictions, annotations, and evaluation artefacts are released.
Reproducibility
The companion implementation records the preprocessing audit, fixed split construction, four training configurations, evaluation scripts, model-specific XAI procedures, checkpoints, and reusable guidance modules.
| Resource | Access |
|---|---|
| Model and experiment code | GitHub repository |
| Browser demonstration | Hugging Face Space |
| Reusable modules | PFD–GSTE on PyPI |
| Machine-readable website data | app/src/content/assets/data/ in this article repository |
| Evidence-upgrade protocol | VALIDATION_PLAN.md in the article repository |
pip install pfd-gste
Conclusion
PFD–GSTE partially supports the project hypothesis. The stronger guidance pathway changed qualitative evidence focus most clearly in Hybrid B, but it did not improve the best held-out classification score. Ablation B remained the strongest classifier; Hybrid B remained the strongest qualitative Grad-CAM++ localiser among the three reported cases.
The next decisive experiment is external, multi-centre validation with tumour masks, quantitative localisation, calibration testing, repeated seeds, and multi-sequence or volumetric MRI. Until then, accuracy and evidence quality should be reported as complementary—not interchangeable—properties.
Supervision and project context
This work was completed as a BSc Artificial Intelligence project in the Department of Computer Science, University of Hertfordshire, under the supervision of Dr Kheng Lee Koay. The report is dated 26 March 2026.