本项目的行人重识别是出自论文"Beyond Scalar Neuron: Adopting Vector-Neuron Capsules for Long-Term Person Re-Identification",该文章所涉及到的相关理论在我另外一篇文章中有讲解:Reid系列论文学习——换装Reid,不过经过本人测试,论文开源的代码有一些bug,同时也没有关于实际图像测试的代码,因此我对这个项目代码进行了完善。
该论文一个重要的贡献就是发布了相关换装的行人数据集celeb-reid。
该数据集有1052个ID,34186张图像,官方数据集链接:
官方数据集百度云: 密码: ix2j
将数据集下载好后放置datasets中。
然后还需要运行脚本进行身体部位的划分:
python split_data.py
得到目录如下:
Reid训练
由于该部分训练牵扯到了人员身体各个部分的训练,因此项目提供了训练脚本可以快速开启训练,修改run_train.sh中的数据集路径:
#!/bin/sh
python train.py --train_path '/datasets/celeb/train' --gallery_path '/datasets/celeb/gallery' --query_path '/datasets/celeb/query' --logs-dir 'log_celeb_all'
python train.py --train_path '/datasets/celeb/train_1_1' --gallery_path '/datasets/celeb/gallery_1_1' --query_path '/datasets/celeb/query_1_1' --logs-dir 'log_celeb_11' --epochs 50 --step_size 40
python train.py --train_path '/datasets/celeb/train_1_2' --gallery_path '/datasets/celeb/gallery_1_2' --query_path '/datasets/celeb/query_1_2' --logs-dir 'log_celeb_12' --epochs 50 --step_size 40
python train.py --train_path '/datasets/celeb/train_1_3' --gallery_path '/datasets/celeb/gallery_1_3' --query_path '/datasets/celeb/query_1_3' --logs-dir 'log_celeb_13' --epochs 50 --step_size 40
python train.py --train_path '/datasets/celeb/train_2_1' --gallery_path '/datasets/celeb/gallery_2_1' --query_path '/datasets/celeb/query_2_1' --logs-dir 'log_celeb_21' --epochs 50 --step_size 40
python train.py --train_path '/datasets/celeb/train_2_2' --gallery_path '/datasets/celeb/gallery_2_2' --query_path '/datasets/celeb/query_2_2' --logs-dir 'log_celeb_22' --epochs 50 --step_size 40
运行上述脚本后可开启训练。
训练完成的各部分权重会保存在以下文件中:
训练详细代码的实现可以看train.py
测试
测试代码在test.py中,该脚本可用于评价指标的复现。并不是检测图像!!
其中--part_train参数是训练好的各身体部分权重路径。
快速开启测试:
python test.py
图像检测
图像检测核心代码在predict.py中。
在检测之前需要将query人员放置在query文件夹中(比如我要从一堆人里找刘德华),然后gallery就是"人群图像集",运行split_data.py脚本进行身体部分的划分,然后就可以运行predict.py了。其中gallery中的人群图像集如下,我要的是从人群中把换装后的刘德华找出来。
最终效果图如下图所示:
query Image是待检测人员,Most similar是最像的(准确度最高的)
注:图像检测代码部分为有偿提供~