---
title: Lip Vertex Error
description: Implements Lip Vertex Error (LVE) metric for 3D talking head evaluation.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/multimodal/lve'
---
# Lip Vertex Error {#lip-vertex-error}

## Module Interface {#module-interface}

### `class torchmetrics.multimodal.lve.LipVertexError(mouth_map, validate_args=True, **kwargs)` {#torchmetrics.multimodal.lve.LipVertexError}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/multimodal/lve.py#L28-L190)

Implements Lip Vertex Error (LVE) metric for 3D talking head evaluation.

The Lip Vertex Error (LVE) metric evaluates the quality of lip synchronization in 3D facial animations by measuring the maximum Euclidean distance (L2 error) between corresponding lip vertices of the generated and ground truth meshes for each frame. The metric is defined as:

```math
\text{LVE} = \frac{1}{N} \sum_{i=1}^{N} \max_{v \in \text{lip}} \|x_{i,v} - \hat{x}_{i,v}\|_2^2
```

where $`N`$ is the number of frames, $`x_{i,v}`$ represents the 3D coordinates of vertex $`v`$ in the lip region of the ground truth frame $`i`$, and $`\hat{x}_{i,v}`$ represents the corresponding vertex in the predicted frame. The metric computes the maximum squared L2 distance between corresponding lip vertices for each frame and averages across all frames. A lower LVE value indicates better lip synchronization quality.

As input to `forward` and `update`, the metric accepts the following input:

*   `preds` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): Predicted vertices tensor of shape (T, V, 3) where T is number of frames,
    
    V is number of vertices, and 3 represents XYZ coordinates
    
*   `target` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): Ground truth vertices tensor of shape (T’, V, 3) where T’ can be different
    
    from T
    

As output of `forward` and `compute`, the metric returns the following output:

*   `lve_score` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): A scalar tensor containing the mean Lip Vertex Error value across
    
    all frames.
    

Parameters:

*   **mouth\_map** ([`List`](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – List of vertex indices corresponding to the mouth region
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If the number of dimensions of vertices\_pred or vertices\_gt is not 3. If vertex dimensions (V) or coordinate dimensions (3) don’t match If `mouth_map` is empty or contains invalid indices

Example

```python
>>> import torch
>>> from torchmetrics.functional.multimodal import lip_vertex_error
>>> vertices_pred = torch.randn(10, 100, 3, generator=torch.manual_seed(42))
>>> vertices_gt = torch.randn(10, 100, 3, generator=torch.manual_seed(43))
>>> mouth_map = [0, 1, 2, 3, 4]
>>> lip_vertex_error(vertices_pred, vertices_gt, mouth_map)
tensor(12.7688)
```

#### `compute()` {#torchmetrics.multimodal.lve.LipVertexError.compute}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/multimodal/lve.py#L135-L144)

Compute the Lip Vertex Error over all accumulated states.

Returns:

A scalar tensor with the mean LVE value

Return type:

[torch.Tensor](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

#### `plot(val=None, ax=None)` {#torchmetrics.multimodal.lve.LipVertexError.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/multimodal/lve.py#L146-L190)

Plot a single or multiple values from the metric.

Parameters:

*   **val** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Sequence`](https://docs.python.org/3/library/typing.html#typing.Sequence "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.
    
*   **ax** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)")\]) – An matplotlib axis object. If provided will add plot to that axis
    

Return type:

[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure "(in Matplotlib v3.11.2)"), `Union`\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)"), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.5)")\]\]

Returns:

Figure and Axes object

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If matplotlib is not installed

```python
>>> # Example plotting a single value
>>> import torch
>>> from torchmetrics.multimodal.lve import LipVertexError
>>> metric = LipVertexError(mouth_map=[0, 1, 2, 3, 4])
>>> vertices_pred = torch.randn(10, 100, 3, generator=torch.manual_seed(42))
>>> vertices_gt = torch.randn(10, 100, 3, generator=torch.manual_seed(43))
>>> metric.update(vertices_pred, vertices_gt)
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/lve-1.png](/docs/torchmetrics/1.9.0/static/_images/lve-1.png)](/docs/torchmetrics/1.9.0/static/_images/lve-1.png)

```python
>>> # Example plotting multiple values
>>> import torch
>>> from torchmetrics.multimodal.lve import LipVertexError
>>> metric = LipVertexError(mouth_map=[0, 1, 2, 3, 4])
>>> values = []
>>> for _ in range(10):
...     vertices_pred = torch.randn(10, 100, 3, generator=torch.manual_seed(42+_))
...     vertices_gt = torch.randn(10, 100, 3, generator=torch.manual_seed(43+_))
...     values.append(metric(vertices_pred, vertices_gt))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/lve-2.png](/docs/torchmetrics/1.9.0/static/_images/lve-2.png)](/docs/torchmetrics/1.9.0/static/_images/lve-2.png)

#### `update(vertices_pred, vertices_gt)` {#torchmetrics.multimodal.lve.LipVertexError.update}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/multimodal/lve.py#L102-L133)

Update metric states with predictions and targets.

Parameters:

*   **vertices\_pred** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Predicted vertices tensor of shape (T, V, 3) where T is number of frames, V is number of vertices, and 3 represents XYZ coordinates
    
*   **vertices\_gt** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Ground truth vertices tensor of shape (T’, V, 3) where T’ can be different from T
    

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

## Functional Interface {#functional-interface}

### `torchmetrics.functional.multimodal.lve.lip_vertex_error(vertices_pred, vertices_gt, mouth_map, validate_args=True)` {#torchmetrics.functional.multimodal.lve.lip_vertex_error}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/multimodal/lve.py#L20-L93)

Compute Lip Vertex Error (LVE) for 3D talking head evaluation.

The Lip Vertex Error (LVE) metric evaluates the quality of lip synchronization in 3D facial animations by measuring the maximum Euclidean distance (L2 error) between corresponding lip vertices of the generated and ground truth meshes for each frame. The metric is defined as:

```math
\text{LVE} = \frac{1}{N} \sum_{i=1}^{N} \max_{v \in \text{lip}} \|x_{i,v} - \hat{x}_{i,v}\|_2^2
```

where $`N`$ is the number of frames, $`x_{i,v}`$ represents the 3D coordinates of vertex $`v`$ in the lip region of the ground truth frame $`i`$, and $`\hat{x}_{i,v}`$ represents the corresponding vertex in the predicted frame. The metric computes the maximum squared L2 distance between corresponding lip vertices for each frame and averages across all frames. A lower LVE value indicates better lip synchronization quality.

Parameters:

*   **vertices\_pred** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Predicted vertices tensor of shape (T, V, 3) where T is number of frames, V is number of vertices, and 3 represents XYZ coordinates
    
*   **vertices\_gt** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Ground truth vertices tensor of shape (T’, V, 3) where T’ can be different from T
    
*   **mouth\_map** ([`List`](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – List of vertex indices corresponding to the mouth region
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    

Returns:

Scalar tensor containing the mean LVE value across all frames

Return type:

[torch.Tensor](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If the number of dimensions of vertices\_pred or vertices\_gt is not 3. If vertex dimensions (V) or coordinate dimensions (3) don’t match If `mouth_map` is empty or contains invalid indices

Example

```python
>>> import torch
>>> from torchmetrics.functional.multimodal import lip_vertex_error
>>> vertices_pred = torch.randn(10, 100, 3, generator=torch.manual_seed(42))
>>> vertices_gt = torch.randn(10, 100, 3, generator=torch.manual_seed(43))
>>> mouth_map = [0, 1, 2, 3, 4]
>>> lip_vertex_error(vertices_pred, vertices_gt, mouth_map)
tensor(12.7688)
```

---

**Navigation**

- Parent: [Multimodal](/docs/torchmetrics/1.9.0/multimodal.md)
