spine.model.image
Whole-image classification/regression tasks.
Classes
|
|
|
Image classication loss. |
|
Whole-image classification model. |
- class spine.model.image.ImageClassifier(*args: Any, **kwargs: Any)[source]
Whole-image classification model.
This model uses various encoder declinations to classifier an entire image as belonging to a certain class.
model: name: image_class modules: classifier: # Image classifier configuration classifier_loss: # Image classifier loss configuration
Methods
__call__(*args, **kwargs)Call self as a function.
forward(data)Run a batch of data through the forward function.
process_model_config(num_classes, **encoder)Initialize the underlying encoder and the final layer.
- MODULES = ['classifier', 'classifier_loss']
- process_model_config(num_classes, **encoder)[source]
Initialize the underlying encoder and the final layer.
- Parameters:
num_classes (int) – Number of classes that each image can be sorted as
**encoder (dict) – Encoder configuration
- forward(data)[source]
Run a batch of data through the forward function.
- Parameters:
data (TensorBatch) – (N, 1 + D + N_f) tensor of voxel/value pairs - N is the the total number of voxels in the image - 1 is the batch ID - D is the number of dimensions in the input image - N_f is the number of features per voxel
- class spine.model.image.ClusterImageClassifier(*args: Any, **kwargs: Any)[source]
Methods
__call__(*args, **kwargs)Call self as a function.
- class spine.model.image.ImageClassLoss(*args: Any, **kwargs: Any)[source]
Image classication loss.
Methods
__call__(*args, **kwargs)Call self as a function.
forward(labels, logits, **kwargs)Applies the image classification loss to a batch of data.
process_loss_config([loss, balance_loss, ...])Initialize the loss function
process_model_config(num_classes, **encoder)Initialize the underlying encoder and the final layer.
- process_model_config(num_classes, **encoder)[source]
Initialize the underlying encoder and the final layer.
- Parameters:
num_classes (int) – Number of classes that each image can be sorted as
**encoder (dict) – Encoder configuration
- process_loss_config(loss='ce', balance_loss=False, weights=None)[source]
Initialize the loss function
- Parameters:
loss (str, default 'ce') – Name of the loss function to apply
balance_loss (bool, default False) – Whether to weight the loss to account for class imbalance
weights (list, optional) –
One weight value per class
- forward(labels, logits, **kwargs)[source]
Applies the image classification loss to a batch of data.
- Parameters:
labels (List[int]) –
List of image labels, one per entry in the batch
logits (TensorBatch) – (B, C) Tensor of predicted logits, one per entry in the batch
**kwargs (dict, optional) – Other labels/outputs of the model which are not relevant here
- Returns:
loss (torch.Tensor) – Value of the loss
accuracy (float) – Value of the image-wise classification accuracy