---
title: Modified Panoptic Quality
description: Compute Modified Panoptic Quality for panoptic segmentations.
canonical: >-
  https://lightning.ai/docs/torchmetrics/stable/detection/modified_panoptic_quality
---
# Modified Panoptic Quality {#modified-panoptic-quality}

## Module Interface {#module-interface}

### `class torchmetrics.detection.ModifiedPanopticQuality(things, stuffs, allow_unknown_preds_category=False, **kwargs)` {#torchmetrics.detection.ModifiedPanopticQuality}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/detection/panoptic_qualities.py#L293-L476)

Compute [Modified Panoptic Quality](#modified-panoptic-quality) for panoptic segmentations.

The metric was introduced in [Seamless Scene Segmentation paper](https://arxiv.org/abs/1905.01220), and is an adaptation of the original [Panoptic Quality](https://arxiv.org/abs/1801.00868) where the metric for a stuff class is computed as

```math
PQ^{\dagger}_c = \frac{IOU_c}{|S_c|}
```

where $`IOU_c`$ is the sum of the intersection over union of all matching segments for a given class, and $`|S_c|`$ is the overall number of segments in the ground truth for that class.

Parameters:

*   **things** ([`Collection`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Collection "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Set of `category_id` for countable things.
    
*   **stuffs** ([`Collection`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Collection "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Set of `category_id` for uncountable stuffs.
    
*   **allow\_unknown\_preds\_category** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Boolean flag to specify if unknown categories in the predictions are to be ignored in the metric computation or raise an exception when found.
    

Raises:

*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `things`, `stuffs` have at least one common `category_id`.
    
*   [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – If `things`, `stuffs` contain non-integer `category_id`.
    

Example

```python
>>> from torch import tensor
>>> from torchmetrics.detection import ModifiedPanopticQuality
>>> preds = tensor([[[0, 0], [0, 1], [6, 0], [7, 0], [0, 2], [1, 0]]])
>>> target = tensor([[[0, 1], [0, 0], [6, 0], [7, 0], [6, 0], [255, 0]]])
>>> pq_modified = ModifiedPanopticQuality(things = {0, 1}, stuffs = {6, 7})
>>> pq_modified(preds, target)
tensor(0.7667, dtype=torch.float64)
```

#### `plot(val=None, ax=None)` {#torchmetrics.detection.ModifiedPanopticQuality.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/detection/panoptic_qualities.py#L417-L476)

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 object and Axes object

Raises:

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

```python
>>> from torch import tensor
>>> from torchmetrics.detection import ModifiedPanopticQuality
>>> preds = tensor([[[[6, 0], [0, 0], [6, 0], [6, 0]],
...                  [[0, 0], [0, 0], [6, 0], [0, 1]],
...                  [[0, 0], [0, 0], [6, 0], [0, 1]],
...                  [[0, 0], [7, 0], [6, 0], [1, 0]],
...                  [[0, 0], [7, 0], [7, 0], [7, 0]]]])
>>> target = tensor([[[[6, 0], [0, 1], [6, 0], [0, 1]],
...                   [[0, 1], [0, 1], [6, 0], [0, 1]],
...                   [[0, 1], [0, 1], [6, 0], [1, 0]],
...                   [[0, 1], [7, 0], [1, 0], [1, 0]],
...                   [[0, 1], [7, 0], [7, 0], [7, 0]]]])
>>> metric = ModifiedPanopticQuality(things = {0, 1}, stuffs = {6, 7})
>>> metric.update(preds, target)
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/modified\_panoptic\_quality-1.png](/docs/torchmetrics/1.9.0/static/_images/modified_panoptic_quality-1.png)](/docs/torchmetrics/1.9.0/static/_images/modified_panoptic_quality-1.png)

```python
>>> # Example plotting multiple values
>>> from torch import tensor
>>> from torchmetrics.detection import ModifiedPanopticQuality
>>> preds = tensor([[[[6, 0], [0, 0], [6, 0], [6, 0]],
...                  [[0, 0], [0, 0], [6, 0], [0, 1]],
...                  [[0, 0], [0, 0], [6, 0], [0, 1]],
...                  [[0, 0], [7, 0], [6, 0], [1, 0]],
...                  [[0, 0], [7, 0], [7, 0], [7, 0]]]])
>>> target = tensor([[[[6, 0], [0, 1], [6, 0], [0, 1]],
...                   [[0, 1], [0, 1], [6, 0], [0, 1]],
...                   [[0, 1], [0, 1], [6, 0], [1, 0]],
...                   [[0, 1], [7, 0], [1, 0], [1, 0]],
...                   [[0, 1], [7, 0], [7, 0], [7, 0]]]])
>>> metric = ModifiedPanopticQuality(things = {0, 1}, stuffs = {6, 7})
>>> vals = []
>>> for _ in range(20):
...     vals.append(metric(preds, target))
>>> fig_, ax_ = metric.plot(vals)
```

[![../../\_images/modified\_panoptic\_quality-2.png](/docs/torchmetrics/1.9.0/static/_images/modified_panoptic_quality-2.png)](/docs/torchmetrics/1.9.0/static/_images/modified_panoptic_quality-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.detection.modified_panoptic_quality(preds, target, things, stuffs, allow_unknown_preds_category=False)` {#torchmetrics.functional.detection.modified_panoptic_quality}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/detection/panoptic_qualities.py#L175-L249)

Compute [Modified Panoptic Quality](#modified-panoptic-quality) for panoptic segmentations.

The metric was introduced in [Seamless Scene Segmentation paper](https://arxiv.org/abs/1905.01220), and is an adaptation of the original [Panoptic Quality](https://arxiv.org/abs/1801.00868) where the metric for a stuff class is computed as

```math
PQ^{\dagger}_c = \frac{IOU_c}{|S_c|}
```

where $`IOU_c`$ is the sum of the intersection over union of all matching segments for a given class, and $`|S_c|`$ is the overall number of segments in the ground truth for that class.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – torch tensor with panoptic detection of shape \[height, width, 2\] containing the pair (category\_id, instance\_id) for each pixel of the image. If the category\_id refer to a stuff, the instance\_id is ignored.
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – torch tensor with ground truth of shape \[height, width, 2\] containing the pair (category\_id, instance\_id) for each pixel of the image. If the category\_id refer to a stuff, the instance\_id is ignored.
    
*   **things** ([`Collection`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Collection "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Set of `category_id` for countable things.
    
*   **stuffs** ([`Collection`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Collection "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Set of `category_id` for uncountable stuffs.
    
*   **allow\_unknown\_preds\_category** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Boolean flag to specify if unknown categories in the predictions are to be ignored in the metric computation or raise an exception when found.
    

Raises:

*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `things`, `stuffs` have at least one common `category_id`.
    
*   [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – If `things`, `stuffs` contain non-integer `category_id`.
    
*   [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – If `preds` or `target` is not an `torch.Tensor`.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `preds` or `target` has different shape.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `preds` has less than 3 dimensions.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If the final dimension of `preds` has size != 2.
    

Return type:

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

Example

```python
>>> from torch import tensor
>>> preds = tensor([[[0, 0], [0, 1], [6, 0], [7, 0], [0, 2], [1, 0]]])
>>> target = tensor([[[0, 1], [0, 0], [6, 0], [7, 0], [6, 0], [255, 0]]])
>>> modified_panoptic_quality(preds, target, things = {0, 1}, stuffs = {6, 7})
tensor(0.7667, dtype=torch.float64)
```

---

**Navigation**

- Parent: [Detection](/docs/torchmetrics/1.9.0/detection.md)
