圖像質量評估的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]