行人重识别库Open-ReID的下载和使用

博主自己也在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运行:


  
  1. cd open-reid
  2. python setup.py install

2.使用IDE运行,可以debug得快一些,博主使用vs2019

关于如何使用vs2019运行Python程序,详情请看博主博客:vs2019 开始自己的第一个Python程序——九九乘法表

(1)脚本参数就是install

(2)运行结果


  
  1. running install
  2. running bdist_egg
  3. running egg_info
  4. writing open_reid.egg-info\PKG-INFO
  5. writing dependency_links to open_reid.egg-info\dependency_links.txt
  6. writing requirements to open_reid.egg-info\requires.txt
  7. writing top-level names to open_reid.egg-info\top_level.txt
  8. reading manifest file 'open_reid.egg-info\SOURCES.txt'
  9. writing manifest file 'open_reid.egg-info\SOURCES.txt'
  10. installing library code to build\bdist.win-amd64\egg
  11. running install_lib
  12. running build_py
  13. creating build\bdist.win-amd64\egg
  14. creating build\bdist.win-amd64\egg\reid
  15. creating build\bdist.win-amd64\egg\reid\datasets
  16. copying build\lib\reid\datasets\cuhk01.py -> build\bdist.win-amd64\egg\reid\datasets
  17. copying build\lib\reid\datasets\cuhk03.py -> build\bdist.win-amd64\egg\reid\datasets
  18. copying build\lib\reid\datasets\dukemtmc.py -> build\bdist.win-amd64\egg\reid\datasets
  19. copying build\lib\reid\datasets\market1501.py -> build\bdist.win-amd64\egg\reid\datasets
  20. copying build\lib\reid\datasets\viper.py -> build\bdist.win-amd64\egg\reid\datasets
  21. copying build\lib\reid\datasets\__init__.py -> build\bdist.win-amd64\egg\reid\datasets
  22. copying build\lib\reid\dist_metric.py -> build\bdist.win-amd64\egg\reid
  23. creating build\bdist.win-amd64\egg\reid\evaluation_metrics
  24. copying build\lib\reid\evaluation_metrics\classification.py -> build\bdist.win-amd64\egg\reid\evaluation_metrics
  25. copying build\lib\reid\evaluation_metrics\ranking.py -> build\bdist.win-amd64\egg\reid\evaluation_metrics
  26. copying build\lib\reid\evaluation_metrics\__init__.py -> build\bdist.win-amd64\egg\reid\evaluation_metrics
  27. copying build\lib\reid\evaluators.py -> build\bdist.win-amd64\egg\reid
  28. creating build\bdist.win-amd64\egg\reid\feature_extraction
  29. copying build\lib\reid\feature_extraction\cnn.py -> build\bdist.win-amd64\egg\reid\feature_extraction
  30. copying build\lib\reid\feature_extraction\database.py -> build\bdist.win-amd64\egg\reid\feature_extraction
  31. copying build\lib\reid\feature_extraction\__init__.py -> build\bdist.win-amd64\egg\reid\feature_extraction
  32. creating build\bdist.win-amd64\egg\reid\loss
  33. copying build\lib\reid\loss\oim.py -> build\bdist.win-amd64\egg\reid\loss
  34. copying build\lib\reid\loss\triplet.py -> build\bdist.win-amd64\egg\reid\loss
  35. copying build\lib\reid\loss\__init__.py -> build\bdist.win-amd64\egg\reid\loss
  36. creating build\bdist.win-amd64\egg\reid\metric_learning
  37. copying build\lib\reid\metric_learning\euclidean.py -> build\bdist.win-amd64\egg\reid\metric_learning
  38. copying build\lib\reid\metric_learning\kissme.py -> build\bdist.win-amd64\egg\reid\metric_learning
  39. copying build\lib\reid\metric_learning\__init__.py -> build\bdist.win-amd64\egg\reid\metric_learning
  40. creating build\bdist.win-amd64\egg\reid\models
  41. copying build\lib\reid\models\inception.py -> build\bdist.win-amd64\egg\reid\models
  42. copying build\lib\reid\models\resnet.py -> build\bdist.win-amd64\egg\reid\models
  43. copying build\lib\reid\models\__init__.py -> build\bdist.win-amd64\egg\reid\models
  44. copying build\lib\reid\trainers.py -> build\bdist.win-amd64\egg\reid
  45. creating build\bdist.win-amd64\egg\reid\utils
  46. creating build\bdist.win-amd64\egg\reid\utils\data
  47. copying build\lib\reid\utils\data\dataset.py -> build\bdist.win-amd64\egg\reid\utils\data
  48. copying build\lib\reid\utils\data\preprocessor.py -> build\bdist.win-amd64\egg\reid\utils\data
  49. copying build\lib\reid\utils\data\sampler.py -> build\bdist.win-amd64\egg\reid\utils\data
  50. copying build\lib\reid\utils\data\transforms.py -> build\bdist.win-amd64\egg\reid\utils\data
  51. copying build\lib\reid\utils\data\__init__.py -> build\bdist.win-amd64\egg\reid\utils\data
  52. copying build\lib\reid\utils\logging.py -> build\bdist.win-amd64\egg\reid\utils
  53. copying build\lib\reid\utils\meters.py -> build\bdist.win-amd64\egg\reid\utils
  54. copying build\lib\reid\utils\osutils.py -> build\bdist.win-amd64\egg\reid\utils
  55. copying build\lib\reid\utils\serialization.py -> build\bdist.win-amd64\egg\reid\utils
  56. copying build\lib\reid\utils\__init__.py -> build\bdist.win-amd64\egg\reid\utils
  57. copying build\lib\reid\__init__.py -> build\bdist.win-amd64\egg\reid
  58. byte-compiling build\bdist.win-amd64\egg\reid\datasets\cuhk01.py to cuhk01.cpython-36.pyc
  59. byte-compiling build\bdist.win-amd64\egg\reid\datasets\cuhk03.py to cuhk03.cpython-36.pyc
  60. byte-compiling build\bdist.win-amd64\egg\reid\datasets\dukemtmc.py to dukemtmc.cpython-36.pyc
  61. byte-compiling build\bdist.win-amd64\egg\reid\datasets\market1501.py to market1501.cpython-36.pyc
  62. byte-compiling build\bdist.win-amd64\egg\reid\datasets\viper.py to viper.cpython-36.pyc
  63. byte-compiling build\bdist.win-amd64\egg\reid\datasets\__init__.py to __init__.cpython-36.pyc
  64. byte-compiling build\bdist.win-amd64\egg\reid\dist_metric.py to dist_metric.cpython-36.pyc
  65. byte-compiling build\bdist.win-amd64\egg\reid\evaluation_metrics\classification.py to classification.cpython-36.pyc
  66. byte-compiling build\bdist.win-amd64\egg\reid\evaluation_metrics\ranking.py to ranking.cpython-36.pyc
  67. byte-compiling build\bdist.win-amd64\egg\reid\evaluation_metrics\__init__.py to __init__.cpython-36.pyc
  68. byte-compiling build\bdist.win-amd64\egg\reid\evaluators.py to evaluators.cpython-36.pyc
  69. byte-compiling build\bdist.win-amd64\egg\reid\feature_extraction\cnn.py to cnn.cpython-36.pyc
  70. byte-compiling build\bdist.win-amd64\egg\reid\feature_extraction\database.py to database.cpython-36.pyc
  71. byte-compiling build\bdist.win-amd64\egg\reid\feature_extraction\__init__.py to __init__.cpython-36.pyc
  72. byte-compiling build\bdist.win-amd64\egg\reid\loss\oim.py to oim.cpython-36.pyc
  73. byte-compiling build\bdist.win-amd64\egg\reid\loss\triplet.py to triplet.cpython-36.pyc
  74. byte-compiling build\bdist.win-amd64\egg\reid\loss\__init__.py to __init__.cpython-36.pyc
  75. byte-compiling build\bdist.win-amd64\egg\reid\metric_learning\euclidean.py to euclidean.cpython-36.pyc
  76. byte-compiling build\bdist.win-amd64\egg\reid\metric_learning\kissme.py to kissme.cpython-36.pyc
  77. byte-compiling build\bdist.win-amd64\egg\reid\metric_learning\__init__.py to __init__.cpython-36.pyc
  78. byte-compiling build\bdist.win-amd64\egg\reid\models\inception.py to inception.cpython-36.pyc
  79. byte-compiling build\bdist.win-amd64\egg\reid\models\resnet.py to resnet.cpython-36.pyc
  80. byte-compiling build\bdist.win-amd64\egg\reid\models\__init__.py to __init__.cpython-36.pyc
  81. byte-compiling build\bdist.win-amd64\egg\reid\trainers.py to trainers.cpython-36.pyc
  82. byte-compiling build\bdist.win-amd64\egg\reid\utils\data\dataset.py to dataset.cpython-36.pyc
  83. byte-compiling build\bdist.win-amd64\egg\reid\utils\data\preprocessor.py to preprocessor.cpython-36.pyc
  84. byte-compiling build\bdist.win-amd64\egg\reid\utils\data\sampler.py to sampler.cpython-36.pyc
  85. byte-compiling build\bdist.win-amd64\egg\reid\utils\data\transforms.py to transforms.cpython-36.pyc
  86. byte-compiling build\bdist.win-amd64\egg\reid\utils\data\__init__.py to __init__.cpython-36.pyc
  87. byte-compiling build\bdist.win-amd64\egg\reid\utils\logging.py to logging.cpython-36.pyc
  88. byte-compiling build\bdist.win-amd64\egg\reid\utils\meters.py to meters.cpython-36.pyc
  89. byte-compiling build\bdist.win-amd64\egg\reid\utils\osutils.py to osutils.cpython-36.pyc
  90. byte-compiling build\bdist.win-amd64\egg\reid\utils\serialization.py to serialization.cpython-36.pyc
  91. byte-compiling build\bdist.win-amd64\egg\reid\utils\__init__.py to __init__.cpython-36.pyc
  92. byte-compiling build\bdist.win-amd64\egg\reid\__init__.py to __init__.cpython-36.pyc
  93. creating build\bdist.win-amd64\egg\EGG-INFO
  94. copying open_reid.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
  95. copying open_reid.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
  96. copying open_reid.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
  97. copying open_reid.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO
  98. copying open_reid.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
  99. zip_safe flag not set; analyzing archive contents...
  100. creating 'dist\open_reid-0.2.0-py3.6.egg' and adding 'build\bdist.win-amd64\egg' to it
  101. removing 'build\bdist.win-amd64\egg' (and everything under it)
  102. Processing open_reid-0.2.0-py3.6.egg
  103. Removing d:\anaconda3\lib\site-packages\open_reid-0.2.0-py3.6.egg
  104. Copying open_reid-0.2.0-py3.6.egg to d:\anaconda3\lib\site-packages
  105. open-reid 0.2.0 is already the active version in easy-install.pth
  106. Installed d:\anaconda3\lib\site-packages\open_reid-0.2.0-py3.6.egg
  107. Processing dependencies for open-reid==0.2.0
  108. Searching for metric-learn==0.4.0
  109. Best match: metric-learn 0.4.0
  110. Processing metric_learn-0.4.0-py3.6.egg
  111. metric-learn 0.4.0 is already the active version in easy-install.pth
  112. Using d:\anaconda3\lib\site-packages\metric_learn-0.4.0-py3.6.egg
  113. Searching for scikit-learn==0.20.1
  114. Best match: scikit-learn 0.20.1
  115. Adding scikit-learn 0.20.1 to easy-install.pth file
  116. Using d:\anaconda3\lib\site-packages
  117. Searching for Pillow==5.3.0
  118. Best match: Pillow 5.3.0
  119. Adding Pillow 5.3.0 to easy-install.pth file
  120. Using d:\anaconda3\lib\site-packages
  121. Searching for h5py==2.8.0
  122. Best match: h5py 2.8.0
  123. Adding h5py 2.8.0 to easy-install.pth file
  124. Using d:\anaconda3\lib\site-packages
  125. Searching for six==1.11.0
  126. Best match: six 1.11.0
  127. Adding six 1.11.0 to easy-install.pth file
  128. Using d:\anaconda3\lib\site-packages
  129. Searching for torchvision==0.2.1
  130. Best match: torchvision 0.2.1
  131. Adding torchvision 0.2.1 to easy-install.pth file
  132. Using d:\anaconda3\lib\site-packages
  133. Searching for torch==1.0.1
  134. Best match: torch 1.0.1
  135. Adding torch 1.0.1 to easy-install.pth file
  136. Installing convert-caffe2-to-onnx-script.py script to D:\Anaconda3\Scripts
  137. Installing convert-caffe2-to-onnx.exe script to D:\Anaconda3\Scripts
  138. Installing convert-onnx-to-caffe2-script.py script to D:\Anaconda3\Scripts
  139. Installing convert-onnx-to-caffe2.exe script to D:\Anaconda3\Scripts
  140. Using d:\anaconda3\lib\site-packages
  141. Searching for scipy==1.1.0
  142. Best match: scipy 1.1.0
  143. Adding scipy 1.1.0 to easy-install.pth file
  144. Using d:\anaconda3\lib\site-packages
  145. Searching for numpy==1.15.4
  146. Best match: numpy 1.15.4
  147. Adding numpy 1.15.4 to easy-install.pth file
  148. Using d:\anaconda3\lib\site-packages
  149. 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

(完)