medusa.data.template_data#

This module contains functions to load in “template data”, i.e., the topological templates used by the different models.

Module Contents#

medusa.data.template_data.get_template_mediapipe(device=None)[source]#

Returns the template (vertices and triangles) of the canonical Mediapipe model.

Returns:

template – Dictionary with vertices (“v”) and faces (“f”)

Return type:

dict

Examples

Get the vertices and faces (triangles) of the standard Mediapipe topology (template):

>>> template = get_template_mediapipe()
>>> template['v'].shape
(468, 3)
>>> template['f'].shape
(898, 3)
medusa.data.template_data.get_template_flame(topo='coarse', keys=None, device=None)[source]#

Returns the template (vertices and triangles) of the canonical Flame model, in either its dense or coarse version. Note that this does exactly the same as the get_flame_template() function from the flame.data module.

Parameters:

dense (bool) – Whether to load in the dense version of the template (True) or the coarse version (False)

Raises:

ValueError – If the ‘flame’ package is not installed and/or the Flame file could not be found

Returns:

template – Dictionary with vertices (“v”) and faces (“f”)

Return type:

dict

Examples

Get the vertices and faces (triangles) of the standard Flame topology (template) in either the coarse version (dense=False) or dense version (dense=True)

>>> template = get_template_flame(dense=False)  
>>> template['v'].shape  
(5023, 3)
>>> template['f'].shape  
(9976, 3)
>>> template = get_template_flame(dense=True)  
>>> template['v'].shape  
(59315, 3)
>>> template['f'].shape  
(117380, 3)
medusa.data.template_data.get_external_data_config(key=None)[source]#

Loads the FLAME config file (i.e., the yaml with paths to the FLAME- based models & data.

Parameters:

key (str) – If None (default), the config is returned as a dictionary; if str, then the value associated with the key is returned

Returns:

The config file as a dictionary if key=None, else a string with the value associated with the key

Return type:

dict, str

Examples

Load in the entire config file as a dictionary

>>> cfg = get_external_data_config()
>>> isinstance(cfg, dict)
True

Get the path of the FLAME model:

>>> flame_path = get_external_data_config(key='flame_path')
medusa.data.template_data.get_rigid_vertices(topo, device=DEVICE)[source]#

Gets the default ‘rigid’ vertices (i.e., vertices that can only move rigidly) for a given topology (‘mediapipe’, ‘flame-coarse’, ‘flame-dense’).

Parameters:
  • topo (str) – Topology name (‘mediapipe’, ‘flame-coarse’, or ‘flame-dense’)

  • device (str) – Either ‘cuda’ (GPU) or ‘cpu’

Returns:

v_idx – A long tensor with indices of rigid vertices

Return type:

torch.tensor

medusa.data.template_data.get_vertex_template(topo, device=DEVICE)[source]#

Gets the default vertices (or ‘template’) for a given topology (‘mediapipe’, ‘flame-coarse’, ‘flame-dense’).

Parameters:
  • topo (str) – Topology name (‘mediapipe’, ‘flame-coarse’, or ‘flame-dense’)

  • device (str) – Either ‘cuda’ (GPU) or ‘cpu’

Returns:

target – A float tensor with the default (template) vertices

Return type:

torch.tensor

medusa.data.template_data.get_tris(topo, device=DEVICE)[source]#

Gets the triangles for a given topology (‘mediapipe’, ‘flame-coarse’, ‘flame-dense’).

Parameters:
  • topo (str) – Topology name (‘mediapipe’, ‘flame-coarse’, or ‘flame-dense’)

  • device (str) – Either ‘cuda’ (GPU) or ‘cpu’

Returns:

tris – A long tensor with the triangles

Return type:

torch.tensor