Model

DeepAlignmentNetwork

class DeepAlignmentNetwork(mean_shape, input_size=112, num_stages=1, p_dropout=0.5, patch_size=16, active_stages_begin=1, return_intermediate_lmks=True, norm_type='instance')[source]

Bases: sphinx.ext.autodoc.importer._MockObject

The actual deep alignment model holding all stages and the logic inbetween

References

Original TensorFlow Implementation Paper

Parameters:
  • mean_shape (numpy.ndarray or torch.Tensor) – the mean shape
  • input_size (int or tuple, optional) – the size of the input images (the default is 112)
  • num_stages (int, optional) – the number of DeepAlignmentStages (the default is 1)
  • p_dropout (float, optional) – the dropout probability (the default is 0.5)
  • patch_size (int, optional) – the patch size for heatmap generation (the default is 16)
  • active_stages_begin (int, optional) – the active stages at the beginning (the default is 1)
  • return_intermediate_lmks (bool, optional) – whether or not to return all landmarks from intermediate stages concatenated into one 4D tensor of shape N x NumStages x NumLandmarks x 2 (the default is True)
  • norm_type (str, optional) – which kind of normalization to apply (the default is “instance”)
static closure(model: <sphinx.ext.autodoc.importer._MockObject object at 0x7fd0531f9b00>, data_dict: dict, optimizers: dict, criterions={}, metrics={}, fold=0, **kwargs)[source]

closure method to do a single backpropagation step :param model: trainable model :type model: ClassificationNetworkBasePyTorch :param data_dict: dictionary containing the data :type data_dict: dict :param optimizers: dictionary of optimizers to optimize model’s parameters :type optimizers: dict :param criterions: dict holding the criterions to calculate errors

(gradients from different criterions will be accumulated)
Parameters:
  • metrics (dict) – dict holding the metrics to calculate
  • fold (int) – Current Fold in Crossvalidation (default: 0)
  • **kwargs – additional keyword arguments
Returns:

  • dict – Metric values (with same keys as input dict metrics)
  • dict – Loss values (with same keys as input dict criterions)
  • list – Arbitrary number of predictions as torch.Tensor

Raises:

AssertionError – if optimizers or criterions are empty or the optimizers are not specified

forward(input_image)[source]

Feeds an input image through aall stages

Parameters:input_image (torch.Tensor) – the input image
Returns:the returned landmarks of shape (N x NumStages x NumLandmarks x 2)
Return type:torch.Tensor
static prepare_batch(data_dict, input_device, output_device)[source]

Pushes all batch entries to correct devices and converts to correct type

Parameters:
  • data_dict (dict) – the data dictionary
  • input_device (torch.device or str) – the device for all network inputs
  • output_device (torch.device or str) – the device for all network outputs and targets
Returns:

dictionary with converted data

Return type:

dict