Networks
eva.vision.models.networks.ABMIL
Bases: Module
ABMIL network for multiple instance learning classification tasks.
Takes an array of patch level embeddings per slide as input. This implementation supports
batched inputs of shape (batch_size
, n_instances
, input_size
). For slides with less
than n_instances
patches, you can apply padding and provide a mask tensor to the forward
pass.
The original implementation from [1] was used as a reference: https://github.com/AMLab-Amsterdam/AttentionDeepMIL/blob/master/model.py
Notes
- use_bias: The paper didn't use bias in their formalism, but their published example code inadvertently does.
- To prevent dot product similarities near-equal due to concentration of measure as a consequence of large input embedding dimensionality (>128), we added the option to project the input embeddings to a lower dimensionality
[1] Maximilian Ilse, Jakub M. Tomczak, Max Welling, "Attention-based Deep Multiple Instance Learning", 2018 https://arxiv.org/abs/1802.04712
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_size |
int
|
input embedding dimension |
required |
output_size |
int
|
number of classes |
required |
projected_input_size |
int | None
|
size of the projected input. if |
required |
hidden_size_attention |
int
|
hidden dimension in attention network |
128
|
hidden_sizes_mlp |
tuple
|
dimensions for hidden layers in last mlp |
(128, 64)
|
use_bias |
bool
|
whether to use bias in the attention network |
True
|
dropout_input_embeddings |
float
|
dropout rate for the input embeddings |
0.0
|
dropout_attention |
float
|
dropout rate for the attention network and classifier |
0.0
|
dropout_mlp |
float
|
dropout rate for the final MLP network |
0.0
|
pad_value |
int | float | None
|
Value indicating padding in the input tensor. If specified, entries with
this value in the will be masked. If set to |
float('-inf')
|
Source code in src/eva/vision/models/networks/abmil.py
forward
Forward pass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_tensor |
Tensor
|
Tensor with expected shape of (batch_size, n_instances, input_size). |
required |