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...

IQA-PyTorch: A Toolbox for Image Quality Assessment

What it is: IQA-PyTorch is a Python library that helps you measure the visual quality of images. It's built on PyTorch and provides many standard quality metrics, both for comparing a distorted image to a reference (full-reference) and for assessing quality without any reference (no-reference). The implementations are designed to match official MATLAB results while running much faster on GPUs.

Key features:

  • Wide range of metrics: Includes popular metrics like LPIPS, SSIM, BRISQUE, and many others. The README lists recent additions such as jld, qrealign, fgresq, dmm, maclip, afine, sfid, and qualiclip.
  • Easy to install and use: Install with pip install pyiqa. You can use it from the command line or via Python code.
  • Flexible usage: Use metrics for scoring, as loss functions in training, or with custom model weights.
  • Dataset support: Provides simple loading of common IQA datasets (like KonIQ-10k, CSIQ) with automatic download from Hugging Face.
  • Benchmarking: Includes scripts to evaluate metrics on standard datasets and compare performance.
  • Training support: Offers training scripts for models like DBCNN, including distributed training.
  • Plugin system: Allows you to add your own custom metrics, datasets, or models via Python entry points.

Installation:

pip install pyiqa

Or install the latest GitHub version:

pip install git+https://github.com/chaofengc/IQA-PyTorch.git

Basic usage (command line):

  • List all available metrics: pyiqa -ls
  • Test a metric on an image: pyiqa [metric_name] -t [image_path] -r [reference_path] (for full-reference) or without -r for no-reference.

Basic usage (Python):

import pyiqa
import torch

# List all models
print(pyiqa.list_models())

# Create a metric (e.g., LPIPS)
iqa_metric = pyiqa.create_metric('lpips', device='cuda')

# Check if lower is better
print(iqa_metric.lower_better)

# Score an image pair (tensors or file paths)
score = iqa_metric(img_tensor_x, img_tensor_y)

Using metrics as loss functions: Set as_loss=True when creating the metric to enable gradient propagation. For example:

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

Loading datasets:

from pyiqa import load_dataset
dataset = load_dataset('koniq10k', data_root='./datasets', split_index='official_split', phase='test')

Benchmarking: Run python benchmark_results.py -m psnr ssim -d csiq tid2013 to test metrics on datasets.

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

Plugin authoring: You can extend pyiqa by adding your own models, datasets, etc., through Python entry points defined in your package's pyproject.toml.

License: This project is licensed under the PolyForm Noncommercial License 1.0.0 and the NTU S-Lab License. It is for non-commercial use.

More information:

Note: This explainer is based solely on the README content provided.

Related

  • Project
  • Project
  • Project
  • Project
  • Project