OpenMIBOOD - MIDOG (Microscopy / Mitosis)

Reproduces the MIDOG benchmark from OpenMIBOOD: Open Medical Imaging Benchmarks for Out-Of-Distribution Detection (CVPR 2025).

Note

The MIDOG data must be prepared first by following the OpenMIBOOD setup guide. The root argument should point at the directory whose subfolders match the relative paths in the bundled image list files (e.g. 1a/017/...).

16 import pandas as pd  # additional dependency, used here for convenience
17 import torch
18 from torchvision import transforms
19 from torchvision.models import resnet50
20
21 from pytorch_ood.benchmark import MIDOG_OpenMIBOOD
22 from pytorch_ood.detector import MaxSoftmax
23 from pytorch_ood.utils import fix_random_seed
24
25 fix_random_seed(123)
26
27 device = "cuda:0" if torch.cuda.is_available() else "cpu"
28 loader_kwargs = {"batch_size": 64, "num_workers": 8}

Replace this with the OpenMIBOOD pretrained MIDOG classifier (3 classes). See https://zenodo.org/records/14982267

33 model = resnet50(num_classes=3).eval().to(device)
34
35 trans = transforms.Compose(
36     [
37         transforms.Resize((224, 224)),
38         transforms.ToTensor(),
39         transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
40     ]
41 )
44 detectors = {
45     "MSP": MaxSoftmax(model),
46 }
49 benchmark = MIDOG_OpenMIBOOD(root="data/openmibood/midog", transform=trans)
50
51 results = []
52 with torch.no_grad():
53     for detector_name, detector in detectors.items():
54         print(f"> Evaluating {detector_name}")
55         res = benchmark.evaluate(detector, loader_kwargs=loader_kwargs, device=device)
56         for r in res:
57             r.update({"Detector": detector_name})
58         results += res
59
60 df = pd.DataFrame(results)
61 print((df.set_index(["Dataset", "Detector"]) * 100).to_csv(float_format="%.2f"))

This produces a table with rows for the following splits, in this order:

  • cs-ID: midog_csid_1b, midog_csid_1c (other scanners, same task)

  • near-OOD: midog_2midog_7 (other scanner/staining domains)

  • far-OOD: midog_ccagt (cervical cells), midog_fnac2019 (fine-needle aspirate)

Gallery generated by Sphinx-Gallery