TL;DR
torchmil is a new open-source, PyTorch-based library designed to standardize and streamline deep Multiple Instance Learning (MIL). By unifying data handling via TensorDict and providing modular implementations of 14 popular MIL models, it resolves the field's reproducibility crisis and lowers the entry barrier for researchers and practitioners alike.
What Problem Does This Paper Address?
Multiple Instance Learning (MIL) is a powerful weakly supervised learning framework where training data is organized into labeled "bags" containing multiple unlabeled "instances." It is highly valuable in fields like computational pathology—where an entire whole-slide image (WSI) might be labeled as cancerous, but individual tissue patches are not.
Despite its growing popularity in top-tier AI conferences, deep MIL research suffers from a severe lack of standardization. Existing codebases are fragmented, inconsistent, and heavily dependent on custom preprocessing strategies. This makes reproducing state-of-the-art methods incredibly difficult and creates a steep learning curve for newcomers trying to apply MIL to new domains.
Methods
The authors introduce torchmil, an extensible Python library built on top of PyTorch that unifies the deep MIL workflow into four core submodules:
torchmil.data: Standardizes bag representation usingTensorDictobjects. This allows each bag to flexibly encode instance features, bag-level labels, or graph-based adjacency matrices, while handling varying bag sizes through an efficient padding and masking mechanism during batching.torchmil.datasets: Provides theProcessedMILDatasetclass for optimized, bottleneck-free data loading.torchmil.nn: Contains reusable, modular building blocks (such as attention mechanisms and graph neural network layers) to construct custom MIL architectures.torchmil.models: Implements 14 distinct, popular MIL models (spanning transformer-based, graph-based, and hybrid paradigms) under a unifiedMILModelbase class interface.
Datasets
To ensure robust benchmarking, the authors curated and released three widely used MIL datasets on Hugging Face Datasets:
- RSNA Intracranial Hemorrhage Detection dataset
- PANDA dataset (prostate cancer grading)
- CAMELYON16 dataset (breast cancer metastasis detection)
Additionally, the library integrates algorithmic unit test datasets designed to verify model implementations rigorously.
Key Insights and Ideas
- The Hidden Cost of Custom Preprocessing: When evaluating original author codebases, the researchers discovered that custom, hardcoded preprocessing steps often crippled a model's ability to generalize. For instance, the original SETMIL implementation cropped whole-slide images to a central region—a strategy that inadvertently discarded diagnostically relevant areas on large CAMELYON16 slides.
- Unified Interfaces Broaden Scope: By abstracting data structures into
TensorDict,torchmilseamlessly supports both coordinate-free attention models (like ABMIL) and structurally complex models (like PatchGCN) without requiring separate, bespoke data pipelines.
Key Results
The authors validated torchmil by benchmarking its 14 implemented models against the original authors' codebases using the CAMELYON16 test set.
torchmil successfully matched the performance of the original implementations across almost all methods. Remarkably, it significantly outperformed the original codebases for SETMIL (Accuracy of 0.775 vs. 0.571) and GTP (Accuracy of 0.940 vs. 0.842) due to torchmil's cleaner, more robust handling of large-scale whole-slide images and generalized hyperparameter framework.
Limitations and Future Work
While torchmil provides a solid foundation, its ultimate utility depends on community adoption. The authors note that the library's collection of models and datasets must continue to grow to keep pace with the rapid evolution of deep MIL. Future work will focus on fostering community contributions to integrate emerging architectures and support an even wider array of application domains.
Summary updated