Panoptic Quality¶
Module Interface¶
- class torchmetrics.detection.PanopticQuality(things, stuffs, allow_unknown_preds_category=False, **kwargs)[source]
Compute the Panoptic Quality for panoptic segmentations.

where IOU, TP, FP and FN are respectively the sum of the intersection over union for true positives, the number of true postitives, false positives and false negatives. This metric is inspired by the PQ implementation of panopticapi, a standard implementation for the PQ metric for panoptic segmentation.
- Parameters:
things¶ (
Collection[int]) – Set ofcategory_idfor countable things.stuffs¶ (
Collection[int]) – Set ofcategory_idfor uncountable stuffs.allow_unknown_preds_category¶ (
bool) – 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 – If
things,stuffshave at least one commoncategory_id.TypeError – If
things,stuffscontain non-integercategory_id.
Example
>>> from torch import tensor >>> from torchmetrics.detection import PanopticQuality >>> 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]]]]) >>> panoptic_quality = PanopticQuality(things = {0, 1}, stuffs = {6, 7}) >>> panoptic_quality(preds, target) tensor(0.5463, dtype=torch.float64)
- plot(val=None, ax=None)[source]
Plot a single or multiple values from the metric.
- Parameters:
val¶ (
Union[Tensor,Sequence[Tensor],None]) – 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[Axes]) – An matplotlib axis object. If provided will add plot to that axis
- Return type:
- Returns:
Figure object and Axes object
- Raises:
ModuleNotFoundError – If matplotlib is not installed
>>> from torch import tensor >>> from torchmetrics.detection import PanopticQuality >>> 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 = PanopticQuality(things = {0, 1}, stuffs = {6, 7}) >>> metric.update(preds, target) >>> fig_, ax_ = metric.plot()
>>> # Example plotting multiple values >>> from torch import tensor >>> from torchmetrics.detection import PanopticQuality >>> 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 = PanopticQuality(things = {0, 1}, stuffs = {6, 7}) >>> vals = [] >>> for _ in range(20): ... vals.append(metric(preds, target)) >>> fig_, ax_ = metric.plot(vals)
Functional Interface¶
- torchmetrics.functional.detection.panoptic_quality(preds, target, things, stuffs, allow_unknown_preds_category=False)[source]
Compute Panoptic Quality for panoptic segmentations.

where IOU, TP, FP and FN are respectively the sum of the intersection over union for true positives, the number of true postitives, false positives and false negatives. This metric is inspired by the PQ implementation of panopticapi, a standard implementation for the PQ metric for object detection.
- Parameters:
preds¶ (
Tensor) – 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) – 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[int]) – Set ofcategory_idfor countable things.stuffs¶ (
Collection[int]) – Set ofcategory_idfor uncountable stuffs.allow_unknown_preds_category¶ (
bool) – 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 – If
things,stuffshave at least one commoncategory_id.TypeError – If
things,stuffscontain non-integercategory_id.TypeError – If
predsortargetis not antorch.Tensor.ValueError – If
predsortargethas different shape.ValueError – If
predshas less than 3 dimensions.ValueError – If the final dimension of
predshas size != 2.
- Return type:
Example
>>> from torch import tensor >>> 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]]]]) >>> panoptic_quality(preds, target, things = {0, 1}, stuffs = {6, 7}) tensor(0.5463, dtype=torch.float64)