Torchreid是一个深入学习的人重新识别的图书馆,用Pytorch编写,并为我们的ICCV'19项目开发,“ Omni级”功能学习人员重新识别。
它的特征:
代码:https://github.com/kaiyangzhou/deep-person-reid。
文档:https://kaiyangzhou.github.io/deep-person-reid/。
操作指令:https://kaiyangzhou.github.io/deep-person-reid/user_guide。
模型动物园:https://kaiyangzhou.github.io/deep-person-reid/model_zoo。
技术报告:https://arxiv.org/abs/1910.10093。
您可以在这里找到一些在Torchreid顶部建立的研究项目。
osnet_ain_x0_75 , osnet_ain_x0_5和osnet_ain_x0_25的Imagenet预测模型。预训练的设置遵循PYCL。tools/parse_test_res.py 。v1.4.0 :我们添加了搜索数据集,cuhk-sysu。请参阅有关如何下载数据集的文档(其中包含裁剪的人图像)。v1.3.6添加了University-1652,这是一个用于多视图多源地理位置化的新数据集(荣誉归功于Zhedong Zheng)。v1.3.5 :现在,Cython代码在Windows上工作(贷记为Lablabla)。v1.3.3 :修复了visrank中的错误(由不拆箱dsetid引起)。v1.3.2 :将_junk_pids添加到grid和prid中。这避免了使用标签的图库图像进行训练时,将其设置combineall=True 。v1.3.0 :(1)将dsetid添加到现有的3元组数据源中,从而导致(impath, pid, camid, dsetid) 。该变量表示数据集ID,在组合多个用于培训的数据集(作为数据集指标)时很有用。例如,当组合market1501和cuhk03时,前者将分配dsetid=0而后者将分配dsetid=1 。 (2)添加了RandomDatasetSampler 。类似于RandomDomainSampler , RandomDatasetSampler从每个指定的数据集中示例了一定数量的图像( batch_size // num_datasets )(该量由num_datasets确定)。v1.2.6 :添加了RandomDomainSampler (它采样了每个带有batch_size // num_cams图像num_cams摄像机以形成一个迷你批次)。v1.2.5 :(1) __getitem__的数据加载器的输出已从list更改为dict 。以前,用imgs=data[0]获取一个元素,例如图像张量。现在应该通过imgs=data['img']获得。请参阅此提交的详细更改。 (2)添加了k_tfm作为图像数据加载程序的选项,该选项允许将数据扩展k_tfm应用于图像。如果k_tfm > 1 , imgs=data['img']返回带有k_tfm图像张量的列表。projects/attribute_recognition/ 。v1.2.1 :添加了一个简单的API用于特征提取( torchreid/utils/feature_extractor.py )。有关指令,请参见文档。projects/DML上发布了OSNET论文中深度相互学习的实验的代码。v1.2.0 。发动机类已成为更具模型的型号,以提高可扩展性。有关更多详细信息,请参见引擎和ImagesoftMaxEngine。信用dassl.pytorch。ImageDataManager可以通过设置load_train_targets=True加载目标数据集中的训练数据,并且可以使用train_loader_t = datamanager.train_loader_t访问火车加载程序。此功能可用于域适应研究。 确保安装了Conda。
# cd to your preferred directory and clone this repo
git clone https://github.com/KaiyangZhou/deep-person-reid.git
# create environment
cd deep-person-reid/
conda create --name torchreid python=3.7
conda activate torchreid
# install dependencies
# make sure `which python` and `which pip` point to the correct path
pip install -r requirements.txt
# install torch and torchvision (select the proper cuda version to suit your machine)
conda install pytorch torchvision cudatoolkit=9.0 -c pytorch
# install torchreid (don't need to re-build it if you modify the source code)
python setup.py develop安装的另一种方法是运行Docker容器中的所有内容:
make build-imagemake run torchreid import torchreid datamanager = torchreid . data . ImageDataManager (
root = "reid-data" ,
sources = "market1501" ,
targets = "market1501" ,
height = 256 ,
width = 128 ,
batch_size_train = 32 ,
batch_size_test = 100 ,
transforms = [ "random_flip" , "random_crop" ]
)3构建模型,优化器和LR_SCHEDULER
model = torchreid . models . build_model (
name = "resnet50" ,
num_classes = datamanager . num_train_pids ,
loss = "softmax" ,
pretrained = True
)
model = model . cuda ()
optimizer = torchreid . optim . build_optimizer (
model ,
optim = "adam" ,
lr = 0.0003
)
scheduler = torchreid . optim . build_lr_scheduler (
optimizer ,
lr_scheduler = "single_step" ,
stepsize = 20
) engine = torchreid . engine . ImageSoftmaxEngine (
datamanager ,
model ,
optimizer = optimizer ,
scheduler = scheduler ,
label_smooth = True
) engine . run (
save_dir = "log/resnet50" ,
max_epoch = 60 ,
eval_freq = 10 ,
print_freq = 10 ,
test_only = False
)在“ Deep-Person-Reid/Scripts/”中,我们提供了一个统一的接口来训练和测试模型。有关更多详细信息,请参见“脚本/main.py”和“脚本/default_config.py”。文件夹“ Configs/”包含一些预定义的配置,您可以将其用作起点。
在下面,我们提供了训练和测试OSNET的示例(Zhou等人ICCV'19)。假设PATH_TO_DATA是包含REID数据集的目录。省略了环境变量CUDA_VISIBLE_DEVICES ,如果您有GPU池并想要使用特定的集合,则需要指定它。
在Market1501上训练OSNET,请
python scripts/main.py
--config-file configs/im_osnet_x1_0_softmax_256x128_amsgrad_cosine.yaml
--transforms random_flip random_erase
--root $PATH_TO_DATA配置文件将Market1501设置为默认数据集。如果您想使用dukemtmc-reid,请执行
python scripts/main.py
--config-file configs/im_osnet_x1_0_softmax_256x128_amsgrad_cosine.yaml
-s dukemtmcreid
-t dukemtmcreid
--transforms random_flip random_erase
--root $PATH_TO_DATA
data.save_dir log/osnet_x1_0_dukemtmcreid_softmax_cosinelr该代码将自动(下载并)加载ImageNet预算的重量。训练完成后,该模型将被保存为“ log/osnet_x1_0_market1_softmax_cosinelr/model.pth.pth.tar-250”。在同一文件夹下,您可以找到张板文件。要使用张量板可视化学习曲线,您可以运行tensorboard --logdir=log/osnet_x1_0_market1501_softmax_cosinelr在终端中,并访问http://localhost:6006/在您的Web浏览器中。
评估在培训结束时自动进行。要使用受过训练的模型再次进行测试,请
python scripts/main.py
--config-file configs/im_osnet_x1_0_softmax_256x128_amsgrad_cosine.yaml
--root $PATH_TO_DATA
model.load_weights log/osnet_x1_0_market1501_softmax_cosinelr/model.pth.tar-250
test.evaluate True假设您想在dukemtmc-reid上训练OSNET并在Market1501上测试其性能,您可以做
python scripts/main.py
--config-file configs/im_osnet_x1_0_softmax_256x128_amsgrad.yaml
-s dukemtmcreid
-t market1501
--transforms random_flip color_jitter
--root $PATH_TO_DATA在这里,我们仅测试跨域性能。但是,如果您还想测试源数据集(即Dukemtmc -reid)上的性能,则可以设置-t dukemtmcreid market1501 ,该Market1501将分别评估两个数据集中的模型。
与同一域设置不同,在这里我们用color_jitter替换random_erase 。这可以改善看不见的目标数据集上的概括性能。
验证的模型在模型动物园中可用。
如果您在研究中使用此代码或模型,请归功于以下论文:
@article{torchreid,
title={Torchreid: A Library for Deep Learning Person Re-Identification in Pytorch},
author={Zhou, Kaiyang and Xiang, Tao},
journal={arXiv preprint arXiv:1910.10093},
year={2019}
}
@inproceedings{zhou2019osnet,
title={Omni-Scale Feature Learning for Person Re-Identification},
author={Zhou, Kaiyang and Yang, Yongxin and Cavallaro, Andrea and Xiang, Tao},
booktitle={ICCV},
year={2019}
}
@article{zhou2021osnet,
title={Learning Generalisable Omni-Scale Representations for Person Re-Identification},
author={Zhou, Kaiyang and Yang, Yongxin and Cavallaro, Andrea and Xiang, Tao},
journal={TPAMI},
year={2021}
}