
該存儲庫為生成模型評估提供了精確,有效且可擴展的實現,包括:
數值精度:與許多其他重新實現不同,由火炬依據匹配的參考實現產生的值,直到浮點的機器精度。這允許使用火炬依據來報告論文中的指標,而不是分散和緩慢的參考實現。閱讀有關數值精度的更多信息
效率:不同指標之間的功能共享節省了重新計算時間,並且額外的緩存級別避免了重新計算功能和統計信息。高效率允許在每個時期結束時在訓練循環中使用火炬保真度。閱讀更多有關效率的信息
可擴展性:由於來自輸入數據,模型和特徵提取器的指標的高模塊化和抽象,超越2D圖像的生成非常容易。例如,一個人可以將InceptionV3特徵提取器交換為接受3D掃描量的一個,例如MRI中使用的量。閱讀有關可擴展性的更多信息
tldr; pytorch的快速可靠的GAN評估
pip install torch-fidelity另請參閱:安裝最新的GitHub代碼
以下是使用火炬依據來評估命令行評估指標的三個示例。查看文檔中的更多示例。
CIFAR-10訓練分裂的成立得分:
> fidelity --gpu 0 --isc --input1 cifar10-train
inception_score_mean: 11.23678
inception_score_std: 0.09514061存儲在~/images/ ::
> fidelity --gpu 0 --isc --input1 ~ /images/在~/generator.onnx和CIFAR-10訓練中存儲的生成模型之間的ISC和PPL的有效計算,以及input1 ,FID,prc,PRC:
> fidelity
--gpu 0
--isc
--fid
--kid
--ppl
--prc
--input1 ~ /generator.onnx
--input1-model-z-type normal
--input1-model-z-size 128
--input1-model-num-samples 50000
--input2 cifar10-train 另請參閱:其他用法示例
在跟踪生成模型在訓練時的性能時,由於長時間的計算時間,每個時期都會昂貴後評估指標。 torch_fidelity通過充分利用緩存來解決此問題,以避免在可能的情況下重新計算常見功能和每次金屬統計。計算50000 32x32生成的圖像和cifar10-train的所有指標在NVIDIA P100 GPU上僅需2分鐘26秒,而使用原始代碼庫,則為10分鐘。因此,在整個訓練週期中計算指標20倍,使整個訓練時間僅一小時。
在下面的示例中,假設使用CIFAR-10的無條件圖像生成設置和生成模型generator採用128維標準的正常噪聲向量。
首先,導入模塊:
import torch_fidelity在時期評估結束時添加以下幾行:
wrapped_generator = torch_fidelity . GenerativeModelModuleWrapper ( generator , 128 , 'normal' , 0 )
metrics_dict = torch_fidelity . calculate_metrics (
input1 = wrapped_generator ,
input2 = 'cifar10-train' ,
cuda = True ,
isc = True ,
fid = True ,
kid = True ,
prc = True ,
verbose = False ,
)帶有計算指標的最終字典可以直接記錄到張板,WandB或控制台:
print ( metrics_dict )輸出:
{
'inception_score_mean' : 11.23678 ,
'inception_score_std' : 0.09514061 ,
'frechet_inception_distance' : 18.12198 ,
'kernel_inception_distance_mean' : 0.01369556 ,
'kernel_inception_distance_std' : 0.001310059
'precision' : 0.51369556 ,
'recall' : 0.501310059
}另請參閱:完整的API參考
有關完整的培訓示例,請參閱sngan_cifar10.py。
示例中固定發電機潛在潛在的演變:

訓練示例產生的發電機檢查點可以在此處下載。
建議除非將上述路徑添加到路徑環境變量,否則獨立的fidelity工具將無法使用。如果修改它是不可取的,則該工具仍然可以通過其完整路徑來調用: <SOMEPATH>/fidelity 。
建議引用來加強依靠火炬保真度的作品中的評估協議。為了確保引用此存儲庫時的可重複性,請使用以下Bibtex:
@misc{obukhov2020torchfidelity,
author={Anton Obukhov and Maximilian Seitzer and Po-Wei Wu and Semen Zhydenko and Jonathan Kyl and Elvis Yu-Jing Lin},
year=2020,
title={High-fidelity performance metrics for generative models in PyTorch},
url={https://github.com/toshas/torch-fidelity},
publisher={Zenodo},
version={v0.3.0},
doi={10.5281/zenodo.4957738},
note={Version: 0.3.0, DOI: 10.5281/zenodo.4957738}
}