ncalab.models.applications.classification.classificationNCA
Classes
Abstract base class for NCA models. |
Module Contents
- class ncalab.models.applications.classification.classificationNCA.ClassificationNCAModel(device: torch.device, num_image_channels: int, num_hidden_channels: int, num_classes: int, fire_rate: float = 0.8, hidden_size: int = 128, use_alive_mask: bool = False, pixel_wise_loss: bool = False, num_learned_filters: int = 2, filter_padding: Literal['zero', 'reflect', 'replicate', 'circular'] = 'reflect', use_laplace: bool = False, kernel_size: int = 3, pad_noise: bool = False, use_temporal_encoding: bool = False, use_classifier: bool = True, class_names: List[str] | None = None, avg_pool_size: int = 8, lambda_hidden: float = 0, **kwargs)
Bases:
ncalab.models.basicNCA.AbstractNCAModelAbstract base class for NCA models.
BasicNCAModel is a composition of an NCA backbone model (called “rule”), and an (optional) head module for downstream tasks.
- Parameters:
device – Pytorch device descriptor.
num_image_channels – _description_
num_hidden_channels – _description_
num_classes – _description_
fire_rate – Fire rate for stochastic weight update. Defaults to 0.8.
hidden_size – Number of neurons in hidden layer. Defaults to 128.
use_alive_mask – Whether to use alive masking (channel 3) during training. Defaults to False.
pixel_wise_loss – Whether a prediction per pixel is desired, like in self-classifying MNIST. Defaults to False.
num_learned_filters – Number of learned filters. If zero, use two sobel filters instead. Defaults to 2.
filter_padding – Padding type to use. Might affect reliance on spatial cues. Defaults to “circular”.
pad_noise – Whether to pad input image tensor with noise in hidden / output channels
- _num_classes
- pixel_wise_loss = False
- use_classifier = True
- avg_pool_size = 8
- metrics
- focal_loss
- property num_classes: int
- classify(image: torch.Tensor, steps: int = 100, reduce: bool = False) torch.Tensor
Predict classification for an input image.
- Parameters:
image – Input image.
steps – Inference steps. Defaults to 100.
reduce – Return a single softmax probability. Defaults to False.
- Returns:
Single class index or vector of logits.
- loss(pred: ncalab.prediction.Prediction, label: torch.Tensor) Dict[str, torch.Tensor]
Return the classification loss.
- Parameters:
pred – Prediction.
label – Ground truth.
- Returns:
Dictionary of identifiers mapped to computed losses.
- post_prediction(prediction: ncalab.prediction.Prediction) ncalab.prediction.Prediction