图像质量评估的Pytorch工具箱带有纯Python和Pytorch的IQA工具箱。请参阅Awesome-Image质量评估,以进行对IQA方法的全面调查,并为IQA数据集下载链接。
这是一个全面的图像质量评估(IQA)工具箱,该工具箱由纯Python和Pytorch构建。我们提供了许多主流完整参考(FR)的重新实现,并且没有参考(NR)指标(如果存在,则使用官方MATLAB脚本校准结果)。随着GPU加速度,我们的大多数实现都比MATLAB快得多。请参阅以下文件以获取详细信息:
?型号卡| ?️数据集卡| ?数据集下载|文档| ?基准
fid ,将其与fid_metric(..., distance_type='mmd', kernel_type='rbf')请参阅CMMD,以获取更多详细信息。感谢INA的贡献。fid_dinov2 ,有关更多详细信息,请参阅DGM-EVAL。pyiqa.load_dataset ,以轻松加载几个常见数据集。compare2score和deepdc 。感谢Hanwei的出色工作?topiq_nr-face 。感谢他们的工作! ?msswd 。感谢他们的工作! ?qalign和qalign_8bit )外,需要少于6GB的GPU存储器。qalign_4bit和qalign_8bit具有更少的内存要求和类似性能。piqe Metric和niqe_matlab, brisque_matlab (结果已用MATLAB R2021B校准)。lpips+和lpips-vgg+ 。arniqa及其在不同数据集上培训的差异,请参阅此处的官方回购。感谢Lorenzo Agnolucci的贡献。pyiqa命令添加inception_score和控制台入口点。unique ,请参阅此处的官方回购。感谢Weixia Zhang的贡献? # Install with pip
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 -r requirements.txt
python setup.py develop您可以简单地将带有命令行接口的软件包使用。
# 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 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" )请注意,默认情况下禁用梯度传播。设置as_loss=True以启用它为损失函数。并非所有指标都支持反向传播,请参考模型卡,并确保您以lower_better方式使用它。
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 我们还提供了一种灵活的方法,以使用自定义设置和权重,以防您要重新训练或微调型号。
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 for FR metric with dirs
python inference_iqa.py -m LPIPS[or lpips] -i ./ResultsCalibra/dist_dir[dist_img] -r ./ResultsCalibra/ref_dir[ref_img]
# example for NR metric with single image
python inference_iqa.py -m brisque -i ./ResultsCalibra/dist_dir/I03.bmp我们提供了一种简单的方法,可以通过配置文件pyiqa/default_dataset_configs.yml加载流行的IQA数据集。指定的数据集将自动从HuggingFace IQA-Pytorch-Dataset下载。请参阅下面的示例代码:
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 )请参阅数据集卡,以获取有关dataset_opts的更多详细信息。
请参阅结果校准,以验证与Matlab或Python中的官方脚本相比,验证Python实现的正确性。
为了方便起见,我们将所有相关数据集上传到HuggingFace IQA-Toolbox-dataset,并将相应的元信息文件上传到HuggingFace IQA-Toolbox-Dataset-Metainfo中。这是示例代码,可以从huggingface下载它们:
警告
我们仅收集数据集用于学术,研究和教育目的。对于用户而言,重要的是要遵守每个数据集的原始创建者或所有者规定的使用指南,许可条款和条件。
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 } " )通过git clone下载元信息或使用git pull更新:
cd ./datasets
git clone https://huggingface.co/datasets/chaofengc/IQA-Toolbox-Datasets-metainfo meta_info
cd ./datasets/meta_info
git pull
可以在./pyiqa/default_dataset_configs.yml中找到特定数据集选项的示例。可以在数据集准备中找到数据加载程序接口和元信息文件的详细信息
如果可用,我们使用官方模型进行评估。否则,我们使用以下设置来训练和评估不同的模型,以简单和一致性:
| 公制类型 | 火车 | 测试 | 结果 |
|---|---|---|---|
| fr | kadid-10k | CSIQ,LIVE,TID2008,TID2013 | 基准 |
| nr | Koniq-10k | LIVEC,KONIQ-10K(官方拆分),TID2013,SPAQ | NR基准 |
| 美学IQA | ava | AVA(官方分裂) | IAA基准 |
| 面对IQA | CGFIQA | CGFIQA(官方拆分) | 面对IQA基准 |
| 效率 | CPU/GPU时间,GPU内存 | 平均开 | 效率基准 |
结果计算:
基本上,我们使用最大的现有数据集进行培训,并使用交叉数据集评估性能进行公平比较。以下模型不提供官方权重,并且由我们的脚本重新训练:
| 公制类型 | 再现模型 |
|---|---|
| fr | wadiqam_fr |
| nr | cnniqa , dbcnn , hyperiqa , wadiqam_nr |
| 美学IQA | nima , nima-vgg16-ava |
笔记
inception_resnet_v2用于默认nima 。这是一个示例脚本,可以在不同数据集上获得性能基准:
# 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在LiveChallenge数据集上训练DBCNN的示例
# 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分布式培训的示例
torchrun --nproc_per_node=2 --master_port=4321 pyiqa/train.py -opt options/train/CLIPIQA/train_CLIPIQA_koniq10k.yml --launcher pytorch对该存储库的任何贡献都非常感谢。请按照贡献说明进行贡献指导。
这项工作是根据NTU S-LAB许可证和Creative Commons归因于非商业期4.0国际许可证获得许可的。
如果您发现我们的代码对您的研究有帮助,请考虑使用以下引用:
@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} "
}如果对您有用,请考虑一下我们的图像质量评估的作品:
@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. }
}代码体系结构是从Basicsr借来的。从以下几种实现来获取:IQA优化,图像质量评估箱,PIQ,PIQA,CLEAN-FID
我们还要感谢以下公共存储库:Musiq,DBCNN,NIMA,HYPERIQA,CNNIQA,WADIQAM,PIEAPP,PAQ2PIQ,MANIQA
如有任何疑问,请发送电子邮件[email protected]