Predict
Submodules
kale.predict.class_domain_nets module
Classification of data or domain
Modules for typical classification tasks (into class labels) and adversarial discrimination of source vs target domains, from https://github.com/criteo-research/pytorch-ada/blob/master/adalib/ada/models/modules.py
- class kale.predict.class_domain_nets.SoftmaxNet(input_dim=15, n_classes=2, name='c', hidden=(), activation_fn=<class 'torch.nn.modules.activation.ReLU'>, **activation_args)
Bases:
Module
Regular and domain classifier network for regular-size images
- Parameters:
input_dim (int, optional) – the dimension of the final feature vector.. Defaults to 15.
n_classes (int, optional) – the number of classes. Defaults to 2.
name (str, optional) – the classifier name. Defaults to “c”.
hidden (tuple, optional) – the hidden layer sizes. Defaults to ().
activation_fn ([type], optional) – the activation function. Defaults to nn.ReLU.
- forward(input_data)
- extra_repr()
- n_classes()
- class kale.predict.class_domain_nets.ClassNet(n_class=10, input_shape=(-1, 64, 8, 8))
Bases:
Module
Simple classification prediction-head block to plug ontop of the 4D output of a CNN.
- Parameters:
n_class (int, optional) – the number of different classes that can be predicted. Defaults to 10.
input_shape (tuples, optional) – the shape that input to this head will have. Expected to be (batch_size, channels, height, width). Defaults to (-1, 64, 8, 8).
- forward(x)
- class kale.predict.class_domain_nets.ClassNetSmallImage(input_size=128, n_class=10)
Bases:
Module
Regular classifier network for small-size images
- Parameters:
input_size (int, optional) – the dimension of the final feature vector. Defaults to 128.
n_class (int, optional) – the number of classes. Defaults to 10.
- n_classes()
- forward(input)
- class kale.predict.class_domain_nets.DomainNetSmallImage(input_size=128, bigger_discrim=False)
Bases:
Module
Domain classifier network for small-size images
- Parameters:
input_size (int, optional) – the dimension of the final feature vector. Defaults to 128.
bigger_discrim (bool, optional) – whether to use deeper network. Defaults to False.
- forward(input)
- class kale.predict.class_domain_nets.ClassNetVideo(input_size=512, n_channel=100, dropout_keep_prob=0.5, n_class=8)
Bases:
Module
Regular classifier network for video input.
- Parameters:
input_size (int, optional) – the dimension of the final feature vector. Defaults to 512.
n_channel (int, optional) – the number of channel for Linear and BN layers.
dropout_keep_prob (int, optional) – the dropout probability for keeping the parameters.
n_class (int, optional) – the number of classes. Defaults to 8.
- n_classes()
- forward(input)
- class kale.predict.class_domain_nets.ClassNetVideoConv(input_size=1024, n_class=8)
Bases:
Module
Classifier network for video input refer to MMSADA.
- Parameters:
input_size (int, optional) – the dimension of the final feature vector. Defaults to 1024.
n_class (int, optional) – the number of classes. Defaults to 8.
References
Munro Jonathan, and Dima Damen. “Multi-modal domain adaptation for fine-grained action recognition.” In CVPR, pp. 122-132. 2020.
- forward(input)
- class kale.predict.class_domain_nets.DomainNetVideo(input_size=128, n_channel=100)
Bases:
Module
Regular domain classifier network for video input.
- Parameters:
input_size (int, optional) – the dimension of the final feature vector. Defaults to 512.
n_channel (int, optional) – the number of channel for Linear and BN layers.
- forward(input)
kale.predict.decode module
Provides implementations of various decoders based on neural network modules for prediction and classification tasks. Refer to the PyTorch documentation for the accompanying tutorial on neural network modules: https://pytorch.org/docs/stable/generated/torch.nn.Module.html
- class kale.predict.decode.MLPDecoder(in_dim, hidden_dim, out_dim, dropout_rate=0.1, include_decoder_layers=False)
Bases:
Module
A generalized MLP model that can act as either a 2-layer MLPDecoder or a 4-layer MLPDecoder based on the include_decoder_layers parameter.
- Parameters:
in_dim (int) – the dimension of input feature.
hidden_dim (int) – the dimension of hidden layers.
out_dim (int) – the dimension of output layer.
dropout_rate (float) – the dropout rate during training.
include_decoder_layers (bool) – whether or not to include the additional layers that are part of the MLPDecoder
- forward(x)
- class kale.predict.decode.DistMultDecoder(in_channels: int, num_edge_type: int)
Bases:
Module
Build DistMult factorization as GripNet decoder in PoSE dataset. Copy-paste with slight modifications from https://github.com/NYXFLOWER/GripNet.
- Parameters:
in_channels (int) – the dimension of input feature.
num_edge_type (int) – the number of edge types.
- forward(x, edge_index: Tensor, edge_type: Tensor, sigmoid: bool = True) Tensor
- Parameters:
x – the input node feature embeddings.
edge_index – the edge index in COO format with shape [2, num_edges].
edge_type – the one-dimensional relation type/index for each target edge in edge_index.
sigmoid – whether to use sigmoid function or not.
- reset_parameters()
- class kale.predict.decode.GripNetLinkPrediction(supergraph: SuperGraph, learning_rate: float, epsilon: float = 1e-13)
Bases:
LightningModule
Build GripNet-DistMult (encoder-decoder) model for link prediction.
- Parameters:
supergraph (SuperGraph) – the input supergraph.
learning_rate (float) – the learning rate for training.
epsilon (float, optional) – a small number in loss function to improve numerical stability. Defaults to 1e-13.
- forward(edge_index: Tensor, edge_type: Tensor, edge_type_range: Tensor) Tuple
- configure_optimizers()
- training_step(batch, batch_idx)
- validation_step(batch, batch_idx)
- test_step(batch, batch_idx)
- class kale.predict.decode.LinearClassifier(in_dim: int, out_dim: int, bias: bool = True)
Bases:
Module
Build a linear transformation module.
- Parameters:
in_dim (int) – Size of each input sample.
out_dim (int) – Size of each output sample.
bias (bool, optional) – If set to
False
, the layer will not learn an additive bias. (default:True
)
- reset_parameters() None
Initialize the parameters of the model.
- forward(x: Tensor) Tensor
- class kale.predict.decode.VCDN(num_modalities: int, num_classes: int, hidden_dim: int)
Bases:
Module
The View Correlation Discovery Network (VCDN) to learn the higher-level intra-view and cross-view correlations in the label space, implemented according to the method described in ‘MOGONET integrates multi-omics data using graph convolutional networks allowing patient classification and biomarker identification’ - Wang, T., Shao, W., Huang, Z., Tang, H., Zhang, J., Ding, Z., Huang, K. (2021).
- Parameters:
num_modalities (int) – The total number of modalities in the dataset.
num_classes (int) – The total number of classes in the dataset.
hidden_dim (int) – Size of the hidden layer.
- reset_parameters() None
Initialize the parameters of the model.
- forward(multimodal_input: List[Tensor]) Tensor
kale.predict.isonet module
The ISONet module, which is based on the ResNet module, from https://github.com/HaozhiQi/ISONet/blob/master/isonet/models/isonet.py (based on https://github.com/facebookresearch/pycls/blob/master/pycls/models/resnet.py)
- kale.predict.isonet.get_trans_fun(name)
Retrieves the transformation function by name.
- class kale.predict.isonet.BasicTransform(w_in, w_out, stride, has_bn, use_srelu, w_b=None, num_gs=1)
Bases:
Module
Basic transformation: 3x3, 3x3
- forward(x)
- class kale.predict.isonet.BottleneckTransform(w_in, w_out, stride, has_bn, use_srelu, w_b, num_gs)
Bases:
Module
Bottleneck transformation: 1x1, 3x3, 1x1, only for very deep networks
- forward(x)
- class kale.predict.isonet.ResBlock(w_in, w_out, stride, trans_fun, has_bn, has_st, use_srelu, w_b=None, num_gs=1)
Bases:
Module
Residual block: x + F(x)
- forward(x)
- class kale.predict.isonet.ResStage(w_in, w_out, stride, net_params, d, w_b=None, num_gs=1)
Bases:
Module
Stage of ResNet.
- forward(x)
- class kale.predict.isonet.ResStem(w_in, w_out, net_params, kernelsize=3, stride=1, padding=1, use_maxpool=False, poolksize=3, poolstride=2, poolpadding=1)
Bases:
Module
Stem of ResNet.
- forward(x)
- class kale.predict.isonet.ISONet(net_params)
Bases:
Module
ISONet, a modified ResNet model.
- forward(x)
- ortho(device)
regularizes the convolution kernel to be (near) orthogonal during training. This is called in Trainer.loss of the isonet example.
- ortho_conv(m, device)
regularizes the convolution kernel to be (near) orthogonal during training.
- Parameters:
m (nn.module]) – [description]
kale.predict.uncertainty_binning
Authors: Lawrence Schobs, lawrenceschobs@gmail.com Module from the implementation of L. A. Schobs, A. J. Swift and H. Lu, “Uncertainty Estimation for Heatmap-Based Landmark Localization,” in IEEE Transactions on Medical Imaging, vol. 42, no. 4, pp. 1021-1034, April 2023, doi: 10.1109/TMI.2022.3222730.
- Functions to predict uncertainty quantiles from the quantile binning method. Includes:
Binning Predictions: quantile_binning_predictions
- kale.predict.uncertainty_binning.quantile_binning_predictions(uncertainties_test: Dict[str, int | float], uncert_thresh: List[List[float]], save_pred_path: str | None = None) Dict[str, int]
Bin predictions based on quantile thresholds.
- Parameters:
uncertainties_test (Dict) – A dictionary of uncertainties with string ids and float/int uncertainty values.
uncert_thresh (List[List[float]]) – A list of quantile thresholds to determine binning.
save_pred_path (str, optional) – A path preamble to save predicted bins to.
- Returns:
A dictionary of predicted quantile bins with string ids as keys and integer bin values as values.
- Return type:
Dict