Profile
Back to NewsBack
GitHub Trending 12 min
Reader Mode
chaofengc/IQA-PyTorch: 🔎 🖼️ 🔥PyTorch Toolbox for Image Quality Assessment, including PSNR, SSIM, LPIPS, FID, NIQE, NRQM(Ma), MUSIQ, TOPIQ, NIMA, DBCNN, BRISQUE, PI and more...

chaofengc/IQA-PyTorch: 🔎 🖼️ 🔥PyTorch Toolbox for Image Quality Assessment, including PSNR, SSIM, LPIPS, FID, NIQE, NRQM(Ma), MUSIQ, TOPIQ, NIMA, DBCNN, BRISQUE, PI and more...

20 hours ago

An Image Quality Assessment (IQA) toolbox with pure python and pytorch.

🚀 Install with pip install pyiqa

google colab logo PyPI</a> Downloads</a> Documentation Status</a> Awesome</a> Citation</a> Zhihu</a>

:open_book: Introduction

This is a comprehensive image quality assessment (IQA) toolbox built with pure Python and PyTorch. We provide reimplementation of many widely used full reference (FR) and no reference (NR) metrics, with results calibrated against official MATLAB scripts when available. With GPU acceleration, our implementations are much faster than their Matlab counterparts. Please refer to the following documents for details:

[!TIP]
- If you cannot access Hugging Face, try the mirror site hf-mirror.com to download datasets and models.
- 无法访问 Hugging Face 时,可尝试使用镜像网站 hf-mirror.com 下载数据集和模型权重。设置环境变量export HF_ENDPOINT=https://hf-mirror.com。
- The default model cache directory is ~/.cache/torch/hub/pyiqa/.

:triangular_flag_on_post: Updates/Changelog

  • 🆕Jun, 2026. Add qrealign (Q-ReAlign), a modern Q-Align visual scorer on a Qwen3.5-VL backbone, with three sizes qrealign-mini (0.8B) / qrealign-lite (4B) / qrealign-pro (9B). Requires transformers>=5.0. See Q-ReAlign.
  • 🆕May, 2026. Add fgresq metric from FGResQ. Thanks to their great work 🤗, and see the paper for details.
  • 👉Dec, 2025.Add FR-IQA method dmm proposed in paper, with SVD-based debiased mapping to mitigate perception bias. Thanks to baoliang for their great work 🤗, refer to DMM for more details.
  • ✨Dec, 2025. Add maclip metric proposed in MACLIP, introducing magnitude in IQA. Thanks to zhicheng for their contribution 🤗, and please refer to their official papers for more details!
  • 🎉Sep, 2025. Add afine metric proposed in AFINE. Thanks to Du CHEN for their great work 🤗, and please refer to their official papers for more details!
  • 🎉Jun, 2025. Add sfid, a commonly used metric in generative models.
  • 🎆Jan, 2025. Add qualiclip, qualiclip+ and its variances trained on different datasets, refer to official repo here. Thanks for the contribution from Lorenzo Agnolucci 🤗.
  • More

:zap: Quick Start

Installation

# Install with pip
pip install pyiqa

Install faster with uv

pip install uv uv pip install pyiqa

Install latest github version

pip uninstall pyiqa # if have older version installed already pip install git+https://github.com/chaofengc/IQA-PyTorch.git

Install with git clone

git clone https://github.com/chaofengc/IQA-PyTorch.git cd IQA-PyTorch pip install -e .

Basic Usage

You can simply use the package with commandline interface.

# list all available metrics
pyiqa -ls

test with default settings

pyiqa [metric_name(s)] -t [image_path or dir] -r [image_path or dir] --device [cuda or cpu] --verbose

Advanced Usage with Codes

Test metrics

import pyiqa
import torch

list all available metrics

print(pyiqa.list_models())

device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")

create metric with default setting

iqa_metric = pyiqa.create_metric('lpips', device=device)

check if lower better or higher better

print(iqa_metric.lower_better)

example for iqa score inference

Tensor inputs, img_tensor_x/y: (N, 3, H, W), RGB, 0 ~ 1

score_fr = iqa_metric(img_tensor_x, img_tensor_y)

img path as inputs.

score_fr = iqa_metric('./ResultsCalibra/dist_dir/I03.bmp', './ResultsCalibra/ref_dir/I03.bmp')

For FID metric, use directory or precomputed statistics as inputs

refer to clean-fid for more details: https://github.com/GaParmar/clean-fid

fid_metric = pyiqa.create_metric('fid') score = fid_metric('./ResultsCalibra/dist_dir/', './ResultsCalibra/ref_dir') score = fid_metric('./ResultsCalibra/dist_dir/', dataset_name="FFHQ", dataset_res=1024, dataset_split="trainval70k")

Use as loss functions

Note that gradient propagation is disabled by default. Set as_loss=True to enable it as a loss function. Not all metrics support backpropagation, please refer to Model Cards and be sure that you are using it in a lower_better way.

lpips_loss = pyiqa.create_metric('lpips', device=device, as_loss=True)

ssim_loss = pyiqa.create_metric('ssimc', device=device, as_loss=True) loss = 1 - ssim_loss(img_tensor_x, img_tensor_y) # ssim is not lower better

Use custom settings and weights

We also provide a flexible way to use custom settings and weights in case you want to retrain or fine-tune the models.

iqa_metric = pyiqa.create_metric('topiq_nr', device=device, **custom_opts)

Note that if you train the model with this package, the weights will be saved in weight_dict['params']. Otherwise, please set weight_keys=None.

iqa_metric.load_weights('path/to/weights.pth', weight_keys='params')

Example test script

Example test script with input directory/images and reference directory/images.

# example for FR metric with dirs
python inference_iqa.py -m LPIPS[or lpips] -t ./ResultsCalibra/dist_dir[dist_img] -r ./ResultsCalibra/ref_dir[ref_img]

example for NR metric with single image

python inference_iqa.py -m brisque -t ./ResultsCalibra/dist_dir/I03.bmp

Candidate-pool gMAD-style testing

pyiqa-gmad is a standalone candidate-pool helper that uses two non-reference metrics to find pairs where one metric gives similar scores while the other metric differs. See the gMAD documentation for input formats, score direction, output interpretation, and limitations. It is not a replacement for the official gMAD evaluation protocol.

pyiqa-gmad ./candidate_images \
  --metric-a musiq \
  --metric-b brisque \
  --tie-tolerance 0.1 \
  --device cuda \
  --output gmad_results.json

The directory is searched recursively. Scores are standardized within the candidate pool, with lower_better metrics sign-corrected before comparison. The tie tolerance is measured in standardized-score units. Results contain one most-differentiating pair for each direction, or null if no pair meets the tie constraint. Install pyiqa with pip install -e . to register the command.

To reuse precomputed scores, provide a CSV with an image column and one column for each metric. Relative image paths are resolved from the CSV's directory by default; use --image-root to choose a different root.

image,musiq,brisque
images/sample1.png,62.4,28.1
images/sample2.png,48.7,39.5
pyiqa-gmad --scores-csv scores.csv \
  --metric-a musiq \
  --metric-b brisque \
  --tie-tolerance 0.1

For metric names not known to pyiqa, specify score direction with --direction-a lower|higher and --direction-b lower|higher. Known pyiqa metric directions are inferred automatically.

Easy load of popular datasets

We offer an easy way to load popular IQA datasets through the configuration file pyiqa/default_dataset_configs.yml. The specified datasets will automatically download from the huggingface IQA-PyTorch-Dataset. See example code below: ``python from pyiqa import get_dataset_info, load_dataset

list all available datasets

print(get_dataset_info().keys())

load dataset with default options and official split

dataset = load_dataset('koniq10k', data_root='./datasets', force_download=False, split_index='official_split', phase='test') print(f'Loaded dataset, len={len(dataset)}, {dataset[0].keys()}') print(dataset[0]['img'].shape)

split_ratio: train/test/val

dataset = load_dataset('csiq', data_root='./datasets', force_download=False, split_index=1, split_ratio='622', phase='test') print(f'Loaded dataset, len={len(dataset)}, {dataset[0].keys()}') print(dataset[0]['img'].shape)

or use dataset options

dataset_opts = { 'split_index': 1, 'split_ratio': '622', 'phase': 'test', 'augment': { 'resize': 256, 'center_crop': 224, } } dataset = load_dataset('csiq', data_root='./datasets', force_download=False, dataset_opts=dataset_opts) print(f'Loaded dataset, len={len(dataset)}, {dataset[0].keys()}') print(dataset[0]['img'].shape)
Please refer to Dataset Cards for more details about the dataset_opts.

:1st_place_medal: Benchmark Performances and Model Zoo

Results Calibration

Please refer to the results calibration to verify the correctness of the python implementations compared with official scripts in matlab or python.

⏬ Download Benchmark Datasets

For convenience, we upload all related datasets to huggingface IQA-Toolbox-Dataset, and corresponding meta information files to huggingface IQA-Toolbox-Dataset-metainfo. Here are example codes to download them from huggingface:

>[!CAUTION] > we only collect the datasets for academic, research, and educational purposes. It is important for the users to adhere to the usage guidelines, licensing terms, and conditions set forth by the original creators or owners of each dataset.

python import os from huggingface_hub import snapshot_download

save_dir = './datasets' os.makedirs(save_dir, exist_ok=True)

filename = "koniq10k.tgz" snapshot_download("chaofengc/IQA-Toolbox-Datasets", repo_type="dataset", local_dir=save_dir, allow_patterns=filename, local_dir_use_symlinks=False)

os.system(f"tar -xzvf {save_dir}/{filename} -C {save_dir}")

Download meta information from Huggingface with git clone or update with git pull:
cd ./datasets git clone https://huggingface.co/datasets/chaofengc/IQA-Toolbox-Datasets-metainfo meta_info

cd ./datasets/meta_info git pull

Examples to specific dataset options can be found in ./pyiqa/default_dataset_configs.yml. Details of the dataloader interface and meta information files can be found in Dataset Preparation

Performance Evaluation Protocol

We use official models for evaluation if available. Otherwise, we use the following settings to train and evaluate different models for simplicity and consistency:

| Metric Type | Train | Test | Results | | ------------- | --------- | ------------------------------------------ | -------------------------------------------------------- | | FR | KADID-10k | CSIQ, LIVE, TID2008, TID2013 | FR benchmark | | NR | KonIQ-10k | LIVEC, KonIQ-10k (official split), TID2013, SPAQ | NR benchmark | | Aesthetic IQA | AVA | AVA (official split) | IAA benchmark | | Face IQA | CGFIQA | CGFIQA (official split) | Face IQA benchmark | | Efficiency | CPU/GPU Time, GPU Memory | Average on $1080\times800$ image inputs | Efficiency benchmark |

Results are calculated with:

  • PLCC without any correction. Although test time value correction is common in IQA papers, we want to use the original value in our benchmark.
  • Full image single input. We do not use multi-patch testing unless necessary.
Basically, we use the largest existing datasets for training, and cross dataset evaluation performance for fair comparison. The following models do not provide official weights, and are retrained by our scripts:

| Metric Type | Reproduced Models | | ------------- | ----------------------------- | | FR | wadiqam_fr | | NR | cnniqa, dbcnn, hyperiqa, metaiqa, wadiqam_nr | | Aesthetic IQA | nima, nima-vgg16-ava |

>[!NOTE] >- Due to optimized training process, performance of some retrained approaches may be different with original paper. >- Results of all retrained models by ours are normalized to [0, 1] and change to higher better for convenience. >- Results of KonIQ-10k, AVA are both tested with official split. >- NIMA is only applicable to AVA dataset now. We use inception_resnet_v2 for default nima. >- MUSIQ is not included in the IAA benchmark because we do not have train/split information of the official model.

Benchmark Performance with Provided Script

Here is an example script to get performance benchmark on different datasets:

bash

NOTE: this script will test ALL specified metrics on ALL specified datasets

Test default metrics on default datasets

python benchmark_results.py -m psnr ssim -d csiq tid2013 tid2008

Test with your own options

python benchmark_results.py -m psnr --data_opt options/example_benchmark_data_opts.yml

python benchmark_results.py --metric_opt options/example_benchmark_metric_opts.yml tid2013 tid2008

python benchmark_results.py --metric_opt options/example_benchmark_metric_opts.yml --data_opt options/example_benchmark_data_opts.yml

## :hammer_and_wrench: Train

Example Train Script

Example to train DBCNN on LIVEChallenge dataset

bash

train for single experiment

python pyiqa/train.py -opt options/train/DBCNN/train_DBCNN.yml

train N splits for small datasets

python pyiqa/train_nsplits.py -opt options/train/DBCNN/train_DBCNN.yml
Example for distributed training
bash torchrun --nproc_per_node=2 --master_port=4321 pyiqa/train.py -opt options/train/CLIPIQA/train_CLIPIQA_koniq10k.yml --launcher pytorch
## :electric_plug: Plugin Authoring (Experimental)

You can add custom datasets/architectures/models/losses/metrics from an external package via Python entry points.

1) Add entry points in your plugin pyproject.toml

toml [project] name = "my-pyiqa-plugin" version = "0.1.0" dependencies = ["pyiqa>=0.1"]

[project.entry-points."pyiqa.models"] my_models = "my_pyiqa_plugin.register:register_models"

[project.entry-points."pyiqa.archs"] my_archs = "my_pyiqa_plugin.register:register_archs"

[project.entry-points."pyiqa.datasets"] my_datasets = "my_pyiqa_plugin.register:register_datasets"

[project.entry-points."pyiqa.losses"] my_losses = "my_pyiqa_plugin.register:register_losses"

[project.entry-points."pyiqa.metrics"] my_metrics = "my_pyiqa_plugin.register:register_metrics"

### 2) Minimal registration function
python

my_pyiqa_plugin/register.py

from pyiqa.utils.registry import MODEL_REGISTRY

def register_models(): from .my_model import MyModel

# Registers with key "MyModel" by default. MODEL_REGISTRY.register(MyModel)

After installing your plugin package, PyIQA will discover and load these entry points lazily when a registry is queried.

:beers: Contribution

Any contributions to this repository are greatly appreciated. Please follow the contribution instructions for contribution guidance.

:scroll: License

This work is licensed under the PolyForm Noncommercial License 1.0.0 (see LICENSE) and the NTU S-Lab License for applicable components.

:bookmark_tabs: Citation

If you find our codes helpful to your research, please consider to use the following citation:

bib @misc{pyiqa, title={{IQA-PyTorch}: PyTorch Toolbox for Image Quality Assessment}, author={Chaofeng Chen and Jiadi Mo}, year={2022}, howpublished = "[Online]. Available: \url{https://github.com/chaofengc/IQA-PyTorch}" }
Please also consider to cite our works on image quality assessment if it is useful to you:
bib @article{chen2024topiq, author={Chen, Chaofeng and Mo, Jiadi and Hou, Jingwen and Wu, Haoning and Liao, Liang and Sun, Wenxiu and Yan, Qiong and Lin, Weisi}, title={TOPIQ: A Top-Down Approach From Semantics to Distortions for Image Quality Assessment}, journal={IEEE Transactions on Image Processing}, year={2024}, volume={33}, pages={2404-2418}, doi={10.1109/TIP.2024.3378466} }
`
@article{wu2024qalign,
  title={Q-Align: Teaching LMMs for Visual Scoring via Discrete Text-Defined Levels},
  author={Wu, Haoning and Zhang, Zicheng and Zhang, Weixia and Chen, Chaofeng and Li, Chunyi and Liao, Liang and Wang, Annan and Zhang, Erli and Sun, Wenxiu and Yan, Qiong and Min, Xiongkuo and Zhai, Guangtai and Lin, Weisi},
  journal={International Conference on Machine Learning (ICML)},
  year={2024},
  institution={Nanyang Technological University and Shanghai Jiao Tong University and Sensetime Research},
  note={Equal Contribution by Wu, Haoning and Zhang, Zicheng. Project Lead by Wu, Haoning. Corresponding Authors: Zhai, Guangtai and Lin, Weisi.}
}

:heart: Acknowledgement

The code architecture is borrowed from BasicSR. Several implementations are taken from: IQA-optimization, Image-Quality-Assessment-Toolbox, piq, piqa, clean-fid

We also thanks the following public repositories: MUSIQ, DBCNN, NIMA, HyperIQA, CNNIQA, WaDIQaM, PieAPP, paq2piq, MANIQA , MetaIQA

:e-mail: Contact

If you have any questions, please email [email protected]`

Chat with me