Update README.md
Browse files
README.md
CHANGED
|
@@ -7,4 +7,77 @@ sdk: static
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
**Github repository:** https://github.com/Franblueee/torchmil
|
| 11 |
+
|
| 12 |
+
[**torchmil**](https://github.com/Franblueee/torchmil) is a [PyTorch](https://pytorch.org/)-based library for deep Multiple Instance Learning (MIL).
|
| 13 |
+
It provides a simple, flexible, and extensible framework for working with MIL models and data.
|
| 14 |
+
|
| 15 |
+
It includes:
|
| 16 |
+
|
| 17 |
+
- A collection of popular [MIL models](https://franblueee.github.io/torchmil/api/models/).
|
| 18 |
+
- Different [PyTorch modules](https://franblueee.github.io/torchmil/api/nn/) frequently used in MIL models.
|
| 19 |
+
- Handy tools to deal with [MIL data](https://franblueee.github.io/torchmil/api/data/).
|
| 20 |
+
- A collection of popular [MIL datasets](https://franblueee.github.io/torchmil/api/datasets/).
|
| 21 |
+
|
| 22 |
+
## Installation
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
pip install torchmil
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
## Quick start
|
| 29 |
+
|
| 30 |
+
You can load a MIL dataset and train a MIL model in just a few lines of code:
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
from torchmil.datasets import Camelyon16MIL
|
| 34 |
+
from torchmil.models import ABMIL
|
| 35 |
+
from torchmil.utils import Trainer
|
| 36 |
+
from torchmil.data import collate_fn
|
| 37 |
+
from torch.utils.data import DataLoader
|
| 38 |
+
|
| 39 |
+
# Load the Camelyon16 dataset
|
| 40 |
+
dataset = Camelyon16MIL(root='data', features='UNI')
|
| 41 |
+
dataloader = DataLoader(dataset, batch_size=4, shuffle=True, collate_fn=collate_fn)
|
| 42 |
+
|
| 43 |
+
# Instantiate the ABMIL model and optimizer
|
| 44 |
+
model = ABMIL(in_shape=(2048,), criterion=torch.nn.BCEWithLogitsLoss()) # each model has its own criterion
|
| 45 |
+
optimizer = torch.optim.Adam(model.parameters(), lr=1e-4)
|
| 46 |
+
|
| 47 |
+
# Instantiate the Trainer
|
| 48 |
+
trainer = Trainer(model, optimizer, device='cuda')
|
| 49 |
+
|
| 50 |
+
# Train the model
|
| 51 |
+
trainer.train(dataloader, epochs=10)
|
| 52 |
+
|
| 53 |
+
# Save the model
|
| 54 |
+
torch.save(model.state_dict(), 'model.pth')
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## Next steps
|
| 58 |
+
|
| 59 |
+
You can take a look at the [examples](https://franblueee.github.io/torchmil/examples/) to see how to use **torchmil** in practice.
|
| 60 |
+
To see the full list of available models, datasets, and modules, check the [API reference](https://franblueee.github.io/torchmil/api/).
|
| 61 |
+
|
| 62 |
+
## Contributing to torchmil
|
| 63 |
+
|
| 64 |
+
We welcome contributions to **torchmil**! There several ways you can contribute:
|
| 65 |
+
|
| 66 |
+
- Reporting bugs or issues you encounter while using the library, asking questions, or requesting new features: use the [Github issues](https://github.com/Franblueee/torchmil/issues).
|
| 67 |
+
- Improving the documentation: if you find any part of the documentation unclear or incomplete, feel free to submit a pull request with improvements.
|
| 68 |
+
- If you have a new model, dataset, or utility that you think would be useful for the community, please consider submitting a pull request to add it to the library.
|
| 69 |
+
|
| 70 |
+
Take a look at [CONTRIBUTING.md](https://github.com/Franblueee/torchmil/blob/main/CONTRIBUTING.md) for more details on how to contribute.
|
| 71 |
+
|
| 72 |
+
## Citation
|
| 73 |
+
|
| 74 |
+
If you find this library useful, please consider citing it:
|
| 75 |
+
|
| 76 |
+
```bibtex
|
| 77 |
+
@misc{torchmil,
|
| 78 |
+
author = {Castro-Mac{\'\i}as, Francisco M and S{\'a}ez-Maldonado, Francisco Javier and Morales Alvarez, Pablo and Molina, Rafael},
|
| 79 |
+
title = {torchmil: A PyTorch-based library for deep Multiple Instance Learning},
|
| 80 |
+
year = {2025},
|
| 81 |
+
howpublished = {\url{https://franblueee.github.io/torchmil/}}
|
| 82 |
+
}
|
| 83 |
+
```
|