Drug-efficacy studies in oncology depend on accurate tissue segmentation — you can't measure the tumor microenvironment, count infiltrating lymphocytes, or quantify stromal response if a pathologist (or a model) can't reliably tell tumor from stroma from background. This project does that for colorectal cancer histology with a small EfficientNet-B0.
EfficientNet-B0 (pretrained on ImageNet) fine-tuned to classify H&E-stained tissue patches into 9 classes, achieving 99.6% validation accuracy on the NCT-CRC-HE-100K benchmark — above the published state-of-the-art range of 94–97%.
Built with PyTorch and timm.
Trained on 80/20 split. Early stopped at epoch 15/30.
Validation accuracy: 99.6%
| Class | F1 Score |
|---|---|
| ADI | 1.00 |
| BACK | 1.00 |
| DEB | 1.00 |
| LYM | 1.00 |
| MUC | 0.99 |
| MUS | 1.00 |
| NORM | 1.00 |
| STR | 0.99 |
| TUM | 0.99 |
NCT-CRC-HE-100K — 100,000 histological image patches (224×224) of human colorectal cancer tissue across 9 classes:
- ADI — Adipose
- BACK — Background
- DEB — Debris
- LYM — Lymphocytes
- MUC — Mucus
- MUS — Smooth muscle
- NORM — Normal colon mucosa
- STR — Cancer-associated stroma
- TUM — Colorectal adenocarcinoma epithelium
- EfficientNet-B0 backbone via timm, pretrained on ImageNet
- Dropout (0.3) + linear classification head
- AdamW optimizer with cosine annealing LR schedule
- Mixed precision training (fp16) on CUDA
- Data augmentation via Albumentations: flips, rotations, color jitter, blur
- Early stopping with patience of 5 epochs
pip install -r requirements.txtSet dataset path:
export MEDVISION_DATA_DIR="/path/to/NCT-CRC-HE-100K"The directory should contain class subfolders directly (ADI/, BACK/, ..., TUM/).
Train:
python main.pyEvaluate — prints classification report and saves confusion matrix:
python evaluate.pyTensorBoard:
tensorboard --logdir runsAll hyperparameters are in config.py.
To reproduce the reported results:
- Download NCT-CRC-HE-100K from Zenodo
- Set
MEDVISION_DATA_DIRto the dataset root - Run
python main.py— training will early stop around epoch 15 - Run
python evaluate.pyto generate the classification report and confusion matrix
Training was run on an NVIDIA GeForce GTX 1660 Ti (CUDA 12.1). CPU training is supported but significantly slower.
medvision/
├── config.py # hyperparameters and paths
├── main.py # training entry point
├── evaluate.py # evaluation and confusion matrix
├── data/dataset.py # augmentations and dataloaders
├── models/classifier.py # efficientnet + classification head
├── training/trainer.py # train/val loop, checkpointing
├── utils/metrics.py # sklearn metrics wrappers
├── utils/visualization.py # confusion matrix and curve plots
└── results/ # saved figures
MIT
