Skip to content

extract_flame_params 🗿

Extract FLAME parameters from 3D face models.

FLAME model

Check out the interactive FLAME model viewer online:

https://flame.is.tue.mpg.de/interactivemodelviewer.html

Functions:

Name Description
get_flame_params

Get FLAME parameters (e.g., shape) from the list of head models.

load_deca_params

Load estimated FLAME parameters of the DECA model.

load_flame_params

Load FLAME parameters of the original FLAME implementation.

get_flame_params 🗿

get_flame_params(
    list_of_head_nrs: list[str | int],
    param: str,
    model: str = "deca",
) -> DataFrame

Get FLAME parameters (e.g., shape) from the list of head models.

Source code in code/facesim3d/modeling/FLAME/extract_flame_params.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def get_flame_params(list_of_head_nrs: list[str | int], param: str, model: str = "deca") -> pd.DataFrame:
    """Get FLAME parameters (e.g., shape) from the list of head models."""
    model = model.lower()
    assert model in ["deca", "flame"], "Model must be either 'deca' or 'flame'."  # noqa: S101
    assert param in latent_flame_code + (  # noqa: S101
        ["detail"] if model == "deca" else []
    ), f"Parameter must be one of {latent_flame_code}."

    param_loader = load_deca_params if model == "deca" else load_flame_params  # select loader
    param_length = param_loader("Head1")[param].shape[-1]  # get length of parameter from first head
    df_param = pd.DataFrame(
        index=list_of_head_nrs, columns=[f"{param.title()[0]}{i:03d}" for i in range(param_length)]
    )

    # Fill df with FLAME shape params into df
    for head_nr in list_of_head_nrs:
        df_param.loc[head_nr, :] = param_loader(head_nr)[param]

    return df_param

load_deca_params 🗿

load_deca_params(head_idx_or_nr: str | int)

Load estimated FLAME parameters of the DECA model.

Source code in code/facesim3d/modeling/FLAME/extract_flame_params.py
44
45
46
47
48
49
def load_deca_params(head_idx_or_nr: str | int):
    """Load estimated FLAME parameters of the DECA model."""
    head_idx = head_nr_to_index(head_idx_or_nr) if str(head_idx_or_nr).startswith("Head") else head_idx_or_nr
    return np.load(
        Path(paths.data.facemodel.deca, f"{head_idx}_inputs_codedict_orig_numpy.npy"), allow_pickle=True
    ).item()

load_flame_params 🗿

load_flame_params(head_idx_or_nr: str | int)

Load FLAME parameters of the original FLAME implementation.

Source code in code/facesim3d/modeling/FLAME/extract_flame_params.py
52
53
54
55
def load_flame_params(head_idx_or_nr: str | int):
    """Load FLAME parameters of the original FLAME implementation."""
    head_idx = head_nr_to_index(head_idx_or_nr) if str(head_idx_or_nr).startswith("Head") else head_idx_or_nr
    return np.load(Path(paths.data.facemodel.flame, f"{head_idx}_inputs_FLAMEfit.npy"), allow_pickle=True).item()