這是一個Python工具箱,可實現我們論文中描述的方法的培訓和測試:
微調CNN圖像檢索沒有人類註釋,
RadenovićF。 ,Tolias G.,Chum O.,TPAMI 2018 [Arxiv]
CNN圖像檢索從Bow中學習:無監督的微調,並用硬示例學習,
RadenovićF。 ,Tolias G.,Chum O.,ECCV 2016 [Arxiv]
此代碼實施:
為了運行此工具箱,您需要:
導航( cd )到工具箱的根[YOUR_CIRTORCH_ROOT] 。您可以使用pip3 install .如果需要的話。確保安裝了所需的Pytorch和Torchvision軟件包。
示例培訓腳本位於YOUR_CIRTORCH_ROOT/cirtorch/examples/train.py中
python3 -m cirtorch.examples.train [-h] [--training-dataset DATASET] [--no-val]
[--test-datasets DATASETS] [--test-whiten DATASET]
[--test-freq N] [--arch ARCH] [--pool POOL]
[--local-whitening] [--regional] [--whitening]
[--not-pretrained] [--loss LOSS] [--loss-margin LM]
[--image-size N] [--neg-num N] [--query-size N]
[--pool-size N] [--gpu-id N] [--workers N] [--epochs N]
[--batch-size N] [--optimizer OPTIMIZER] [--lr LR]
[--momentum M] [--weight-decay W] [--print-freq N]
[--resume FILENAME]
EXPORT_DIR
有關運行選項的詳細說明:
python3 -m cirtorch.examples.train -h
注意:使用示例腳本時,用於培訓和測試的數據和網絡將自動下載。
示例測試腳本位於YOUR_CIRTORCH_ROOT/cirtorch/examples/test.py中
python3 -m cirtorch.examples.test [-h] (--network-path NETWORK | --network-offtheshelf NETWORK)
[--datasets DATASETS] [--image-size N]
[--multiscale MULTISCALE] [--whitening WHITENING] [--gpu-id N]
有關運行選項的詳細說明:
python3 -m cirtorch.examples.test -h
注意:使用示例腳本時,用於測試的數據將自動下載。
例如,訓練在TPAMI 2018紙張中描述的最佳網絡運行以下命令。在每個時期之後,將對重新訪問的牛津和巴黎基準測試進行微調網絡:
python3 -m cirtorch.examples.train YOUR_EXPORT_DIR --gpu-id '0' --training-dataset 'retrieval-SfM-120k'
--test-datasets 'roxford5k,rparis6k' --arch 'resnet101' --pool 'gem' --loss 'contrastive'
--loss-margin 0.85 --optimizer 'adam' --lr 5e-7 --neg-num 5 --query-size=2000
--pool-size=22000 --batch-size 5 --image-size 362
每個時期之後可以通過學習的美白(在時期結束時估計美白)來評估網絡。為了實現以下命令。請注意,這將大大減慢整個培訓程序,您可以在以後使用示例測試腳本來評估網絡。
python3 -m cirtorch.examples.train YOUR_EXPORT_DIR --gpu-id '0' --training-dataset 'retrieval-SfM-120k'
--test-datasets 'roxford5k,rparis6k' --test-whiten 'retrieval-SfM-30k'
--arch 'resnet101' --pool 'gem' --loss 'contrastive' --loss-margin 0.85
--optimizer 'adam' --lr 5e-7 --neg-num 5 --query-size=2000 --pool-size=22000
--batch-size 5 --image-size 362
注意:調整後的學習率設置為與啞光和pytorch-0.3.0實現培訓的實現相似的性能。
提供了與我們的TPAMI 2018論文相同的參數訓練的網絡,並提供了預先計算的後加工美白步驟。評估它們的運行:
python3 -m cirtorch.examples.test --gpu-id '0' --network-path 'retrievalSfM120k-resnet101-gem'
--datasets 'oxford5k,paris6k,roxford5k,rparis6k'
--whitening 'retrieval-SfM-120k'
--multiscale '[1, 1/2**(1/2), 1/2]'
或者
python3 -m cirtorch.examples.test --gpu-id '0' --network-path 'retrievalSfM120k-vgg16-gem'
--datasets 'oxford5k,paris6k,roxford5k,rparis6k'
--whitening 'retrieval-SfM-120k'
--multiscale '[1, 1/2**(1/2), 1/2]'
下表顯示了使用此框架訓練的網絡的性能比較以及在MatConvnet中使用我們的CNN圖像檢索培訓的論文中使用的網絡:
| 模型 | 牛津 | 巴黎 | ROXF(M) | RPAR(M) | roxf(h) | RPAR(h) |
|---|---|---|---|---|---|---|
| vgg16-gem(啞光) | 87.9 | 87.7 | 61.9 | 69.3 | 33.7 | 44.3 |
| VGG16-GEM(Pytorch) | 87.3 | 87.8 | 60.9 | 69.3 | 32.9 | 44.2 |
| resnet101-gem(啞光) | 87.8 | 92.7 | 64.7 | 77.2 | 38.5 | 56.3 |
| resnet101-gem(pytorch) | 88.2 | 92.5 | 65.4 | 76.7 | 40.1 | 55.2 |
注意(2022年6月):我們更新了牛津5K和巴黎6K圖像的下載文件,以使用原始數據集所有者建議的帶有模糊面的圖像。請記住,“實驗表明,可以使用臉部毛髮版本對圖像檢索進行基準測試,而準確性喪失可以忽略不計”。
使用單個量表和學習美白評估訓練的網絡:
python3 -m cirtorch.examples.test --gpu-id '0' --network-path YOUR_NETWORK_PATH
--datasets 'oxford5k,paris6k,roxford5k,rparis6k'
使用多量表評估評估訓練的網絡,並以學習的美白為後處理:
python3 -m cirtorch.examples.test --gpu-id '0' --network-path YOUR_NETWORK_PATH
--datasets 'oxford5k,paris6k,roxford5k,rparis6k'
--whitening 'retrieval-SfM-120k'
--multiscale '[1, 1/2**(1/2), 1/2]'
例如,也可以評估現成的網絡:
python3 -m cirtorch.examples.test --gpu-id '0' --network-offtheshelf 'resnet101-gem'
--datasets 'oxford5k,paris6k,roxford5k,rparis6k'
--whitening 'retrieval-SfM-120k'
--multiscale '[1, 1/2**(1/2), 1/2]'
替代體系結構包括全局池後的可學習FC(投影)層。重要的是要以學習美白的結果初始化該層的參數。要訓練這樣的設置,您應該運行以下命令(將在roxford5k和rparis6k上每5個時期評估性能):
python3 -m cirtorch.examples.train YOUR_EXPORT_DIR --gpu-id '0' --training-dataset 'retrieval-SfM-120k'
--loss 'triplet' --loss-margin 0.5 --optimizer 'adam' --lr 1e-6
--arch 'resnet50' --pool 'gem' --whitening
--neg-num 5 --query-size=2000 --pool-size=20000
--batch-size 5 --image-size 1024 --epochs 100
--test-datasets 'roxford5k,rparis6k' --test-freq 5
或者
python3 -m cirtorch.examples.train YOUR_EXPORT_DIR --gpu-id '0' --training-dataset 'retrieval-SfM-120k'
--loss 'triplet' --loss-margin 0.5 --optimizer 'adam' --lr 5e-7
--arch 'resnet101' --pool 'gem' --whitening
--neg-num 4 --query-size=2000 --pool-size=20000
--batch-size 5 --image-size 1024 --epochs 100
--test-datasets 'roxford5k,rparis6k' --test-freq 5
或者
python3 -m cirtorch.examples.train YOUR_EXPORT_DIR --gpu-id '0' --training-dataset 'retrieval-SfM-120k'
--loss 'triplet' --loss-margin 0.5 --optimizer 'adam' --lr 5e-7
--arch 'resnet152' --pool 'gem' --whitening
--neg-num 3 --query-size=2000 --pool-size=20000
--batch-size 5 --image-size 900 --epochs 100
--test-datasets 'roxford5k,rparis6k' --test-freq 5
分別用於ResNet50 , ResNet101或ResNet152 。
實施詳細信息:
--neg-num和--image-size超參數,以便可以在具有16 GB內存的單個GPU上執行訓練。提供了帶有投影層的驗證網絡,並在retrieval-SfM-120k (rSfM120k)和google-landmarks-2018 (gl18)火車數據集中接受了培訓。對於此架構,不需要將美白作為後處理步驟(通常是無關緊要的),儘管也可以做到這一點。例如,在google-landmarks-2018 (gl18)數據集中使用高分辨率圖像和三胞胎丟失在Google-Landmarks-2018(GL18)數據集中對RESNET101進行的RESNET101進行多尺度評估,並使用以下腳本進行:
python3 -m cirtorch.examples.test_e2e --gpu-id '0' --network 'gl18-tl-resnet101-gem-w'
--datasets 'roxford5k,rparis6k' --multiscale '[1, 2**(1/2), 1/2**(1/2)]'
下表給出了所有可用預訓練網絡的多尺度性能:
| 模型 | ROXF(M) | RPAR(M) | roxf(h) | RPAR(h) |
|---|---|---|---|---|
| RSFM120K-TL-RESNET50-GEM-W | 64.7 | 76.3 | 39.0 | 54.9 |
| RSFM120K-TL-RESNET101-GEM-W | 67.8 | 77.6 | 41.7 | 56.3 |
| RSFM120K-TL-RESNET152-GEM-W | 68.8 | 78.0 | 41.3 | 57.2 |
| GL18-TL-RESNET50-GEM-W | 63.6 | 78.0 | 40.9 | 57.5 |
| GL18-TL-RESNET101-GEM-W | 67.3 | 80.6 | 44.3 | 61.5 |
| GL18-TL-RESNET152-GEM-W | 68.7 | 79.7 | 44.2 | 60.3 |
注意(2022年6月):我們更新了牛津5K和巴黎6K圖像的下載文件,以使用原始數據集所有者建議的帶有模糊面的圖像。請記住,“實驗表明,可以使用臉部毛髮版本對圖像檢索進行基準測試,而準確性喪失可以忽略不計”。
@article{RTC18,
title = {Fine-tuning {CNN} Image Retrieval with No Human Annotation},
author = {Radenovi{'c}, F. and Tolias, G. and Chum, O.}
journal = {TPAMI},
year = {2018}
}
@inproceedings{RTC16,
title = {{CNN} Image Retrieval Learns from {BoW}: Unsupervised Fine-Tuning with Hard Examples},
author = {Radenovi{'c}, F. and Tolias, G. and Chum, O.},
booktitle = {ECCV},
year = {2016}
}
@inproceedings{RITAC18,
author = {Radenovi{'c}, F. and Iscen, A. and Tolias, G. and Avrithis, Y. and Chum, O.},
title = {Revisiting Oxford and Paris: Large-Scale Image Retrieval Benchmarking},
booktitle = {CVPR},
year = {2018}
}
roxford5k和rparis6k上添加了Mutli級的性能,用於新的預培訓網絡,並在retrieval-SfM-120和google-landmarks-2018 Train DataSet上接受了培訓