shapenet¶
shapenet
provides a PyTorch Implementation of Super-Realtime Facial Landmark Detection by Deep Regression of Shape Model Parameters
ShapeNet¶
The ShapeNet
package provides a PyTorch
implementation of our paper “Super-Realtime Facial Landmark Detection and Shape Fitting by Deep Regression of Shape Model Parameters”.
It cointains:
JIT¶
The jit
subpackage contains simplified implementations of some modules
(networks and layers) to export them via torch.jit
Layers¶
The following layers have been simplified for torch.jit
:
HomogeneousShapeLayer¶
-
class
HomogeneousShapeLayer
(shapes, n_dims, use_cpp=False)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Module to Perform a Shape Prediction (including a global homogeneous transformation)
HomogeneousTransformationLayer¶
-
class
HomogeneousTransformationLayer
(n_dims: int, use_cpp=False)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Wrapper Class to Wrap the Python and C++ API into a combined python API
-
forward
(shapes: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcb7b8>, params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcb7f0>)[source]¶ Selects individual parameters from
params
and forwards them through the actual layer implementationParameters: - shapes (
torch.Tensor
) – shapes to transform - params (
torch.Tensor
) – parameters specifying the affine transformation
Returns: the transformed shapes in cartesian coordinates
Return type: torch.Tensor
- shapes (
-
num_params
¶
-
_HomogeneousTransformationLayerPy¶
-
class
_HomogeneousTransformationLayerPy
(n_dims)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Module to perform homogeneous transformations in 2D and 3D (Implemented in Python)
-
_ensemble_2d_matrix
(rotation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcba58>, translation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcba90>, scale_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcbac8>)[source]¶ ensembles the homogeneous transformation matrix for 2D
Parameters: - rotation_params (
torch.Tensor
) – parameters specifying the rotation (one parameter) - translation_params (
torch.Tensor
) – parameters specifying the translation (two parameters) - scale_params (
torch.Tensor
) – parameter specifying the global scaling factor (one parameter) (currently only isotropic scaling supported)
Returns: 2D transformation matrix
Return type: torch.Tensor
- rotation_params (
-
_ensemble_3d_matrix
(rotation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcbb00>, translation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcbb38>, scale_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcbb70>)[source]¶ ensembles the homogeneous transformation matrix for 3D
Parameters: - rotation_params (
torch.Tensor
) – parameters specifying the rotation (three parameters) - translation_params (
torch.Tensor
) – parameters specifying the translation (three parameters) - scale_params (
torch.Tensor
) – parameter specifying the global scaling factor (one parameter) (currently only isotropic scaling supported)
Returns: 3D transformation matrix
Return type: torch.Tensor
- rotation_params (
-
_ensemble_trafo
(rotation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcb9b0>, translation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcb9e8>, scale_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcba20>)[source]¶ ensembles the transformation matrix in 2D and 3D
Parameters: - rotation_params (
torch.Tensor
) – parameters specifying the rotation (one per DoF) - translation_params (
torch.Tensor
) – parameters specifying the translation (one per dimension) - scale_params (
torch.Tensor
) – parameter specifying the global scaling factor (currently only isotropic scaling supported)
Returns: transformation matrix
Return type: torch.Tensor
- rotation_params (
-
forward
(shapes: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcb898>, rotation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcb8d0>, translation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcb908>, scale_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfcb940>)[source]¶ ensembles the homogeneous transformation matrix and applies it to the shape tensor
Parameters: - shapes (
torch.Tensor
) – shapes to transform - rotation_params (
torch.Tensor
) – parameters specifying the rotation (one per DoF) - translation_params (
torch.Tensor
) – parameters specifying the translation (one per dimension) - scale_params (
torch.Tensor
) – parameter specifying the global scaling factor (currently only isotropic scaling supported)
Returns: the transformed shapes in cartesian coordinates
Return type: torch.Tensor
- shapes (
-
AbstractShapeNetwork¶
AbstractFeatureExtractor¶
-
class
AbstractFeatureExtractor
(in_channels, out_params, norm_class, p_dropout=0)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Abstract Feature Extractor Class all further feature extractors should be derived from
Conv2dRelu¶
Img224x224Kernel7x7SeparatedDims¶
-
class
Img224x224Kernel7x7SeparatedDims
(in_channels, out_params, norm_class, p_dropout=0)[source]¶ Bases:
shapenet.jit.abstract_network.AbstractFeatureExtractor
-
static
_build_model
(in_channels, out_params, norm_class, p_dropout)[source]¶ Build the actual model structure
Parameters: Returns: ensembled model
Return type: torch.jit.ScriptModule
-
forward
(input_batch)¶ Feed batch through network
Parameters: input_batch ( torch.Tensor
) – batch to feed through networkReturns: extracted features Return type: torch.Tensor
-
static
ShapeNetwork¶
-
class
ShapeNetwork
(layer_cls, layer_kwargs, in_channels=1, norm_type='instance', img_size=224, tiny=False, feature_extractor=None, **kwargs)[source]¶ Bases:
shapenet.jit.abstract_network.AbstractShapeNetwork
Network to Predict a single shape
-
forward
(input_images)[source]¶ Forward input batch through network and shape layer
Parameters: input_images ( torch.Tensor
) – input batchReturns: predicted shapes Return type: torch.Tensor
-
model
¶
-
static
norm_type_to_class
(norm_type)¶
-
Layer¶
The layer
subpackage contains implementations of all provided layers
ShapeLayer¶
-
class
ShapeLayer
(shapes, use_cpp=False)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Wrapper to compine Python and C++ Implementation under Single API
_ShapeLayerPy¶
-
class
_ShapeLayerPy
(shapes)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Python Implementation of Shape Layer
_ShapeLayerCpp¶
-
class
_ShapeLayerCpp
(shapes, verbose=True)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
C++ Implementation of Shape Layer
HomogeneousTransformationLayer¶
-
class
HomogeneousTransformationLayer
(n_dims: int, use_cpp=False)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Wrapper Class to Wrap the Python and C++ API into a combined python API
-
forward
(shapes: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3198>, params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc31d0>)[source]¶ Actual prediction
Parameters: - shapes (
torch.Tensor
) – shapes before applied global transformation - params (
torch.Tensor
) – parameters specifying the global transformation
Returns: Transformed shapes
Return type: torch.Tensor
- shapes (
-
num_params
¶
-
_HomogeneousTransformationLayerPy¶
-
class
_HomogeneousTransformationLayerPy
(n_dims)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Module to perform homogeneous transformations in 2D and 3D (Implemented in Python)
-
_ensemble_2d_matrix
(rotation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3550>, translation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3588>, scale_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc35c0>)[source]¶ ensembles the homogeneous transformation matrix for 2D
Parameters: - rotation_params (
torch.Tensor
) – parameters specifying the rotation (one parameter) - translation_params (
torch.Tensor
) – parameters specifying the translation (two parameters) - scale_params (
torch.Tensor
) – parameter specifying the global scaling factor (one parameter) (currently only isotropic scaling supported)
Returns: 2D transformation matrix
Return type: torch.Tensor
- rotation_params (
-
_ensemble_3d_matrix
(rotation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc35f8>, translation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3630>, scale_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3668>)[source]¶ ensembles the homogeneous transformation matrix for 3D
Parameters: - rotation_params (
torch.Tensor
) – parameters specifying the rotation (three parameters) - translation_params (
torch.Tensor
) – parameters specifying the translation (three parameters) - scale_params (
torch.Tensor
) – parameter specifying the global scaling factor (one parameter) (currently only isotropic scaling supported)
Returns: 3D transformation matrix
Return type: torch.Tensor
- rotation_params (
-
_ensemble_trafo
(rotation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc34a8>, translation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc34e0>, scale_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3518>)[source]¶ ensembles the transformation matrix in 2D and 3D
Parameters: - rotation_params (
torch.Tensor
) – parameters specifying the rotation (one per DoF) - translation_params (
torch.Tensor
) – parameters specifying the translation (one per dimension) - scale_params (
torch.Tensor
) – parameter specifying the global scaling factor (currently only isotropic scaling supported)
Returns: transformation matrix
Return type: torch.Tensor
- rotation_params (
-
forward
(shapes: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc33c8>, rotation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3400>, translation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3438>, scale_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3470>)[source]¶ ensembles the homogeneous transformation matrix and applies it to the shape tensor
Parameters: - shapes (
torch.Tensor
) – shapes to transform - rotation_params (
torch.Tensor
) – parameters specifying the rotation (one per DoF) - translation_params (
torch.Tensor
) – parameters specifying the translation (one per dimension) - scale_params (
torch.Tensor
) – parameter specifying the global scaling factor (currently only isotropic scaling supported)
Returns: the transformed shapes in cartesian coordinates
Return type: torch.Tensor
- shapes (
-
_HomogeneousTransformationLayerCpp¶
-
class
_HomogeneousTransformationLayerCpp
(n_dims, verbose=True)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Module to perform homogeneous transformations in 2D and 3D (Implemented in C++)
-
forward
(shapes: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3278>, rotation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc32b0>, translation_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc32e8>, scale_params: <sphinx.ext.autodoc.importer._MockObject object at 0x7fb7fdfc3320>)[source]¶ ensembles the homogeneous transformation matrix and applies it to the shape tensor
Parameters: - shapes (
torch.Tensor
) – shapes to transform - rotation_params (
torch.Tensor
) – parameters specifying the rotation (one per DoF) - translation_params (
torch.Tensor
) – parameters specifying the translation (one per dimension) - scale_params (
torch.Tensor
) – parameter specifying the global scaling factor (currently only isotropic scaling supported)
Returns: the transformed shapes in cartesian coordinates
Return type: torch.Tensor
- shapes (
-
HomogeneousShapeLayer¶
-
class
HomogeneousShapeLayer
(shapes, n_dims, use_cpp=False)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Module to Perform a Shape Prediction (including a global homogeneous transformation)
Networks¶
The networks
subpackage contains implementations of all provided networks
AbstractShapeNetwork¶
AbstractFeatureExtractor¶
-
class
AbstractFeatureExtractor
(in_channels, out_params, norm_class, p_dropout=0)[source]¶ Bases:
sphinx.ext.autodoc.importer._MockObject
Abstract Feature Extractor Class all further feature extracotrs should be derived from
Conv2dRelu¶
Img224x224Kernel7x7SeparatedDims¶
-
class
Img224x224Kernel7x7SeparatedDims
(in_channels, out_params, norm_class, p_dropout=0)[source]¶ Bases:
shapenet.networks.abstract_network.AbstractFeatureExtractor
-
static
_build_model
(in_channels, out_params, norm_class, p_dropout)[source]¶ Build the actual model structure
Parameters: Returns: ensembled model
Return type: torch.nn.Module
-
forward
(input_batch)¶ Feed batch through network
Parameters: input_batch ( torch.Tensor
) – batch to feed through networkReturns: exracted features Return type: torch.Tensor
-
static
ShapeNetwork¶
-
class
ShapeNetwork
(layer_cls, layer_kwargs, in_channels=1, norm_type='instance', img_size=224, feature_extractor=None, **kwargs)[source]¶ Bases:
shapenet.networks.abstract_network.AbstractShapeNetwork
Network to Predict a single shape
-
static
closure
(model, data_dict: dict, optimizers: dict, criterions={}, metrics={}, fold=0, **kwargs)[source]¶ closure method to do a single backpropagation step
Parameters: - model (
ShapeNetwork
) – trainable model - data_dict (dict) – dictionary containing the data
- optimizers (dict) – dictionary of optimizers to optimize model’s parameters
- criterions (dict) – dict holding the criterions to calculate errors (gradients from different criterions will be accumulated)
- 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- model (
-
forward
(input_images)[source]¶ Forward input batch through network and shape layer
Parameters: input_images ( torch.Tensor
) – input batchReturns: predicted shapes Return type: torch.Tensor
-
model
¶
-
static
Scripts¶
The scripts
subpackage contains basic scripts for:
prepare_all_data¶
prepare_helen_dset¶
prepare_lfpw_dset¶
prepare_cat_dset¶
_prepare_ibug_dset¶
-
_prepare_ibug_dset
(zip_file, dset_name, out_dir, remove_zip=False, normalize_pca_rot=True)[source]¶ Prepares an ibug dataset (from a given zipfile)
Parameters: - zip_file (str) – the zip archive containing the data
- dset_name (str) – the dataset’s name
- out_dir (str) – the output directory
- remove_zip (bool, optional) – whether or not to remove the ZIP file after finishing the preparation
- normalize_pca_rot (bool, optional) – whether or not to normalize the data’s rotation during PCA
See also
_prepare_cats¶
_process_single_cat_file¶
_make_pca¶
-
_make_pca
(data_dir, out_file, normalize_rot=False, rotation_idxs=())[source]¶ Creates a PCA from data in a given directory
Parameters: - data_dir (str) – directory containing the image and landmark files
- out_file (str) – file the pca will be saved to
- normalize_rot (bool, optional) – whether or not to normalize the data’s rotation
- rotation_idxs (tuple, optional) – indices for rotation normalization, msut be specified if
normalize_rot=True
train_shapenet¶
Utils¶
The utils
subpackage contains general utilities, whcih did not fit into any
other subpackage