---
title: CLIP Image Quality Assessment (CLIP-IQA)
description: 'Calculates CLIP-IQA, that can be used to measure the visual content of images.'
canonical: 'https://lightning.ai/docs/torchmetrics/stable/multimodal/clip_iqa'
---
# CLIP Image Quality Assessment (CLIP-IQA) {#clip-image-quality-assessment-clip-iqa}

## Module Interface {#module-interface}

### `class torchmetrics.multimodal.CLIPImageQualityAssessment(model_name_or_path='clip_iqa', data_range=1.0, prompts=('quality',), **kwargs)` {#class-torchmetrics-multimodal-clipimagequalityassessment-model-name-or-path-clip-iqa-data-range-1-0-prompts-quality-kwargs}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/multimodal/clip_iqa.py#L57-L261)

Calculates [CLIP-IQA](https://arxiv.org/abs/2207.12396), that can be used to measure the visual content of images.

The metric is based on the [CLIP](https://arxiv.org/abs/2103.00020) model, which is a neural network trained on a variety of (image, text) pairs to be able to generate a vector representation of the image and the text that is similar if the image and text are semantically similar.

The metric works by calculating the cosine similarity between user provided images and pre-defined prompts. The prompts always comes in pairs of “positive” and “negative” such as “Good photo.” and “Bad photo.”. By calculating the similartity between image embeddings and both the “positive” and “negative” prompt, the metric can determine which prompt the image is more similar to. The metric then returns the probability that the image is more similar to the first prompt than the second prompt.

Build in prompts are:

*   quality: “Good photo.” vs “Bad photo.”
    
*   brightness: “Bright photo.” vs “Dark photo.”
    
*   noisiness: “Clean photo.” vs “Noisy photo.”
    
*   colorfullness: “Colorful photo.” vs “Dull photo.”
    
*   sharpness: “Sharp photo.” vs “Blurry photo.”
    
*   contrast: “High contrast photo.” vs “Low contrast photo.”
    
*   complexity: “Complex photo.” vs “Simple photo.”
    
*   natural: “Natural photo.” vs “Synthetic photo.”
    
*   happy: “Happy photo.” vs “Sad photo.”
    
*   scary: “Scary photo.” vs “Peaceful photo.”
    
*   new: “New photo.” vs “Old photo.”
    
*   warm: “Warm photo.” vs “Cold photo.”
    
*   real: “Real photo.” vs “Abstract photo.”
    
*   beautiful: “Beautiful photo.” vs “Ugly photo.”
    
*   lonely: “Lonely photo.” vs “Sociable photo.”
    
*   relaxing: “Relaxing photo.” vs “Stressful photo.”
    

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

*   `images` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): tensor with images feed to the feature extractor with shape `(N,C,H,W)`
    

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

*   `clip_iqa` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)") or dict of tensors): tensor with the CLIP-IQA score. If a single prompt is provided, a single tensor with shape `(N,)` is returned. If a list of prompts is provided, a dict of tensors is returned with the prompt as key and the tensor with shape `(N,)` as value.
    

Parameters:

*   **model\_name\_or\_path** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'clip_iqa'`, `'openai/clip-vit-base-patch16'`, `'openai/clip-vit-base-patch32'`, `'openai/clip-vit-large-patch14-336'`, `'openai/clip-vit-large-patch14'`\]) –
    
    string indicating the version of the CLIP model to use. Available models are:
    
    *   ”clip\_iqa”, model corresponding to the CLIP-IQA paper.
        
    *   ”openai/clip-vit-base-patch16”
        
    *   ”openai/clip-vit-base-patch32”
        
    *   ”openai/clip-vit-large-patch14-336”
        
    *   ”openai/clip-vit-large-patch14”
        
    
*   **data\_range** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – The maximum value of the input tensor. For example, if the input images are in range \[0, 255\], data\_range should be 255. The images are normalized by this value.
    
*   **prompts** ([`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")\]\], [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis "(in Python v3.15)")\]) – A string, tuple of strings or nested tuple of strings. If a single string is provided, it must be one of the available prompts (see above). Else the input is expected to be a tuple, where each element can be one of two things: either a string or a tuple of strings. If a string is provided, it must be one of the available prompts (see above). If tuple is provided, it must be of length 2 and the first string must be a positive prompt and the second string must be a negative prompt.
    
*   **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.
    

Hint

If using the default clip\_iqa model, the package piq must be installed. Either install with pip install piq or pip install torchmetrics\[image\].

Raises:

*   [**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If transformers package is not installed or version is lower than 4.10.0
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If prompts is a tuple and it is not of length 2
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If prompts is a string and it is not one of the available prompts
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If prompts is a list of strings and not all strings are one of the available prompts
    

Example::

Single prompt:

```python
>>> from torch import randint
>>> from torchmetrics.multimodal import CLIPImageQualityAssessment
>>> imgs = randint(255, (2, 3, 224, 224)).float()
>>> metric = CLIPImageQualityAssessment()
>>> metric(imgs)
tensor([0.8894, 0.8902])
```

Example::

Multiple prompts:

```python
>>> from torch import randint
>>> from torchmetrics.multimodal import CLIPImageQualityAssessment
>>> imgs = randint(255, (2, 3, 224, 224)).float()
>>> metric = CLIPImageQualityAssessment(prompts=("quality", "brightness"))
>>> metric(imgs)
{'quality': tensor([0.8693, 0.8705]), 'brightness': tensor([0.5722, 0.4762])}
```

Example::

Custom prompts. Must always be a tuple of length 2, with a positive and negative prompt.

```python
>>> from torch import randint
>>> from torchmetrics.multimodal import CLIPImageQualityAssessment
>>> imgs = randint(255, (2, 3, 224, 224)).float()
>>> metric = CLIPImageQualityAssessment(prompts=(("Super good photo.", "Super bad photo."), "brightness"))
>>> metric(imgs)
{'user_defined_0': tensor([0.9578, 0.9654]), 'brightness': tensor([0.5495, 0.5764])}
```

#### `plot(val=None, ax=None)` {#plot-val-none-ax-none}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/multimodal/clip_iqa.py#L223-L261)

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.multimodal.clip_iqa import CLIPImageQualityAssessment
>>> metric = CLIPImageQualityAssessment()
>>> metric.update(torch.rand(1, 3, 224, 224))
>>> fig_, ax_ = metric.plot()
```

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

```python
>>> # Example plotting multiple values
>>> import torch
>>> from torchmetrics.multimodal.clip_iqa import CLIPImageQualityAssessment
>>> metric = CLIPImageQualityAssessment()
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(torch.rand(1, 3, 224, 224)))
>>> fig_, ax_ = metric.plot(values)
```

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

## Functional Interface {#functional-interface}

### `torchmetrics.functional.multimodal.clip_image_quality_assessment(images, model_name_or_path='clip_iqa', data_range=1.0, prompts=('quality',))` {#torchmetrics-functional-multimodal-clip-image-quality-assessment-images-model-name-or-path-clip-iqa-data-range-1-0-prompts-quality}

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

Calculates [CLIP-IQA](https://arxiv.org/abs/2207.12396), that can be used to measure the visual content of images.

The metric is based on the [CLIP](https://arxiv.org/abs/2103.00020) model, which is a neural network trained on a variety of (image, text) pairs to be able to generate a vector representation of the image and the text that is similar if the image and text are semantically similar.

The metric works by calculating the cosine similarity between user provided images and pre-defined prompts. The prompts always come in pairs of “positive” and “negative” such as “Good photo.” and “Bad photo.”. By calculating the similartity between image embeddings and both the “positive” and “negative” prompt, the metric can determine which prompt the image is more similar to. The metric then returns the probability that the image is more similar to the first prompt than the second prompt.

Build in prompts are:

*   quality: “Good photo.” vs “Bad photo.”
    
*   brightness: “Bright photo.” vs “Dark photo.”
    
*   noisiness: “Clean photo.” vs “Noisy photo.”
    
*   colorfullness: “Colorful photo.” vs “Dull photo.”
    
*   sharpness: “Sharp photo.” vs “Blurry photo.”
    
*   contrast: “High contrast photo.” vs “Low contrast photo.”
    
*   complexity: “Complex photo.” vs “Simple photo.”
    
*   natural: “Natural photo.” vs “Synthetic photo.”
    
*   happy: “Happy photo.” vs “Sad photo.”
    
*   scary: “Scary photo.” vs “Peaceful photo.”
    
*   new: “New photo.” vs “Old photo.”
    
*   warm: “Warm photo.” vs “Cold photo.”
    
*   real: “Real photo.” vs “Abstract photo.”
    
*   beautiful: “Beautiful photo.” vs “Ugly photo.”
    
*   lonely: “Lonely photo.” vs “Sociable photo.”
    
*   relaxing: “Relaxing photo.” vs “Stressful photo.”
    

Parameters:

*   **images** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Either a single `[N, C, H, W]` tensor or a list of `[C, H, W]` tensors
    
*   **model\_name\_or\_path** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'clip_iqa'`, `'openai/clip-vit-base-patch16'`, `'openai/clip-vit-base-patch32'`, `'openai/clip-vit-large-patch14-336'`, `'openai/clip-vit-large-patch14'`\]) – string indicating the version of the CLIP model to use. By default this argument is set to `clip_iqa` which corresponds to the model used in the original paper. Other available models are “openai/clip-vit-base-patch16”, “openai/clip-vit-base-patch32”, “openai/clip-vit-large-patch14-336” and “openai/clip-vit-large-patch14”
    
*   **data\_range** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – The maximum value of the input tensor. For example, if the input images are in range \[0, 255\], data\_range should be 255. The images are normalized by this value.
    
*   **prompts** ([`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")\]\], [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis "(in Python v3.15)")\]) – A string, tuple of strings or nested tuple of strings. If a single string is provided, it must be one of the available prompts (see above). Else the input is expected to be a tuple, where each element can be one of two things: either a string or a tuple of strings. If a string is provided, it must be one of the available prompts (see above). If tuple is provided, it must be of length 2 and the first string must be a positive prompt and the second string must be a negative prompt.
    

Hint

If using the default clip\_iqa model, the package piq must be installed. Either install with pip install piq or pip install torchmetrics\[multimodal\].

Return type:

`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`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)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]\]

Returns:

A tensor of shape `(N,)` if a single prompts is provided. If a list of prompts is provided, a dictionary of with the prompts as keys and tensors of shape `(N,)` as values.

Raises:

*   [**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If transformers package is not installed or version is lower than 4.10.0
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If not all images have format \[C, H, W\]
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If prompts is a tuple and it is not of length 2
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If prompts is a string and it is not one of the available prompts
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If prompts is a list of strings and not all strings are one of the available prompts
    

Example::

Single prompt:

```python
>>> from torch import randint
>>> from torchmetrics.functional.multimodal import clip_image_quality_assessment
>>> imgs = randint(255, (2, 3, 224, 224)).float()
>>> clip_image_quality_assessment(imgs, prompts=("quality",))
tensor([0.8894, 0.8902])
```

Example::

Multiple prompts:

```python
>>> from torch import randint
>>> from torchmetrics.functional.multimodal import clip_image_quality_assessment
>>> imgs = randint(255, (2, 3, 224, 224)).float()
>>> clip_image_quality_assessment(imgs, prompts=("quality", "brightness"))
{'quality': tensor([0.8693, 0.8705]), 'brightness': tensor([0.5722, 0.4762])}
```

Example::

Custom prompts. Must always be a tuple of length 2, with a positive and negative prompt.

```python
>>> from torch import rand
>>> from torchmetrics.functional.multimodal import clip_image_quality_assessment
>>> imgs = randint(255, (2, 3, 224, 224)).float()
>>> clip_image_quality_assessment(imgs, prompts=(("Super good photo.", "Super bad photo."), "brightness"))
{'user_defined_0': tensor([0.9578, 0.9654]), 'brightness': tensor([0.5495, 0.5764])}
```

---

**Navigation**

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