Package: piq
PyTorch Image Quality (PIQ) is not endorsed by Facebook, Inc.;PyTorch, the PyTorch logo and any related marks are trademarks of Facebook, Inc.PyTorch Image Quality (PIQ)is a collection of measures and metrics for
image quality assessment. PIQ helps you to concentrate on your experiments without the boilerplate code.
The library contains a set of measures and metrics that is continually getting extended.
For measures/metrics that can be used as loss functions, corresponding PyTorch modules are implemented.We provide:Unified interface, which is easy to use and extend.Written on pure PyTorch with bare minima of additional dependencies.Extensive user input validation. Your code will not crash in the middle of the training.Fast (GPU computations available) and reliable.Most metrics can be backpropagated for model optimization.Supports python 3.7-3.10.PIQ was initially namedPhotoSynthesis.Metrics.InstallationPyTorch Image Quality (PIQ)can be installed usingpip,condaorgit.If you usepip, you can install it with:$pipinstallpiqIf you useconda, you can install it with:$condainstallpiq-cphotosynthesis-team-cconda-forge-cPyTorchIf you want to use the latest features straight from the master, clonePIQ repo:gitclonehttps://github.com/photosynthesis-team/piq.gitcdpiqpythonsetup.pyinstallDocumentationThe full documentation is available athttps://piq.readthedocs.io.Usage ExamplesImage-Based metricsThe group of metrics (such as PSNR, SSIM, BRISQUE) takes an image or a pair of images as input to compute a distance between them.
We have a functional interface, which returns a metric value, and a class interface, which allows to use any metric
as a loss function.importtorchfrompiqimportssim,SSIMLossx=torch.rand(4,3,256,256,requires_grad=True)y=torch.rand(4,3,256,256)ssim_index:torch.Tensor=ssim(x,y,data_range=1.)loss=SSIMLoss(data_range=1.)output:torch.Tensor=loss(x,y)output.backward()For a full list of examples, seeimage metricsexamples.Distribution-Based metricsThe group of metrics (such as IS, FID, KID) takes a list of image features to compute the distance between distributions.
Image features can be extracted by some feature extractor network separately or by using thecompute_featsmethod of a
class.Note:compute_featsconsumes a data loader of a predefined format.importtorchfromtorch.utils.dataimportDataLoaderfrompiqimportFIDfirst_dl,second_dl=DataLoader(),DataLoader()fid_metric=FID()first_feats=fid_metric.compute_feats(first_dl)second_feats=fid_metric.compute_feats(second_dl)fid:torch.Tensor=fid_metric(first_feats,second_feats)If you already have image features, use the class interface for score computation:importtorchfrompiqimportFIDx_feats=torch.rand(10000,1024)y_feats=torch.rand(10000,1024)msid_metric=MSID()msid:torch.Tensor=msid_metric(x_feats,y_feats)For a full list of examples, seefeature metricsexamples.List of metricsFull-Reference (FR)AcronymYearMetricPSNR-Peak Signal-to-Noise RatioSSIM2003Structural SimilarityMS-SSIM2004Multi-Scale Structural SimilarityIW-SSIM2011Information Content Weighted Structural Similarity IndexVIFp2004Visual Information FidelityFSIM2011Feature Similarity Index MeasureSR-SIM2012Spectral Residual Based SimilarityGMSD2013Gradient Magnitude Similarity DeviationMS-GMSD2017Multi-Scale Gradient Magnitude Similarity DeviationVSI2014Visual Saliency-induced IndexDSS2015DCT Subband Similarity Index-2016Content Score-2016Style ScoreHaarPSI2016Haar Perceptual Similarity IndexMDSI2016Mean Deviation Similarity IndexLPIPS2018Learned Perceptual Image Patch SimilarityPieAPP2018Perceptual Image-Error Assessment through Pairwise PreferenceDISTS2020Deep Image Structure and Texture SimilarityNo-Reference (NR)AcronymYearMetricTV1937Total VariationBRISQUE2012Blind/Referenceless Image Spatial Quality EvaluatorCLIP-IQA2022CLIP-IQADistribution-Based (DB)AcronymYearMetricIS2016Inception ScoreFID2017Frechet Inception DistanceGS2018Geometry ScoreKID2018Kernel Inception DistanceMSID2019Multi-Scale Intrinsic DistancePR2019Improved Precision and RecallBenchmarkAs part of our library we providecode to benchmarkall metrics on a set of common Mean Opinon Scores databases.
Currently we support several Full-Reference (TID2013,KADID10kandPIPAL) and No-Reference (KonIQ10kandLIVE-itW) datasets.
You need to download them separately and provide path to images as an argument to the script.Here is an example how to evaluate SSIM and MS-SSIM metrics on TID2013 dataset:python3tests/results_benchmark.py--datasettid2013--metricsSSIMMS-SSIM--path~/datasets/tid2013--batch_size16Below we provide a comparison betweenSpearman’s Rank Correlation Coefficient(SRCC) values obtained with PIQ and reported in surveys.
Closer SRCC values indicate the higher degree of agreement between results of computations on given datasets.
We do not reportKendall rank correlation coefficient(KRCC)
as it is highly correlated with SRCC and provides limited additional information.
We do not reportPearson linear correlation coefficient(PLCC)
as it’s highly dependent on fitting method and is biased towards simple examples.For metrics that can take greyscale or colour images,cmeans chromatic version.Full-Reference (FR) DatasetsTID2013KADID10kPIPALSourcePIQ / ReferencePIQ / ReferencePIQ / ReferencePSNR0.69 / 0.69TID20130.68 / -0.41 / 0.41PIPALSSIM0.72 / 0.64TID20130.72 / 0.72KADID10k0.50 / 0.53PIPALMS-SSIM0.80 / 0.79TID20130.80 / 0.80KADID10k0.55 / 0.46PIPALIW-SSIM0.78 / 0.78Eval20190.85 / 0.85KADID10k0.60 / -VIFp0.61 / 0.61TID20130.65 / 0.65KADID10k0.50 / -FSIM0.80 / 0.80TID20130.83 / 0.83KADID10k0.59 / 0.60PIPALFSIMc0.85 / 0.85TID20130.85 / 0.85KADID10k0.59 / -SR-SIM0.81 / 0.81Eval20190.84 / 0.84KADID10k0.57 / -SR-SIMc0.87 / -0.87 / -0.57 / -GMSD0.80 / 0.80MS-GMSD0.85 / 0.85KADID10k0.58 / -VSI0.90 / 0.90Eval20190.88 / 0.86KADID10k0.54 / -DSS0.79 / 0.79Eval20190.86 / 0.86KADID10k0.63 / -Content0.71 / -0.72 / -0.45 / -Style0.54 / -0.65 / -0.34 / -HaarPSI0.87 / 0.87HaarPSI0.89 / 0.89KADID10k0.59 / -MDSI0.89 / 0.89MDSI0.89 / 0.89KADID10k0.59 / -MS-GMSD0.81 / 0.81MS-GMSD0.85 / -0.59 / -MS-GMSDc0.89 / 0.89MS-GMSD0.87 / -0.59 / -LPIPS-VGG0.67 / 0.67DISTS0.72 / -0.57 / 0.58PIPALPieAPP0.84 / 0.88DISTS0.87 / -0.70 / 0.71PIPALDISTS0.81 / 0.83DISTS0.88 / -0.62 / 0.66PIPALBRISQUE0.37 / 0.84Eval20190.33 / 0.53KADID10k0.21 / -CLIP-IQA0.50 / -0.48 / -0.26 / -IS0.26 / -0.25 / -0.09 / -FID0.67 / -0.66 / -0.18 / -KID0.42 / -0.66 / -0.12 / -MSID0.21 / -0.32 / -0.01 / -GS0.37 / -0.37 / -0.02 / -No-Reference (NR) DatasetsKonIQ10kLIVE-itWSourcePIQ / ReferencePIQ / ReferenceBRISQUE0.22 / -0.31 / -CLIP-IQA0.68 / 0.68CLIP-IQA off0.64 / 0.64CLIP-IQA offUnlike FR and NR IQMs, designed to compute an image-wise distance, the DB metrics compare distributions ofsetsof images.
To address these problems, we adopt a different way of computing the DB IQMs proposed inhttps://arxiv.org/abs/2203.07809.
Instead of extracting features from the whole images, we crop them into overlapping tiles of size96 × 96withstride = 32.
This pre-processing allows us to treat each pair of images as a pair of distributions of tiles, enabling further comparison.
The other stages of computing the DB IQMs are kept intact.AssertionsIn PIQ we use assertions to raise meaningful messages when some component doesn’t receive an input of the expected type.
This makes prototyping and debugging easier, but it might hurt the performance.
To disable all checks, use the Python-Oflag:python-Oyour_script.pyRoadmapSee theopen issuesfor a list of proposed
features and known issues.ContributingIf you would like to help develop this library, you’ll find more information in ourcontribution guide.CitationIf you use PIQ in your project, please, cite it as follows.@misc{kastryulin2022piq,
  title ={PyTorch Image Quality: Metrics for Image Quality Assessment},
  url ={https://arxiv.org/abs/2208.14818},
  author ={Kastryulin, Sergey and Zakirov, Jamil and Prokopenko, Denis and Dylov, Dmitry V.},
  doi ={10.48550/ARXIV.2208.14818},
  publisher ={arXiv},
  year ={2022}}@misc{piq,
  title={{PyTorch Image Quality}: Metrics and Measure for Image Quality Assessment},
  url={https://github.com/photosynthesis-team/piq},
  note={Open-source software available at https://github.com/photosynthesis-team/piq},
  author={Sergey Kastryulin and Dzhamil Zakirov and Denis Prokopenko},
  year={2019}}ContactsSergey Kastryulin-@snk4tr-snk4tr@gmail.comJamil Zakirov-@zakajd-djamilzak@gmail.comDenis Prokopenko-@denproc-d.prokopenko@outlook.com