dnt 0.2.4__py3-none-any.whl → 0.3.1.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. dnt/__init__.py +3 -2
  2. dnt/analysis/__init__.py +3 -2
  3. dnt/analysis/count.py +54 -37
  4. dnt/analysis/interaction2.py +518 -0
  5. dnt/analysis/stop.py +22 -17
  6. dnt/analysis/stop2.py +289 -0
  7. dnt/analysis/stop3.py +758 -0
  8. dnt/detect/signal/detector.py +326 -0
  9. dnt/detect/timestamp.py +105 -0
  10. dnt/detect/yolov8/detector.py +179 -36
  11. dnt/detect/yolov8/segmentor.py +60 -2
  12. dnt/engine/__init__.py +8 -0
  13. dnt/engine/bbox_interp.py +83 -0
  14. dnt/engine/bbox_iou.py +20 -0
  15. dnt/engine/cluster.py +31 -0
  16. dnt/engine/iob.py +66 -0
  17. dnt/filter/filter.py +333 -2
  18. dnt/label/labeler.py +4 -4
  19. dnt/label/labeler2.py +631 -0
  20. dnt/shared/__init__.py +2 -1
  21. dnt/shared/data/coco.names +0 -0
  22. dnt/shared/data/openimages.names +0 -0
  23. dnt/shared/data/voc.names +0 -0
  24. dnt/shared/download.py +12 -0
  25. dnt/shared/synhcro.py +150 -0
  26. dnt/shared/util.py +17 -4
  27. dnt/third_party/fast-reid/__init__.py +1 -0
  28. dnt/third_party/fast-reid/configs/Base-AGW.yml +19 -0
  29. dnt/third_party/fast-reid/configs/Base-MGN.yml +12 -0
  30. dnt/third_party/fast-reid/configs/Base-SBS.yml +63 -0
  31. dnt/third_party/fast-reid/configs/Base-bagtricks.yml +76 -0
  32. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R101-ibn.yml +12 -0
  33. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50-ibn.yml +11 -0
  34. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50.yml +7 -0
  35. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_S50.yml +11 -0
  36. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R101-ibn.yml +12 -0
  37. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50-ibn.yml +11 -0
  38. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50.yml +7 -0
  39. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_S50.yml +11 -0
  40. dnt/third_party/fast-reid/configs/DukeMTMC/mgn_R50-ibn.yml +11 -0
  41. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R101-ibn.yml +12 -0
  42. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50-ibn.yml +11 -0
  43. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50.yml +7 -0
  44. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_S50.yml +11 -0
  45. dnt/third_party/fast-reid/configs/MOT17/AGW_R101-ibn.yml +12 -0
  46. dnt/third_party/fast-reid/configs/MOT17/AGW_R50-ibn.yml +11 -0
  47. dnt/third_party/fast-reid/configs/MOT17/AGW_R50.yml +7 -0
  48. dnt/third_party/fast-reid/configs/MOT17/AGW_S50.yml +11 -0
  49. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R101-ibn.yml +12 -0
  50. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50-ibn.yml +11 -0
  51. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50.yml +7 -0
  52. dnt/third_party/fast-reid/configs/MOT17/bagtricks_S50.yml +11 -0
  53. dnt/third_party/fast-reid/configs/MOT17/mgn_R50-ibn.yml +11 -0
  54. dnt/third_party/fast-reid/configs/MOT17/sbs_R101-ibn.yml +12 -0
  55. dnt/third_party/fast-reid/configs/MOT17/sbs_R50-ibn.yml +11 -0
  56. dnt/third_party/fast-reid/configs/MOT17/sbs_R50.yml +7 -0
  57. dnt/third_party/fast-reid/configs/MOT17/sbs_S50.yml +11 -0
  58. dnt/third_party/fast-reid/configs/MOT20/AGW_R101-ibn.yml +12 -0
  59. dnt/third_party/fast-reid/configs/MOT20/AGW_R50-ibn.yml +11 -0
  60. dnt/third_party/fast-reid/configs/MOT20/AGW_R50.yml +7 -0
  61. dnt/third_party/fast-reid/configs/MOT20/AGW_S50.yml +11 -0
  62. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R101-ibn.yml +12 -0
  63. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50-ibn.yml +11 -0
  64. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50.yml +7 -0
  65. dnt/third_party/fast-reid/configs/MOT20/bagtricks_S50.yml +11 -0
  66. dnt/third_party/fast-reid/configs/MOT20/mgn_R50-ibn.yml +11 -0
  67. dnt/third_party/fast-reid/configs/MOT20/sbs_R101-ibn.yml +12 -0
  68. dnt/third_party/fast-reid/configs/MOT20/sbs_R50-ibn.yml +11 -0
  69. dnt/third_party/fast-reid/configs/MOT20/sbs_R50.yml +7 -0
  70. dnt/third_party/fast-reid/configs/MOT20/sbs_S50.yml +11 -0
  71. dnt/third_party/fast-reid/configs/MSMT17/AGW_R101-ibn.yml +12 -0
  72. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50-ibn.yml +11 -0
  73. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50.yml +7 -0
  74. dnt/third_party/fast-reid/configs/MSMT17/AGW_S50.yml +11 -0
  75. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R101-ibn.yml +13 -0
  76. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50-ibn.yml +12 -0
  77. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50.yml +7 -0
  78. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_S50.yml +12 -0
  79. dnt/third_party/fast-reid/configs/MSMT17/mgn_R50-ibn.yml +11 -0
  80. dnt/third_party/fast-reid/configs/MSMT17/sbs_R101-ibn.yml +12 -0
  81. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50-ibn.yml +11 -0
  82. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50.yml +7 -0
  83. dnt/third_party/fast-reid/configs/MSMT17/sbs_S50.yml +11 -0
  84. dnt/third_party/fast-reid/configs/Market1501/AGW_R101-ibn.yml +12 -0
  85. dnt/third_party/fast-reid/configs/Market1501/AGW_R50-ibn.yml +11 -0
  86. dnt/third_party/fast-reid/configs/Market1501/AGW_R50.yml +7 -0
  87. dnt/third_party/fast-reid/configs/Market1501/AGW_S50.yml +11 -0
  88. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R101-ibn.yml +12 -0
  89. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50-ibn.yml +11 -0
  90. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50.yml +7 -0
  91. dnt/third_party/fast-reid/configs/Market1501/bagtricks_S50.yml +11 -0
  92. dnt/third_party/fast-reid/configs/Market1501/bagtricks_vit.yml +88 -0
  93. dnt/third_party/fast-reid/configs/Market1501/mgn_R50-ibn.yml +11 -0
  94. dnt/third_party/fast-reid/configs/Market1501/sbs_R101-ibn.yml +12 -0
  95. dnt/third_party/fast-reid/configs/Market1501/sbs_R50-ibn.yml +11 -0
  96. dnt/third_party/fast-reid/configs/Market1501/sbs_R50.yml +7 -0
  97. dnt/third_party/fast-reid/configs/Market1501/sbs_S50.yml +11 -0
  98. dnt/third_party/fast-reid/configs/VERIWild/bagtricks_R50-ibn.yml +35 -0
  99. dnt/third_party/fast-reid/configs/VeRi/sbs_R50-ibn.yml +35 -0
  100. dnt/third_party/fast-reid/configs/VehicleID/bagtricks_R50-ibn.yml +36 -0
  101. dnt/third_party/fast-reid/configs/__init__.py +0 -0
  102. dnt/third_party/fast-reid/fast_reid_interfece.py +175 -0
  103. dnt/third_party/fast-reid/fastreid/__init__.py +6 -0
  104. dnt/third_party/fast-reid/fastreid/config/__init__.py +15 -0
  105. dnt/third_party/fast-reid/fastreid/config/config.py +319 -0
  106. dnt/third_party/fast-reid/fastreid/config/defaults.py +329 -0
  107. dnt/third_party/fast-reid/fastreid/data/__init__.py +17 -0
  108. dnt/third_party/fast-reid/fastreid/data/build.py +194 -0
  109. dnt/third_party/fast-reid/fastreid/data/common.py +58 -0
  110. dnt/third_party/fast-reid/fastreid/data/data_utils.py +202 -0
  111. dnt/third_party/fast-reid/fastreid/data/datasets/AirportALERT.py +50 -0
  112. dnt/third_party/fast-reid/fastreid/data/datasets/__init__.py +43 -0
  113. dnt/third_party/fast-reid/fastreid/data/datasets/bases.py +183 -0
  114. dnt/third_party/fast-reid/fastreid/data/datasets/caviara.py +44 -0
  115. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk03.py +274 -0
  116. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk_sysu.py +58 -0
  117. dnt/third_party/fast-reid/fastreid/data/datasets/dukemtmcreid.py +70 -0
  118. dnt/third_party/fast-reid/fastreid/data/datasets/grid.py +44 -0
  119. dnt/third_party/fast-reid/fastreid/data/datasets/iLIDS.py +45 -0
  120. dnt/third_party/fast-reid/fastreid/data/datasets/lpw.py +49 -0
  121. dnt/third_party/fast-reid/fastreid/data/datasets/market1501.py +89 -0
  122. dnt/third_party/fast-reid/fastreid/data/datasets/msmt17.py +114 -0
  123. dnt/third_party/fast-reid/fastreid/data/datasets/pes3d.py +44 -0
  124. dnt/third_party/fast-reid/fastreid/data/datasets/pku.py +44 -0
  125. dnt/third_party/fast-reid/fastreid/data/datasets/prai.py +43 -0
  126. dnt/third_party/fast-reid/fastreid/data/datasets/prid.py +41 -0
  127. dnt/third_party/fast-reid/fastreid/data/datasets/saivt.py +47 -0
  128. dnt/third_party/fast-reid/fastreid/data/datasets/sensereid.py +47 -0
  129. dnt/third_party/fast-reid/fastreid/data/datasets/shinpuhkan.py +48 -0
  130. dnt/third_party/fast-reid/fastreid/data/datasets/sysu_mm.py +47 -0
  131. dnt/third_party/fast-reid/fastreid/data/datasets/thermalworld.py +43 -0
  132. dnt/third_party/fast-reid/fastreid/data/datasets/vehicleid.py +126 -0
  133. dnt/third_party/fast-reid/fastreid/data/datasets/veri.py +69 -0
  134. dnt/third_party/fast-reid/fastreid/data/datasets/veriwild.py +140 -0
  135. dnt/third_party/fast-reid/fastreid/data/datasets/viper.py +45 -0
  136. dnt/third_party/fast-reid/fastreid/data/datasets/wildtracker.py +59 -0
  137. dnt/third_party/fast-reid/fastreid/data/samplers/__init__.py +18 -0
  138. dnt/third_party/fast-reid/fastreid/data/samplers/data_sampler.py +85 -0
  139. dnt/third_party/fast-reid/fastreid/data/samplers/imbalance_sampler.py +67 -0
  140. dnt/third_party/fast-reid/fastreid/data/samplers/triplet_sampler.py +260 -0
  141. dnt/third_party/fast-reid/fastreid/data/transforms/__init__.py +11 -0
  142. dnt/third_party/fast-reid/fastreid/data/transforms/autoaugment.py +806 -0
  143. dnt/third_party/fast-reid/fastreid/data/transforms/build.py +100 -0
  144. dnt/third_party/fast-reid/fastreid/data/transforms/functional.py +180 -0
  145. dnt/third_party/fast-reid/fastreid/data/transforms/transforms.py +161 -0
  146. dnt/third_party/fast-reid/fastreid/engine/__init__.py +15 -0
  147. dnt/third_party/fast-reid/fastreid/engine/defaults.py +490 -0
  148. dnt/third_party/fast-reid/fastreid/engine/hooks.py +534 -0
  149. dnt/third_party/fast-reid/fastreid/engine/launch.py +103 -0
  150. dnt/third_party/fast-reid/fastreid/engine/train_loop.py +357 -0
  151. dnt/third_party/fast-reid/fastreid/evaluation/__init__.py +6 -0
  152. dnt/third_party/fast-reid/fastreid/evaluation/clas_evaluator.py +81 -0
  153. dnt/third_party/fast-reid/fastreid/evaluation/evaluator.py +176 -0
  154. dnt/third_party/fast-reid/fastreid/evaluation/query_expansion.py +46 -0
  155. dnt/third_party/fast-reid/fastreid/evaluation/rank.py +200 -0
  156. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/__init__.py +20 -0
  157. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/setup.py +32 -0
  158. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/test_cython.py +106 -0
  159. dnt/third_party/fast-reid/fastreid/evaluation/reid_evaluation.py +143 -0
  160. dnt/third_party/fast-reid/fastreid/evaluation/rerank.py +73 -0
  161. dnt/third_party/fast-reid/fastreid/evaluation/roc.py +90 -0
  162. dnt/third_party/fast-reid/fastreid/evaluation/testing.py +88 -0
  163. dnt/third_party/fast-reid/fastreid/layers/__init__.py +19 -0
  164. dnt/third_party/fast-reid/fastreid/layers/activation.py +59 -0
  165. dnt/third_party/fast-reid/fastreid/layers/any_softmax.py +80 -0
  166. dnt/third_party/fast-reid/fastreid/layers/batch_norm.py +205 -0
  167. dnt/third_party/fast-reid/fastreid/layers/context_block.py +113 -0
  168. dnt/third_party/fast-reid/fastreid/layers/drop.py +161 -0
  169. dnt/third_party/fast-reid/fastreid/layers/frn.py +199 -0
  170. dnt/third_party/fast-reid/fastreid/layers/gather_layer.py +30 -0
  171. dnt/third_party/fast-reid/fastreid/layers/helpers.py +31 -0
  172. dnt/third_party/fast-reid/fastreid/layers/non_local.py +54 -0
  173. dnt/third_party/fast-reid/fastreid/layers/pooling.py +124 -0
  174. dnt/third_party/fast-reid/fastreid/layers/se_layer.py +25 -0
  175. dnt/third_party/fast-reid/fastreid/layers/splat.py +109 -0
  176. dnt/third_party/fast-reid/fastreid/layers/weight_init.py +122 -0
  177. dnt/third_party/fast-reid/fastreid/modeling/__init__.py +23 -0
  178. dnt/third_party/fast-reid/fastreid/modeling/backbones/__init__.py +18 -0
  179. dnt/third_party/fast-reid/fastreid/modeling/backbones/build.py +27 -0
  180. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenet.py +195 -0
  181. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenetv3.py +283 -0
  182. dnt/third_party/fast-reid/fastreid/modeling/backbones/osnet.py +525 -0
  183. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/__init__.py +4 -0
  184. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/config.py +396 -0
  185. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B0_dds_8gpu.yaml +27 -0
  186. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B1_dds_8gpu.yaml +27 -0
  187. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B2_dds_8gpu.yaml +27 -0
  188. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B3_dds_8gpu.yaml +27 -0
  189. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B4_dds_8gpu.yaml +27 -0
  190. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B5_dds_8gpu.yaml +27 -0
  191. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet.py +281 -0
  192. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnet.py +596 -0
  193. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-1.6GF_dds_8gpu.yaml +26 -0
  194. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-12GF_dds_8gpu.yaml +26 -0
  195. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-16GF_dds_8gpu.yaml +26 -0
  196. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-200MF_dds_8gpu.yaml +26 -0
  197. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-3.2GF_dds_8gpu.yaml +26 -0
  198. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-32GF_dds_8gpu.yaml +26 -0
  199. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-4.0GF_dds_8gpu.yaml +26 -0
  200. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-400MF_dds_8gpu.yaml +26 -0
  201. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-6.4GF_dds_8gpu.yaml +26 -0
  202. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-600MF_dds_8gpu.yaml +26 -0
  203. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-8.0GF_dds_8gpu.yaml +26 -0
  204. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-800MF_dds_8gpu.yaml +26 -0
  205. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-1.6GF_dds_8gpu.yaml +27 -0
  206. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-12GF_dds_8gpu.yaml +27 -0
  207. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-16GF_dds_8gpu.yaml +27 -0
  208. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-200MF_dds_8gpu.yaml +26 -0
  209. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-3.2GF_dds_8gpu.yaml +27 -0
  210. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-32GF_dds_8gpu.yaml +27 -0
  211. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-4.0GF_dds_8gpu.yaml +27 -0
  212. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-400MF_dds_8gpu.yaml +27 -0
  213. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-6.4GF_dds_8gpu.yaml +27 -0
  214. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-600MF_dds_8gpu.yaml +27 -0
  215. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-8.0GF_dds_8gpu.yaml +27 -0
  216. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-800MF_dds_8gpu.yaml +27 -0
  217. dnt/third_party/fast-reid/fastreid/modeling/backbones/repvgg.py +309 -0
  218. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnest.py +365 -0
  219. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnet.py +364 -0
  220. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnext.py +335 -0
  221. dnt/third_party/fast-reid/fastreid/modeling/backbones/shufflenet.py +203 -0
  222. dnt/third_party/fast-reid/fastreid/modeling/backbones/vision_transformer.py +399 -0
  223. dnt/third_party/fast-reid/fastreid/modeling/heads/__init__.py +11 -0
  224. dnt/third_party/fast-reid/fastreid/modeling/heads/build.py +25 -0
  225. dnt/third_party/fast-reid/fastreid/modeling/heads/clas_head.py +36 -0
  226. dnt/third_party/fast-reid/fastreid/modeling/heads/embedding_head.py +151 -0
  227. dnt/third_party/fast-reid/fastreid/modeling/losses/__init__.py +12 -0
  228. dnt/third_party/fast-reid/fastreid/modeling/losses/circle_loss.py +71 -0
  229. dnt/third_party/fast-reid/fastreid/modeling/losses/cross_entroy_loss.py +54 -0
  230. dnt/third_party/fast-reid/fastreid/modeling/losses/focal_loss.py +92 -0
  231. dnt/third_party/fast-reid/fastreid/modeling/losses/triplet_loss.py +113 -0
  232. dnt/third_party/fast-reid/fastreid/modeling/losses/utils.py +48 -0
  233. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/__init__.py +14 -0
  234. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/baseline.py +188 -0
  235. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/build.py +26 -0
  236. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/distiller.py +140 -0
  237. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/mgn.py +394 -0
  238. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/moco.py +126 -0
  239. dnt/third_party/fast-reid/fastreid/solver/__init__.py +8 -0
  240. dnt/third_party/fast-reid/fastreid/solver/build.py +348 -0
  241. dnt/third_party/fast-reid/fastreid/solver/lr_scheduler.py +66 -0
  242. dnt/third_party/fast-reid/fastreid/solver/optim/__init__.py +10 -0
  243. dnt/third_party/fast-reid/fastreid/solver/optim/lamb.py +123 -0
  244. dnt/third_party/fast-reid/fastreid/solver/optim/radam.py +149 -0
  245. dnt/third_party/fast-reid/fastreid/solver/optim/swa.py +246 -0
  246. dnt/third_party/fast-reid/fastreid/utils/__init__.py +6 -0
  247. dnt/third_party/fast-reid/fastreid/utils/checkpoint.py +503 -0
  248. dnt/third_party/fast-reid/fastreid/utils/collect_env.py +158 -0
  249. dnt/third_party/fast-reid/fastreid/utils/comm.py +255 -0
  250. dnt/third_party/fast-reid/fastreid/utils/compute_dist.py +200 -0
  251. dnt/third_party/fast-reid/fastreid/utils/env.py +119 -0
  252. dnt/third_party/fast-reid/fastreid/utils/events.py +461 -0
  253. dnt/third_party/fast-reid/fastreid/utils/faiss_utils.py +127 -0
  254. dnt/third_party/fast-reid/fastreid/utils/file_io.py +520 -0
  255. dnt/third_party/fast-reid/fastreid/utils/history_buffer.py +71 -0
  256. dnt/third_party/fast-reid/fastreid/utils/logger.py +211 -0
  257. dnt/third_party/fast-reid/fastreid/utils/params.py +103 -0
  258. dnt/third_party/fast-reid/fastreid/utils/precision_bn.py +94 -0
  259. dnt/third_party/fast-reid/fastreid/utils/registry.py +66 -0
  260. dnt/third_party/fast-reid/fastreid/utils/summary.py +120 -0
  261. dnt/third_party/fast-reid/fastreid/utils/timer.py +68 -0
  262. dnt/third_party/fast-reid/fastreid/utils/visualizer.py +278 -0
  263. dnt/track/__init__.py +2 -0
  264. dnt/track/botsort/__init__.py +4 -0
  265. dnt/track/botsort/bot_tracker/__init__.py +3 -0
  266. dnt/track/botsort/bot_tracker/basetrack.py +60 -0
  267. dnt/track/botsort/bot_tracker/bot_sort.py +473 -0
  268. dnt/track/botsort/bot_tracker/gmc.py +316 -0
  269. dnt/track/botsort/bot_tracker/kalman_filter.py +269 -0
  270. dnt/track/botsort/bot_tracker/matching.py +194 -0
  271. dnt/track/botsort/bot_tracker/mc_bot_sort.py +505 -0
  272. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/evaluation.py +14 -4
  273. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/io.py +19 -36
  274. dnt/track/botsort/bot_tracker/tracking_utils/timer.py +37 -0
  275. dnt/track/botsort/inference.py +96 -0
  276. dnt/track/config.py +120 -0
  277. dnt/track/dsort/configs/bagtricks_R50.yml +7 -0
  278. dnt/track/dsort/configs/deep_sort.yaml +0 -0
  279. dnt/track/dsort/configs/fastreid.yaml +1 -1
  280. dnt/track/dsort/deep_sort/deep/checkpoint/ckpt.t7 +0 -0
  281. dnt/track/dsort/deep_sort/deep/feature_extractor.py +87 -8
  282. dnt/track/dsort/deep_sort/deep_sort.py +31 -20
  283. dnt/track/dsort/deep_sort/sort/detection.py +2 -1
  284. dnt/track/dsort/deep_sort/sort/iou_matching.py +0 -2
  285. dnt/track/dsort/deep_sort/sort/linear_assignment.py +0 -3
  286. dnt/track/dsort/deep_sort/sort/nn_matching.py +5 -5
  287. dnt/track/dsort/deep_sort/sort/preprocessing.py +1 -2
  288. dnt/track/dsort/deep_sort/sort/track.py +2 -1
  289. dnt/track/dsort/deep_sort/sort/tracker.py +1 -1
  290. dnt/track/dsort/dsort.py +43 -33
  291. dnt/track/re_class.py +117 -0
  292. dnt/track/sort/sort.py +9 -6
  293. dnt/track/tracker.py +213 -32
  294. dnt-0.3.1.8.dist-info/METADATA +117 -0
  295. dnt-0.3.1.8.dist-info/RECORD +315 -0
  296. {dnt-0.2.4.dist-info → dnt-0.3.1.8.dist-info}/WHEEL +1 -1
  297. dnt/analysis/yield.py +0 -9
  298. dnt/track/dsort/deep_sort/deep/evaluate.py +0 -15
  299. dnt/track/dsort/deep_sort/deep/original_model.py +0 -106
  300. dnt/track/dsort/deep_sort/deep/test.py +0 -77
  301. dnt/track/dsort/deep_sort/deep/train.py +0 -189
  302. dnt/track/dsort/utils/asserts.py +0 -13
  303. dnt/track/dsort/utils/draw.py +0 -36
  304. dnt/track/dsort/utils/json_logger.py +0 -383
  305. dnt/track/dsort/utils/log.py +0 -17
  306. dnt/track/dsort/utils/parser.py +0 -35
  307. dnt/track/dsort/utils/tools.py +0 -39
  308. dnt-0.2.4.dist-info/METADATA +0 -35
  309. dnt-0.2.4.dist-info/RECORD +0 -64
  310. /dnt/{track/dsort/utils → third_party/fast-reid/checkpoint}/__init__.py +0 -0
  311. {dnt-0.2.4.dist-info → dnt-0.3.1.8.dist-info/licenses}/LICENSE +0 -0
  312. {dnt-0.2.4.dist-info → dnt-0.3.1.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,200 @@
1
+ # credits: https://github.com/KaiyangZhou/deep-person-reid/blob/master/torchreid/metrics/rank.py
2
+
3
+ import warnings
4
+ from collections import defaultdict
5
+
6
+ import numpy as np
7
+
8
+ try:
9
+ from .rank_cylib.rank_cy import evaluate_cy
10
+
11
+ IS_CYTHON_AVAI = True
12
+ except ImportError:
13
+ IS_CYTHON_AVAI = False
14
+ warnings.warn(
15
+ 'Cython rank evaluation (very fast so highly recommended) is '
16
+ 'unavailable, now use python evaluation.'
17
+ )
18
+
19
+
20
+ def eval_cuhk03(distmat, q_pids, g_pids, q_camids, g_camids, max_rank):
21
+ """Evaluation with cuhk03 metric
22
+ Key: one image for each gallery identity is randomly sampled for each query identity.
23
+ Random sampling is performed num_repeats times.
24
+ """
25
+ num_repeats = 10
26
+
27
+ num_q, num_g = distmat.shape
28
+
29
+ indices = np.argsort(distmat, axis=1)
30
+
31
+ if num_g < max_rank:
32
+ max_rank = num_g
33
+ print(
34
+ 'Note: number of gallery samples is quite small, got {}'.
35
+ format(num_g)
36
+ )
37
+
38
+ matches = (g_pids[indices] == q_pids[:, np.newaxis]).astype(np.int32)
39
+
40
+ # compute cmc curve for each query
41
+ all_cmc = []
42
+ all_AP = []
43
+ num_valid_q = 0. # number of valid query
44
+
45
+ for q_idx in range(num_q):
46
+ # get query pid and camid
47
+ q_pid = q_pids[q_idx]
48
+ q_camid = q_camids[q_idx]
49
+
50
+ # remove gallery samples that have the same pid and camid with query
51
+ order = indices[q_idx]
52
+ remove = (g_pids[order] == q_pid) & (g_camids[order] == q_camid)
53
+ keep = np.invert(remove)
54
+
55
+ # compute cmc curve
56
+ raw_cmc = matches[q_idx][
57
+ keep] # binary vector, positions with value 1 are correct matches
58
+ if not np.any(raw_cmc):
59
+ # this condition is true when query identity does not appear in gallery
60
+ continue
61
+
62
+ kept_g_pids = g_pids[order][keep]
63
+ g_pids_dict = defaultdict(list)
64
+ for idx, pid in enumerate(kept_g_pids):
65
+ g_pids_dict[pid].append(idx)
66
+
67
+ cmc = 0.
68
+ for repeat_idx in range(num_repeats):
69
+ mask = np.zeros(len(raw_cmc), dtype=np.bool)
70
+ for _, idxs in g_pids_dict.items():
71
+ # randomly sample one image for each gallery person
72
+ rnd_idx = np.random.choice(idxs)
73
+ mask[rnd_idx] = True
74
+ masked_raw_cmc = raw_cmc[mask]
75
+ _cmc = masked_raw_cmc.cumsum()
76
+ _cmc[_cmc > 1] = 1
77
+ cmc += _cmc[:max_rank].astype(np.float32)
78
+
79
+ cmc /= num_repeats
80
+ all_cmc.append(cmc)
81
+ # compute AP
82
+ num_rel = raw_cmc.sum()
83
+ tmp_cmc = raw_cmc.cumsum()
84
+ tmp_cmc = [x / (i + 1.) for i, x in enumerate(tmp_cmc)]
85
+ tmp_cmc = np.asarray(tmp_cmc) * raw_cmc
86
+ AP = tmp_cmc.sum() / num_rel
87
+ all_AP.append(AP)
88
+ num_valid_q += 1.
89
+
90
+ assert num_valid_q > 0, 'Error: all query identities do not appear in gallery'
91
+
92
+ all_cmc = np.asarray(all_cmc).astype(np.float32)
93
+ all_cmc = all_cmc.sum(0) / num_valid_q
94
+ mAP = np.mean(all_AP)
95
+
96
+ return all_cmc, mAP
97
+
98
+
99
+ def eval_market1501(distmat, q_pids, g_pids, q_camids, g_camids, max_rank):
100
+ """Evaluation with market1501 metric
101
+ Key: for each query identity, its gallery images from the same camera view are discarded.
102
+ """
103
+ num_q, num_g = distmat.shape
104
+
105
+ if num_g < max_rank:
106
+ max_rank = num_g
107
+ print('Note: number of gallery samples is quite small, got {}'.format(num_g))
108
+
109
+ indices = np.argsort(distmat, axis=1)
110
+ # compute cmc curve for each query
111
+ all_cmc = []
112
+ all_AP = []
113
+ all_INP = []
114
+ num_valid_q = 0. # number of valid query
115
+
116
+ for q_idx in range(num_q):
117
+ # get query pid and camid
118
+ q_pid = q_pids[q_idx]
119
+ q_camid = q_camids[q_idx]
120
+
121
+ # remove gallery samples that have the same pid and camid with query
122
+ order = indices[q_idx]
123
+ remove = (g_pids[order] == q_pid) & (g_camids[order] == q_camid)
124
+ keep = np.invert(remove)
125
+
126
+ # compute cmc curve
127
+ matches = (g_pids[order] == q_pid).astype(np.int32)
128
+ raw_cmc = matches[keep] # binary vector, positions with value 1 are correct matches
129
+ if not np.any(raw_cmc):
130
+ # this condition is true when query identity does not appear in gallery
131
+ continue
132
+
133
+ cmc = raw_cmc.cumsum()
134
+
135
+ pos_idx = np.where(raw_cmc == 1)
136
+ max_pos_idx = np.max(pos_idx)
137
+ inp = cmc[max_pos_idx] / (max_pos_idx + 1.0)
138
+ all_INP.append(inp)
139
+
140
+ cmc[cmc > 1] = 1
141
+
142
+ all_cmc.append(cmc[:max_rank])
143
+ num_valid_q += 1.
144
+
145
+ # compute average precision
146
+ # reference: https://en.wikipedia.org/wiki/Evaluation_measures_(information_retrieval)#Average_precision
147
+ num_rel = raw_cmc.sum()
148
+ tmp_cmc = raw_cmc.cumsum()
149
+ tmp_cmc = [x / (i + 1.) for i, x in enumerate(tmp_cmc)]
150
+ tmp_cmc = np.asarray(tmp_cmc) * raw_cmc
151
+ AP = tmp_cmc.sum() / num_rel
152
+ all_AP.append(AP)
153
+
154
+ assert num_valid_q > 0, 'Error: all query identities do not appear in gallery'
155
+
156
+ all_cmc = np.asarray(all_cmc).astype(np.float32)
157
+ all_cmc = all_cmc.sum(0) / num_valid_q
158
+
159
+ return all_cmc, all_AP, all_INP
160
+
161
+
162
+ def evaluate_py(distmat, q_pids, g_pids, q_camids, g_camids, max_rank, use_metric_cuhk03):
163
+ if use_metric_cuhk03:
164
+ return eval_cuhk03(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
165
+ else:
166
+ return eval_market1501(distmat, q_pids, g_pids, q_camids, g_camids, max_rank)
167
+
168
+
169
+ def evaluate_rank(
170
+ distmat,
171
+ q_pids,
172
+ g_pids,
173
+ q_camids,
174
+ g_camids,
175
+ max_rank=50,
176
+ use_metric_cuhk03=False,
177
+ use_cython=True,
178
+ ):
179
+ """Evaluates CMC rank.
180
+ Args:
181
+ distmat (numpy.ndarray): distance matrix of shape (num_query, num_gallery).
182
+ q_pids (numpy.ndarray): 1-D array containing person identities
183
+ of each query instance.
184
+ g_pids (numpy.ndarray): 1-D array containing person identities
185
+ of each gallery instance.
186
+ q_camids (numpy.ndarray): 1-D array containing camera views under
187
+ which each query instance is captured.
188
+ g_camids (numpy.ndarray): 1-D array containing camera views under
189
+ which each gallery instance is captured.
190
+ max_rank (int, optional): maximum CMC rank to be computed. Default is 50.
191
+ use_metric_cuhk03 (bool, optional): use single-gallery-shot setting for cuhk03.
192
+ Default is False. This should be enabled when using cuhk03 classic split.
193
+ use_cython (bool, optional): use cython code for evaluation. Default is True.
194
+ This is highly recommended as the cython code can speed up the cmc computation
195
+ by more than 10x. This requires Cython to be installed.
196
+ """
197
+ if use_cython and IS_CYTHON_AVAI:
198
+ return evaluate_cy(distmat, q_pids, g_pids, q_camids, g_camids, max_rank, use_metric_cuhk03)
199
+ else:
200
+ return evaluate_py(distmat, q_pids, g_pids, q_camids, g_camids, max_rank, use_metric_cuhk03)
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ """
3
+ @author: liaoxingyu
4
+ @contact: sherlockliao01@gmail.com
5
+ """
6
+
7
+
8
+ def compile_helper():
9
+ """Compile helper function at runtime. Make sure this
10
+ is invoked on a single process."""
11
+ import os
12
+ import subprocess
13
+
14
+ path = os.path.abspath(os.path.dirname(__file__))
15
+ ret = subprocess.run(["make", "-C", path])
16
+ if ret.returncode != 0:
17
+ print("Making cython reid evaluation module failed, exiting.")
18
+ import sys
19
+
20
+ sys.exit(1)
@@ -0,0 +1,32 @@
1
+ from distutils.core import setup
2
+ from distutils.extension import Extension
3
+
4
+ import numpy as np
5
+ from Cython.Build import cythonize
6
+
7
+
8
+ def numpy_include():
9
+ try:
10
+ numpy_include = np.get_include()
11
+ except AttributeError:
12
+ numpy_include = np.get_numpy_include()
13
+ return numpy_include
14
+
15
+
16
+ ext_modules = [
17
+ Extension(
18
+ 'rank_cy',
19
+ ['rank_cy.pyx'],
20
+ include_dirs=[numpy_include()],
21
+ ),
22
+ Extension(
23
+ 'roc_cy',
24
+ ['roc_cy.pyx'],
25
+ include_dirs=[numpy_include()],
26
+ )
27
+ ]
28
+
29
+ setup(
30
+ name='Cython-based reid evaluation code',
31
+ ext_modules=cythonize(ext_modules)
32
+ )
@@ -0,0 +1,106 @@
1
+ import sys
2
+ import timeit
3
+ import numpy as np
4
+ import os.path as osp
5
+
6
+ sys.path.insert(0, osp.dirname(osp.abspath(__file__)) + '/../../..')
7
+
8
+ from fastreid.evaluation.rank import evaluate_rank
9
+ from fastreid.evaluation.roc import evaluate_roc
10
+
11
+ """
12
+ Test the speed of cython-based evaluation code. The speed improvements
13
+ can be much bigger when using the real reid data, which contains a larger
14
+ amount of query and gallery images.
15
+ Note: you might encounter the following error:
16
+ 'AssertionError: Error: all query identities do not appear in gallery'.
17
+ This is normal because the inputs are random numbers. Just try again.
18
+ """
19
+
20
+ print('*** Compare running time ***')
21
+
22
+ setup = '''
23
+ import sys
24
+ import os.path as osp
25
+ import numpy as np
26
+ sys.path.insert(0, osp.dirname(osp.abspath(__file__)) + '/../../..')
27
+ from fastreid.evaluation.rank import evaluate_rank
28
+ from fastreid.evaluation.roc import evaluate_roc
29
+ num_q = 30
30
+ num_g = 300
31
+ dim = 512
32
+ max_rank = 5
33
+ q_feats = np.random.rand(num_q, dim).astype(np.float32) * 20
34
+ q_feats = q_feats / np.linalg.norm(q_feats, ord=2, axis=1, keepdims=True)
35
+ g_feats = np.random.rand(num_g, dim).astype(np.float32) * 20
36
+ g_feats = g_feats / np.linalg.norm(g_feats, ord=2, axis=1, keepdims=True)
37
+ distmat = 1 - np.dot(q_feats, g_feats.transpose())
38
+ q_pids = np.random.randint(0, num_q, size=num_q)
39
+ g_pids = np.random.randint(0, num_g, size=num_g)
40
+ q_camids = np.random.randint(0, 5, size=num_q)
41
+ g_camids = np.random.randint(0, 5, size=num_g)
42
+ '''
43
+
44
+ print('=> Using CMC metric')
45
+ pytime = timeit.timeit(
46
+ 'evaluate_rank(distmat, q_pids, g_pids, q_camids, g_camids, max_rank, use_cython=False)',
47
+ setup=setup,
48
+ number=20
49
+ )
50
+ cytime = timeit.timeit(
51
+ 'evaluate_rank(distmat, q_pids, g_pids, q_camids, g_camids, max_rank, use_cython=True)',
52
+ setup=setup,
53
+ number=20
54
+ )
55
+ print('Python time: {} s'.format(pytime))
56
+ print('Cython time: {} s'.format(cytime))
57
+ print('CMC Cython is {} times faster than python\n'.format(pytime / cytime))
58
+
59
+ print('=> Using ROC metric')
60
+ pytime = timeit.timeit(
61
+ 'evaluate_roc(distmat, q_pids, g_pids, q_camids, g_camids, use_cython=False)',
62
+ setup=setup,
63
+ number=20
64
+ )
65
+ cytime = timeit.timeit(
66
+ 'evaluate_roc(distmat, q_pids, g_pids, q_camids, g_camids, use_cython=True)',
67
+ setup=setup,
68
+ number=20
69
+ )
70
+ print('Python time: {} s'.format(pytime))
71
+ print('Cython time: {} s'.format(cytime))
72
+ print('ROC Cython is {} times faster than python\n'.format(pytime / cytime))
73
+
74
+ print("=> Check precision")
75
+ num_q = 30
76
+ num_g = 300
77
+ dim = 512
78
+ max_rank = 5
79
+ q_feats = np.random.rand(num_q, dim).astype(np.float32) * 20
80
+ q_feats = q_feats / np.linalg.norm(q_feats, ord=2, axis=1, keepdims=True)
81
+ g_feats = np.random.rand(num_g, dim).astype(np.float32) * 20
82
+ g_feats = g_feats / np.linalg.norm(g_feats, ord=2, axis=1, keepdims=True)
83
+ distmat = 1 - np.dot(q_feats, g_feats.transpose())
84
+ q_pids = np.random.randint(0, num_q, size=num_q)
85
+ g_pids = np.random.randint(0, num_g, size=num_g)
86
+ q_camids = np.random.randint(0, 5, size=num_q)
87
+ g_camids = np.random.randint(0, 5, size=num_g)
88
+
89
+ cmc_py, mAP_py, mINP_py = evaluate_rank(distmat, q_pids, g_pids, q_camids, g_camids, max_rank, use_cython=False)
90
+
91
+ cmc_cy, mAP_cy, mINP_cy = evaluate_rank(distmat, q_pids, g_pids, q_camids, g_camids, max_rank, use_cython=True)
92
+
93
+ np.testing.assert_allclose(cmc_py, cmc_cy, rtol=1e-3, atol=1e-6)
94
+ np.testing.assert_allclose(mAP_py, mAP_cy, rtol=1e-3, atol=1e-6)
95
+ np.testing.assert_allclose(mINP_py, mINP_cy, rtol=1e-3, atol=1e-6)
96
+ print('Rank results between python and cython are the same!')
97
+
98
+ scores_cy, labels_cy = evaluate_roc(distmat, q_pids, g_pids, q_camids, g_camids, use_cython=True)
99
+ scores_py, labels_py = evaluate_roc(distmat, q_pids, g_pids, q_camids, g_camids, use_cython=False)
100
+
101
+ np.testing.assert_allclose(scores_cy, scores_py, rtol=1e-3, atol=1e-6)
102
+ np.testing.assert_allclose(labels_cy, labels_py, rtol=1e-3, atol=1e-6)
103
+ print('ROC results between python and cython are the same!\n')
104
+
105
+ print("=> Check exact values")
106
+ print("mAP = {} \ncmc = {}\nmINP = {}\nScores = {}".format(np.array(mAP_cy), cmc_cy, np.array(mINP_cy), scores_cy))
@@ -0,0 +1,143 @@
1
+ # encoding: utf-8
2
+ """
3
+ @author: liaoxingyu
4
+ @contact: sherlockliao01@gmail.com
5
+ """
6
+ import copy
7
+ import logging
8
+ import time
9
+ import itertools
10
+ from collections import OrderedDict
11
+
12
+ import numpy as np
13
+ import torch
14
+ import torch.nn.functional as F
15
+ from sklearn import metrics
16
+
17
+ from fastreid.utils import comm
18
+ from fastreid.utils.compute_dist import build_dist
19
+ from .evaluator import DatasetEvaluator
20
+ from .query_expansion import aqe
21
+ from .rank_cylib import compile_helper
22
+
23
+ logger = logging.getLogger(__name__)
24
+
25
+
26
+ class ReidEvaluator(DatasetEvaluator):
27
+ def __init__(self, cfg, num_query, output_dir=None):
28
+ self.cfg = cfg
29
+ self._num_query = num_query
30
+ self._output_dir = output_dir
31
+
32
+ self._cpu_device = torch.device('cpu')
33
+
34
+ self._predictions = []
35
+ self._compile_dependencies()
36
+
37
+ def reset(self):
38
+ self._predictions = []
39
+
40
+ def process(self, inputs, outputs):
41
+ prediction = {
42
+ 'feats': outputs.to(self._cpu_device, torch.float32),
43
+ 'pids': inputs['targets'].to(self._cpu_device),
44
+ 'camids': inputs['camids'].to(self._cpu_device)
45
+
46
+ }
47
+ self._predictions.append(prediction)
48
+
49
+ def evaluate(self):
50
+ if comm.get_world_size() > 1:
51
+ comm.synchronize()
52
+ predictions = comm.gather(self._predictions, dst=0)
53
+ predictions = list(itertools.chain(*predictions))
54
+
55
+ if not comm.is_main_process():
56
+ return {}
57
+
58
+ else:
59
+ predictions = self._predictions
60
+
61
+ features = []
62
+ pids = []
63
+ camids = []
64
+ for prediction in predictions:
65
+ features.append(prediction['feats'])
66
+ pids.append(prediction['pids'])
67
+ camids.append(prediction['camids'])
68
+
69
+ features = torch.cat(features, dim=0)
70
+ pids = torch.cat(pids, dim=0).numpy()
71
+ camids = torch.cat(camids, dim=0).numpy()
72
+ # query feature, person ids and camera ids
73
+ query_features = features[:self._num_query]
74
+ query_pids = pids[:self._num_query]
75
+ query_camids = camids[:self._num_query]
76
+
77
+ # gallery features, person ids and camera ids
78
+ gallery_features = features[self._num_query:]
79
+ gallery_pids = pids[self._num_query:]
80
+ gallery_camids = camids[self._num_query:]
81
+
82
+ self._results = OrderedDict()
83
+
84
+ if self.cfg.TEST.AQE.ENABLED:
85
+ logger.info("Test with AQE setting")
86
+ qe_time = self.cfg.TEST.AQE.QE_TIME
87
+ qe_k = self.cfg.TEST.AQE.QE_K
88
+ alpha = self.cfg.TEST.AQE.ALPHA
89
+ query_features, gallery_features = aqe(query_features, gallery_features, qe_time, qe_k, alpha)
90
+
91
+ dist = build_dist(query_features, gallery_features, self.cfg.TEST.METRIC)
92
+
93
+ if self.cfg.TEST.RERANK.ENABLED:
94
+ logger.info("Test with rerank setting")
95
+ k1 = self.cfg.TEST.RERANK.K1
96
+ k2 = self.cfg.TEST.RERANK.K2
97
+ lambda_value = self.cfg.TEST.RERANK.LAMBDA
98
+
99
+ if self.cfg.TEST.METRIC == "cosine":
100
+ query_features = F.normalize(query_features, dim=1)
101
+ gallery_features = F.normalize(gallery_features, dim=1)
102
+
103
+ rerank_dist = build_dist(query_features, gallery_features, metric="jaccard", k1=k1, k2=k2)
104
+ dist = rerank_dist * (1 - lambda_value) + dist * lambda_value
105
+
106
+ from .rank import evaluate_rank
107
+ cmc, all_AP, all_INP = evaluate_rank(dist, query_pids, gallery_pids, query_camids, gallery_camids)
108
+
109
+ mAP = np.mean(all_AP)
110
+ mINP = np.mean(all_INP)
111
+ for r in [1, 5, 10]:
112
+ self._results['Rank-{}'.format(r)] = cmc[r - 1] * 100
113
+ self._results['mAP'] = mAP * 100
114
+ self._results['mINP'] = mINP * 100
115
+ self._results["metric"] = (mAP + cmc[0]) / 2 * 100
116
+
117
+ if self.cfg.TEST.ROC.ENABLED:
118
+ from .roc import evaluate_roc
119
+ scores, labels = evaluate_roc(dist, query_pids, gallery_pids, query_camids, gallery_camids)
120
+ fprs, tprs, thres = metrics.roc_curve(labels, scores)
121
+
122
+ for fpr in [1e-4, 1e-3, 1e-2]:
123
+ ind = np.argmin(np.abs(fprs - fpr))
124
+ self._results["TPR@FPR={:.0e}".format(fpr)] = tprs[ind]
125
+
126
+ return copy.deepcopy(self._results)
127
+
128
+ def _compile_dependencies(self):
129
+ # Since we only evaluate results in rank(0), so we just need to compile
130
+ # cython evaluation tool on rank(0)
131
+ if comm.is_main_process():
132
+ try:
133
+ from .rank_cylib.rank_cy import evaluate_cy
134
+ except ImportError:
135
+ start_time = time.time()
136
+ logger.info("> compiling reid evaluation cython tool")
137
+
138
+ compile_helper()
139
+
140
+ logger.info(
141
+ ">>> done with reid evaluation cython tool. Compilation time: {:.3f} "
142
+ "seconds".format(time.time() - start_time))
143
+ comm.synchronize()
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ # based on:
4
+ # https://github.com/zhunzhong07/person-re-ranking
5
+
6
+ __all__ = ['re_ranking']
7
+
8
+ import numpy as np
9
+
10
+
11
+ def re_ranking(q_g_dist, q_q_dist, g_g_dist, k1: int = 20, k2: int = 6, lambda_value: float = 0.3):
12
+ original_dist = np.concatenate(
13
+ [np.concatenate([q_q_dist, q_g_dist], axis=1),
14
+ np.concatenate([q_g_dist.T, g_g_dist], axis=1)],
15
+ axis=0)
16
+ original_dist = np.power(original_dist, 2).astype(np.float32)
17
+ original_dist = np.transpose(1. * original_dist / np.max(original_dist, axis=0))
18
+ V = np.zeros_like(original_dist).astype(np.float32)
19
+ initial_rank = np.argsort(original_dist).astype(np.int32)
20
+
21
+ query_num = q_g_dist.shape[0]
22
+ gallery_num = q_g_dist.shape[0] + q_g_dist.shape[1]
23
+ all_num = gallery_num
24
+
25
+ for i in range(all_num):
26
+ # k-reciprocal neighbors
27
+ forward_k_neigh_index = initial_rank[i, :k1 + 1]
28
+ backward_k_neigh_index = initial_rank[forward_k_neigh_index, :k1 + 1]
29
+ fi = np.where(backward_k_neigh_index == i)[0]
30
+ k_reciprocal_index = forward_k_neigh_index[fi]
31
+ k_reciprocal_expansion_index = k_reciprocal_index
32
+ for j in range(len(k_reciprocal_index)):
33
+ candidate = k_reciprocal_index[j]
34
+ candidate_forward_k_neigh_index = initial_rank[candidate,
35
+ :int(np.around(k1 / 2.)) + 1]
36
+ candidate_backward_k_neigh_index = initial_rank[candidate_forward_k_neigh_index,
37
+ :int(np.around(k1 / 2.)) + 1]
38
+ fi_candidate = np.where(candidate_backward_k_neigh_index == candidate)[0]
39
+ candidate_k_reciprocal_index = candidate_forward_k_neigh_index[fi_candidate]
40
+ if len(np.intersect1d(candidate_k_reciprocal_index, k_reciprocal_index)) > 2. / 3 * len(
41
+ candidate_k_reciprocal_index):
42
+ k_reciprocal_expansion_index = np.append(k_reciprocal_expansion_index, candidate_k_reciprocal_index)
43
+
44
+ k_reciprocal_expansion_index = np.unique(k_reciprocal_expansion_index)
45
+ weight = np.exp(-original_dist[i, k_reciprocal_expansion_index])
46
+ V[i, k_reciprocal_expansion_index] = 1. * weight / np.sum(weight)
47
+ original_dist = original_dist[:query_num, ]
48
+ if k2 != 1:
49
+ V_qe = np.zeros_like(V, dtype=np.float32)
50
+ for i in range(all_num):
51
+ V_qe[i, :] = np.mean(V[initial_rank[i, :k2], :], axis=0)
52
+ V = V_qe
53
+ del V_qe
54
+ del initial_rank
55
+ invIndex = []
56
+ for i in range(gallery_num):
57
+ invIndex.append(np.where(V[:, i] != 0)[0])
58
+
59
+ jaccard_dist = np.zeros_like(original_dist, dtype=np.float32)
60
+
61
+ for i in range(query_num):
62
+ temp_min = np.zeros(shape=[1, gallery_num], dtype=np.float32)
63
+ indNonZero = np.where(V[i, :] != 0)[0]
64
+ indImages = [invIndex[ind] for ind in indNonZero]
65
+ for j in range(len(indNonZero)):
66
+ temp_min[0, indImages[j]] = temp_min[0, indImages[j]] + np.minimum(V[i, indNonZero[j]],
67
+ V[indImages[j], indNonZero[j]])
68
+ jaccard_dist[i] = 1 - temp_min / (2. - temp_min)
69
+
70
+ final_dist = jaccard_dist * (1 - lambda_value) + original_dist * lambda_value
71
+ del original_dist, V, jaccard_dist
72
+ final_dist = final_dist[:query_num, query_num:]
73
+ return final_dist
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+ """
3
+ @author: l1aoxingyu
4
+ @contact: sherlockliao01@gmail.com
5
+ """
6
+
7
+ import warnings
8
+
9
+ import faiss
10
+ import numpy as np
11
+
12
+ try:
13
+ from .rank_cylib.roc_cy import evaluate_roc_cy
14
+
15
+ IS_CYTHON_AVAI = True
16
+ except ImportError:
17
+ IS_CYTHON_AVAI = False
18
+ warnings.warn(
19
+ 'Cython roc evaluation (very fast so highly recommended) is '
20
+ 'unavailable, now use python evaluation.'
21
+ )
22
+
23
+
24
+ def evaluate_roc_py(distmat, q_pids, g_pids, q_camids, g_camids):
25
+ r"""Evaluation with ROC curve.
26
+ Key: for each query identity, its gallery images from the same camera view are discarded.
27
+
28
+ Args:
29
+ distmat (np.ndarray): cosine distance matrix
30
+ """
31
+ num_q, num_g = distmat.shape
32
+
33
+ indices = np.argsort(distmat, axis=1)
34
+ matches = (g_pids[indices] == q_pids[:, np.newaxis]).astype(np.int32)
35
+
36
+ pos = []
37
+ neg = []
38
+ for q_idx in range(num_q):
39
+ # get query pid and camid
40
+ q_pid = q_pids[q_idx]
41
+ q_camid = q_camids[q_idx]
42
+
43
+ # Remove gallery samples that have the same pid and camid with query
44
+ order = indices[q_idx]
45
+ remove = (g_pids[order] == q_pid) & (g_camids[order] == q_camid)
46
+ keep = np.invert(remove)
47
+ raw_cmc = matches[q_idx][keep]
48
+
49
+ sort_idx = order[keep]
50
+
51
+ q_dist = distmat[q_idx]
52
+ ind_pos = np.where(raw_cmc == 1)[0]
53
+ pos.extend(q_dist[sort_idx[ind_pos]])
54
+
55
+ ind_neg = np.where(raw_cmc == 0)[0]
56
+ neg.extend(q_dist[sort_idx[ind_neg]])
57
+
58
+ scores = np.hstack((pos, neg))
59
+
60
+ labels = np.hstack((np.zeros(len(pos)), np.ones(len(neg))))
61
+ return scores, labels
62
+
63
+
64
+ def evaluate_roc(
65
+ distmat,
66
+ q_pids,
67
+ g_pids,
68
+ q_camids,
69
+ g_camids,
70
+ use_cython=True
71
+ ):
72
+ """Evaluates CMC rank.
73
+ Args:
74
+ distmat (numpy.ndarray): distance matrix of shape (num_query, num_gallery).
75
+ q_pids (numpy.ndarray): 1-D array containing person identities
76
+ of each query instance.
77
+ g_pids (numpy.ndarray): 1-D array containing person identities
78
+ of each gallery instance.
79
+ q_camids (numpy.ndarray): 1-D array containing camera views under
80
+ which each query instance is captured.
81
+ g_camids (numpy.ndarray): 1-D array containing camera views under
82
+ which each gallery instance is captured.
83
+ use_cython (bool, optional): use cython code for evaluation. Default is True.
84
+ This is highly recommended as the cython code can speed up the cmc computation
85
+ by more than 10x. This requires Cython to be installed.
86
+ """
87
+ if use_cython and IS_CYTHON_AVAI:
88
+ return evaluate_roc_cy(distmat, q_pids, g_pids, q_camids, g_camids)
89
+ else:
90
+ return evaluate_roc_py(distmat, q_pids, g_pids, q_camids, g_camids)