Skip to main content

Deep Multiple Instance Learning library for Pytorch

Project description

torchmil

License Contributors Release

torchmil is a PyTorch-based library for deep Multiple Instance Learning (MIL). It provides a simple, flexible, and extensible framework for working with MIL models and data.

It includes:

Installation

pip install torchmil

Quick start

You can load a MIL dataset and train a MIL model in just a few lines of code:

from torchmil.datasets import Camelyon16MIL
from torchmil.models import ABMIL
from torchmil.utils import Trainer
from torchmil.data import collate_fn
from torch.utils.data import DataLoader

# Load the Camelyon16 dataset
dataset = Camelyon16MIL(root='data', features='UNI')
dataloader = DataLoader(dataset, batch_size=4, shuffle=True, collate_fn=collate_fn)

# Instantiate the ABMIL model and optimizer
model = ABMIL(in_shape=(2048,), criterion=torch.nn.BCEWithLogitsLoss()) # each model has its own criterion
optimizer = torch.optim.Adam(model.parameters(), lr=1e-4)

# Instantiate the Trainer
trainer = Trainer(model, optimizer, device='cuda')

# Train the model
trainer.train(dataloader, epochs=10)

# Save the model
torch.save(model.state_dict(), 'model.pth')

Next steps

You can take a look at the examples to see how to use torchmil in practice. To see the full list of available models, datasets, and modules, check the API reference.

Citation

If you find this library useful, please consider citing it:

@misc{torchmil,
  author = {Castro-Mac{\'\i}as, Francisco M and S{\'a}ez-Maldonado, Francisco Javier and Morales Alvarez, Pablo and Molina, Rafael},
  title = {torchmil: A PyTorch-based library for deep Multiple Instance Learning},
  year = {2025},
  howpublished = {\url{https://franblueee.github.io/torchmil/}}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchmil-0.0.1b0.tar.gz (123.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchmil-0.0.1b0-py3-none-any.whl (195.0 kB view details)

Uploaded Python 3

File details

Details for the file torchmil-0.0.1b0.tar.gz.

File metadata

  • Download URL: torchmil-0.0.1b0.tar.gz
  • Upload date:
  • Size: 123.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for torchmil-0.0.1b0.tar.gz
Algorithm Hash digest
SHA256 13cc40fb662cff29222fb74a84aaa6bd31d4c5ec93bd04e0b7e4fb185b0080e4
MD5 31fd48217ed381534b8150a9d4c6a0ba
BLAKE2b-256 b167ae4290df502f227262b30dc824ae5a14528a50c93d545a1277e869131072

See more details on using hashes here.

File details

Details for the file torchmil-0.0.1b0-py3-none-any.whl.

File metadata

  • Download URL: torchmil-0.0.1b0-py3-none-any.whl
  • Upload date:
  • Size: 195.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for torchmil-0.0.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d81f117dc64d246ff2d09d055117738af28e3ed3ca34fd53109d70b4f3ee5e0
MD5 d1af6a331b7f658173d39c6fe1119b83
BLAKE2b-256 1ff791c2654770bff3cf64abb797f241629e916b2155adaab34f3f2c45446672

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page