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(x)
class kale.predict.class_domain_nets.DomainNetSmallImage(input_size=128, hidden_size=100, deep_hidden_size=500, num_classes=2, bigger_discrim=False)

Bases: Module

Domain classifier network for small-size images

Parameters:
  • input_size (int, optional) – Size of the input feature vector (i.e., number of input features). Defaults to 128.

  • hidden_size (int, optional) – Size of the hidden layer. Used if bigger_discrim is False. Defaults to 100.

  • deep_hidden_size (int, optional) – Size of the first hidden layer when using the deeper (bigger_discrim=True) network configuration. Defaults to 500.

  • num_classes (int, optional) – Size of the final output layer. Defaults to 2 (e.g., binary domain classification).

  • bigger_discrim (bool, optional) – whether to use deeper network. Defaults to False.

forward(x)
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

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.SReLU(nc)

Bases: Module

Shifted ReLU

forward(x)
class kale.predict.isonet.ResHead(w_in, net_params)

Bases: Module

ResNet head.

forward(x)
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:
  1. Binning Predictions: quantile_binning_predictions

kale.predict.uncertainty_binning.quantile_binning_predictions(uncertainties_test: Dict[str, int | float], uncert_thresh: 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[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

Module contents