博主自己也在github上提供了一个极好的行人重识别库,大家可以看看并下载和使用:
https://github.com/nickhuang1996/HJL-re-id
相关简介:行人重识别github开源库——HJL-re-id
详细内容参见Readme部分
目录
一、介绍
Open-ReID是一个轻量级的行人重识别库,用于研究目的。
它旨在为不同的数据集提供统一的界面,一整套模型和评估指标,以及再现(接近)最新结果的示例。
二、依赖项
安装PyTorch(版本≥ 0.2.0)。
虽然Open-ReID同时支持python2和python3,但建议使用python3以获得更好的性能。
三、下载
1.下载地址为:https://cysu.github.io/open-reid/
2.我们下载它,并解压,如下:
四、安装
1.可以使用cmd运行:
-
cd open-reid
-
python setup.py install
2.使用IDE运行,可以debug得快一些,博主使用vs2019:
关于如何使用vs2019运行Python程序,详情请看博主博客:vs2019 开始自己的第一个Python程序——九九乘法表
(1)脚本参数就是install
(2)运行结果
-
running install
-
running bdist_egg
-
running egg_info
-
writing open_reid.egg-info\PKG-INFO
-
writing dependency_links to open_reid.egg-info\dependency_links.txt
-
writing requirements to open_reid.egg-info\requires.txt
-
writing top-level names to open_reid.egg-info\top_level.txt
-
reading manifest file 'open_reid.egg-info\SOURCES.txt'
-
writing manifest file 'open_reid.egg-info\SOURCES.txt'
-
installing library code to build\bdist.win-amd64\egg
-
running install_lib
-
running build_py
-
creating build\bdist.win-amd64\egg
-
creating build\bdist.win-amd64\egg\reid
-
creating build\bdist.win-amd64\egg\reid\datasets
-
copying build\lib\reid\datasets\cuhk01.py -> build\bdist.win-amd64\egg\reid\datasets
-
copying build\lib\reid\datasets\cuhk03.py -> build\bdist.win-amd64\egg\reid\datasets
-
copying build\lib\reid\datasets\dukemtmc.py -> build\bdist.win-amd64\egg\reid\datasets
-
copying build\lib\reid\datasets\market1501.py -> build\bdist.win-amd64\egg\reid\datasets
-
copying build\lib\reid\datasets\viper.py -> build\bdist.win-amd64\egg\reid\datasets
-
copying build\lib\reid\datasets\__init__.py -> build\bdist.win-amd64\egg\reid\datasets
-
copying build\lib\reid\dist_metric.py -> build\bdist.win-amd64\egg\reid
-
creating build\bdist.win-amd64\egg\reid\evaluation_metrics
-
copying build\lib\reid\evaluation_metrics\classification.py -> build\bdist.win-amd64\egg\reid\evaluation_metrics
-
copying build\lib\reid\evaluation_metrics\ranking.py -> build\bdist.win-amd64\egg\reid\evaluation_metrics
-
copying build\lib\reid\evaluation_metrics\__init__.py -> build\bdist.win-amd64\egg\reid\evaluation_metrics
-
copying build\lib\reid\evaluators.py -> build\bdist.win-amd64\egg\reid
-
creating build\bdist.win-amd64\egg\reid\feature_extraction
-
copying build\lib\reid\feature_extraction\cnn.py -> build\bdist.win-amd64\egg\reid\feature_extraction
-
copying build\lib\reid\feature_extraction\database.py -> build\bdist.win-amd64\egg\reid\feature_extraction
-
copying build\lib\reid\feature_extraction\__init__.py -> build\bdist.win-amd64\egg\reid\feature_extraction
-
creating build\bdist.win-amd64\egg\reid\loss
-
copying build\lib\reid\loss\oim.py -> build\bdist.win-amd64\egg\reid\loss
-
copying build\lib\reid\loss\triplet.py -> build\bdist.win-amd64\egg\reid\loss
-
copying build\lib\reid\loss\__init__.py -> build\bdist.win-amd64\egg\reid\loss
-
creating build\bdist.win-amd64\egg\reid\metric_learning
-
copying build\lib\reid\metric_learning\euclidean.py -> build\bdist.win-amd64\egg\reid\metric_learning
-
copying build\lib\reid\metric_learning\kissme.py -> build\bdist.win-amd64\egg\reid\metric_learning
-
copying build\lib\reid\metric_learning\__init__.py -> build\bdist.win-amd64\egg\reid\metric_learning
-
creating build\bdist.win-amd64\egg\reid\models
-
copying build\lib\reid\models\inception.py -> build\bdist.win-amd64\egg\reid\models
-
copying build\lib\reid\models\resnet.py -> build\bdist.win-amd64\egg\reid\models
-
copying build\lib\reid\models\__init__.py -> build\bdist.win-amd64\egg\reid\models
-
copying build\lib\reid\trainers.py -> build\bdist.win-amd64\egg\reid
-
creating build\bdist.win-amd64\egg\reid\utils
-
creating build\bdist.win-amd64\egg\reid\utils\data
-
copying build\lib\reid\utils\data\dataset.py -> build\bdist.win-amd64\egg\reid\utils\data
-
copying build\lib\reid\utils\data\preprocessor.py -> build\bdist.win-amd64\egg\reid\utils\data
-
copying build\lib\reid\utils\data\sampler.py -> build\bdist.win-amd64\egg\reid\utils\data
-
copying build\lib\reid\utils\data\transforms.py -> build\bdist.win-amd64\egg\reid\utils\data
-
copying build\lib\reid\utils\data\__init__.py -> build\bdist.win-amd64\egg\reid\utils\data
-
copying build\lib\reid\utils\logging.py -> build\bdist.win-amd64\egg\reid\utils
-
copying build\lib\reid\utils\meters.py -> build\bdist.win-amd64\egg\reid\utils
-
copying build\lib\reid\utils\osutils.py -> build\bdist.win-amd64\egg\reid\utils
-
copying build\lib\reid\utils\serialization.py -> build\bdist.win-amd64\egg\reid\utils
-
copying build\lib\reid\utils\__init__.py -> build\bdist.win-amd64\egg\reid\utils
-
copying build\lib\reid\__init__.py -> build\bdist.win-amd64\egg\reid
-
byte-compiling build\bdist.win-amd64\egg\reid\datasets\cuhk01.py to cuhk01.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\datasets\cuhk03.py to cuhk03.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\datasets\dukemtmc.py to dukemtmc.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\datasets\market1501.py to market1501.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\datasets\viper.py to viper.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\datasets\__init__.py to __init__.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\dist_metric.py to dist_metric.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\evaluation_metrics\classification.py to classification.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\evaluation_metrics\ranking.py to ranking.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\evaluation_metrics\__init__.py to __init__.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\evaluators.py to evaluators.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\feature_extraction\cnn.py to cnn.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\feature_extraction\database.py to database.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\feature_extraction\__init__.py to __init__.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\loss\oim.py to oim.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\loss\triplet.py to triplet.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\loss\__init__.py to __init__.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\metric_learning\euclidean.py to euclidean.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\metric_learning\kissme.py to kissme.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\metric_learning\__init__.py to __init__.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\models\inception.py to inception.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\models\resnet.py to resnet.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\models\__init__.py to __init__.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\trainers.py to trainers.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\data\dataset.py to dataset.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\data\preprocessor.py to preprocessor.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\data\sampler.py to sampler.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\data\transforms.py to transforms.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\data\__init__.py to __init__.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\logging.py to logging.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\meters.py to meters.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\osutils.py to osutils.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\serialization.py to serialization.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\utils\__init__.py to __init__.cpython-36.pyc
-
byte-compiling build\bdist.win-amd64\egg\reid\__init__.py to __init__.cpython-36.pyc
-
creating build\bdist.win-amd64\egg\EGG-INFO
-
copying open_reid.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
-
copying open_reid.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
-
copying open_reid.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
-
copying open_reid.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO
-
copying open_reid.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
-
zip_safe flag not set; analyzing archive contents...
-
creating 'dist\open_reid-0.2.0-py3.6.egg' and adding 'build\bdist.win-amd64\egg' to it
-
removing 'build\bdist.win-amd64\egg' (and everything under it)
-
Processing open_reid-0.2.0-py3.6.egg
-
Removing d:\anaconda3\lib\site-packages\open_reid-0.2.0-py3.6.egg
-
Copying open_reid-0.2.0-py3.6.egg to d:\anaconda3\lib\site-packages
-
open-reid 0.2.0 is already the active version in easy-install.pth
-
-
Installed d:\anaconda3\lib\site-packages\open_reid-0.2.0-py3.6.egg
-
Processing dependencies for open-reid==0.2.0
-
Searching for metric-learn==0.4.0
-
Best match: metric-learn 0.4.0
-
Processing metric_learn-0.4.0-py3.6.egg
-
metric-learn 0.4.0 is already the active version in easy-install.pth
-
-
Using d:\anaconda3\lib\site-packages\metric_learn-0.4.0-py3.6.egg
-
Searching for scikit-learn==0.20.1
-
Best match: scikit-learn 0.20.1
-
Adding scikit-learn 0.20.1 to easy-install.pth file
-
-
Using d:\anaconda3\lib\site-packages
-
Searching for Pillow==5.3.0
-
Best match: Pillow 5.3.0
-
Adding Pillow 5.3.0 to easy-install.pth file
-
-
Using d:\anaconda3\lib\site-packages
-
Searching for h5py==2.8.0
-
Best match: h5py 2.8.0
-
Adding h5py 2.8.0 to easy-install.pth file
-
-
Using d:\anaconda3\lib\site-packages
-
Searching for six==1.11.0
-
Best match: six 1.11.0
-
Adding six 1.11.0 to easy-install.pth file
-
-
Using d:\anaconda3\lib\site-packages
-
Searching for torchvision==0.2.1
-
Best match: torchvision 0.2.1
-
Adding torchvision 0.2.1 to easy-install.pth file
-
-
Using d:\anaconda3\lib\site-packages
-
Searching for torch==1.0.1
-
Best match: torch 1.0.1
-
Adding torch 1.0.1 to easy-install.pth file
-
Installing convert-caffe2-to-onnx-script.py script to D:\Anaconda3\Scripts
-
Installing convert-caffe2-to-onnx.exe script to D:\Anaconda3\Scripts
-
Installing convert-onnx-to-caffe2-script.py script to D:\Anaconda3\Scripts
-
Installing convert-onnx-to-caffe2.exe script to D:\Anaconda3\Scripts
-
-
Using d:\anaconda3\lib\site-packages
-
Searching for scipy==1.1.0
-
Best match: scipy 1.1.0
-
Adding scipy 1.1.0 to easy-install.pth file
-
-
Using d:\anaconda3\lib\site-packages
-
Searching for numpy==1.15.4
-
Best match: numpy 1.15.4
-
Adding numpy 1.15.4 to easy-install.pth file
-
-
Using d:\anaconda3\lib\site-packages
-
Finished processing dependencies for open-reid==0.2.0
(3)查看项目文件夹,可以看到多了3个文件夹:
- bulid
- dist
- open_reid.egg-info
五、使用前的注意事项
1.期间会下载VIPeR数据集,该数据集包含632个行人图像对,每个图像已缩放为128x48像素大小。
Downloading http://users.soe.ucsc.edu/~manduchi/VIPeR.v1.0.zip to D:\vs2019_project\datasets\open-reid-master\examples\data\viper\raw\VIPeR.v1.0.zip
分为2个文件夹:
- cam_a
- cam_b
打开这2个文件夹,可以看到cam_a主要拍摄的是行人的正面照,cam_b主要拍摄是行人的侧身和背身照
(1)cam_a:
(2)cam_b:
2.此外,使用python3的用户需要更改reid文件夹底下的trainers.py文件的第33行,将
losses.update(loss.data[0], targets.size(0))
改为
losses.update(loss.data.item(), targets.size(0))
如下
六、快速开始(训练+测试)
参数解释:
- -d:dataset,设置为viper
- -b:batch size,设置为64
- -j:workers,设置为2(可根据cpu内核线程数而定)
- -a:arch,设置为resnet50(模型名称,可选'inception', 'resnet18', 'resnet34', 'resnet50', 'resnet101',和 'resnet152')
1.cmd运行examples文件夹底下的softmax_loss.py文件
python examples/softmax_loss.py -d viper -b 64 -j 2 -a resnet50 --logs-dir logs/softmax-loss/viper-resnet50
2.IDE运行,vs2019中设置softmax_loss.py文件为启动文件
3.运行程序:
训练,默认50个epoch
最后进行测试
4.此外,还会生成logs文件夹,如下:
5.我们的实验记录在logs\softmax-loss\viper-resnet50可以看到:
- 有每次训练的checkpoint
- 最好的checkpoint
- 实验记录log.txt(记录了控制台打印的实验信息)
是不是很好用呢~
文章来源: nickhuang1996.blog.csdn.net,作者:悲恋花丶无心之人,版权归原作者所有,如需转载,请联系作者。
原文链接:nickhuang1996.blog.csdn.net/article/details/89843057