---
title: Relative Average Spectral Error (RASE)
description: >-
  Computes Relative Average Spectral Error (RASE)
  (RelativeAverageSpectralError).
canonical: >-
  https://lightning.ai/docs/torchmetrics/stable/image/relative_average_spectral_error
---
# Relative Average Spectral Error (RASE) {#relative-average-spectral-error-rase}

## Module Interface {#module-interface}

### `class torchmetrics.image.RelativeAverageSpectralError(window_size=8, **kwargs)` {#torchmetrics.image.RelativeAverageSpectralError}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/image/rase.py#L30-L135)

Computes Relative Average Spectral Error (RASE) ([RelativeAverageSpectralError](https://www.semanticscholar.org/paper/Data-Fusion.-Definitions-and-Architectures-Fusion-Wald/51b2b81e5124b3bb7ec53517a5dd64d8e348cadf)).

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)")): Predictions from model of shape `(N,C,H,W)`
    
*   `target` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): Ground truth values of shape `(N,C,H,W)`
    

As output of forward and compute the metric returns the following output

*   `rase` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): returns float scalar tensor with average RASE value over sample
    

Parameters:

*   **window\_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Sliding window used for rmse calculation
    
*   **kwargs** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`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.
    

Returns:

Relative Average Spectral Error (RASE)

Example

```python
>>> from torch import rand
>>> preds = rand(4, 3, 16, 16)
>>> target = rand(4, 3, 16, 16)
>>> rase = RelativeAverageSpectralError()
>>> rase(preds, target)
tensor(5326.40...)
```

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `window_size` is not a positive integer.

#### `plot(val=None, ax=None)` {#torchmetrics.image.RelativeAverageSpectralError.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/image/rase.py#L95-L135)

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/collections.abc.html#collections.abc.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.image import RelativeAverageSpectralError
>>> metric = RelativeAverageSpectralError()
>>> metric.update(torch.rand(4, 3, 16, 16), torch.rand(4, 3, 16, 16))
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/relative\_average\_spectral\_error-1.png](/docs/torchmetrics/1.9.0/static/_images/relative_average_spectral_error-1.png)](/docs/torchmetrics/1.9.0/static/_images/relative_average_spectral_error-1.png)

```python
>>> # Example plotting multiple values
>>> from torch import rand
>>> from torchmetrics.image import RelativeAverageSpectralError
>>> metric = RelativeAverageSpectralError()
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(rand(4, 3, 16, 16), rand(4, 3, 16, 16)))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/relative\_average\_spectral\_error-2.png](/docs/torchmetrics/1.9.0/static/_images/relative_average_spectral_error-2.png)](/docs/torchmetrics/1.9.0/static/_images/relative_average_spectral_error-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.image.relative_average_spectral_error(preds, target, window_size=8)` {#torchmetrics.functional.image.relative_average_spectral_error}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/image/rase.py#L70-L102)

Compute Relative Average Spectral Error (RASE) ([RelativeAverageSpectralError](https://www.semanticscholar.org/paper/Data-Fusion.-Definitions-and-Architectures-Fusion-Wald/51b2b81e5124b3bb7ec53517a5dd64d8e348cadf)).

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Deformed image
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Ground truth image
    
*   **window\_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Sliding window used for rmse calculation
    

Return type:

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

Returns:

Relative Average Spectral Error (RASE)

Example

```python
>>> from torch import rand
>>> from torchmetrics.functional.image import relative_average_spectral_error
>>> preds = rand(4, 3, 16, 16)
>>> target = rand(4, 3, 16, 16)
>>> relative_average_spectral_error(preds, target)
tensor(5326.40...)
```

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `window_size` is not a positive integer.

---

**Navigation**

- Parent: [Image](/docs/torchmetrics/1.9.0/image.md)
