dnt 0.2.1__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 (315) hide show
  1. dnt/__init__.py +4 -1
  2. dnt/analysis/__init__.py +3 -1
  3. dnt/analysis/count.py +107 -0
  4. dnt/analysis/interaction2.py +518 -0
  5. dnt/analysis/position.py +12 -0
  6. dnt/analysis/stop.py +92 -33
  7. dnt/analysis/stop2.py +289 -0
  8. dnt/analysis/stop3.py +758 -0
  9. dnt/detect/__init__.py +1 -1
  10. dnt/detect/signal/detector.py +326 -0
  11. dnt/detect/timestamp.py +105 -0
  12. dnt/detect/yolov8/detector.py +182 -35
  13. dnt/detect/yolov8/segmentor.py +171 -0
  14. dnt/engine/__init__.py +8 -0
  15. dnt/engine/bbox_interp.py +83 -0
  16. dnt/engine/bbox_iou.py +20 -0
  17. dnt/engine/cluster.py +31 -0
  18. dnt/engine/iob.py +66 -0
  19. dnt/filter/__init__.py +4 -0
  20. dnt/filter/filter.py +450 -21
  21. dnt/label/__init__.py +1 -1
  22. dnt/label/labeler.py +215 -14
  23. dnt/label/labeler2.py +631 -0
  24. dnt/shared/__init__.py +2 -1
  25. dnt/shared/data/coco.names +0 -0
  26. dnt/shared/data/openimages.names +0 -0
  27. dnt/shared/data/voc.names +0 -0
  28. dnt/shared/download.py +12 -0
  29. dnt/shared/synhcro.py +150 -0
  30. dnt/shared/util.py +17 -4
  31. dnt/third_party/fast-reid/__init__.py +1 -0
  32. dnt/third_party/fast-reid/configs/Base-AGW.yml +19 -0
  33. dnt/third_party/fast-reid/configs/Base-MGN.yml +12 -0
  34. dnt/third_party/fast-reid/configs/Base-SBS.yml +63 -0
  35. dnt/third_party/fast-reid/configs/Base-bagtricks.yml +76 -0
  36. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R101-ibn.yml +12 -0
  37. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50-ibn.yml +11 -0
  38. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50.yml +7 -0
  39. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_S50.yml +11 -0
  40. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R101-ibn.yml +12 -0
  41. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50-ibn.yml +11 -0
  42. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50.yml +7 -0
  43. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_S50.yml +11 -0
  44. dnt/third_party/fast-reid/configs/DukeMTMC/mgn_R50-ibn.yml +11 -0
  45. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R101-ibn.yml +12 -0
  46. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50-ibn.yml +11 -0
  47. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50.yml +7 -0
  48. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_S50.yml +11 -0
  49. dnt/third_party/fast-reid/configs/MOT17/AGW_R101-ibn.yml +12 -0
  50. dnt/third_party/fast-reid/configs/MOT17/AGW_R50-ibn.yml +11 -0
  51. dnt/third_party/fast-reid/configs/MOT17/AGW_R50.yml +7 -0
  52. dnt/third_party/fast-reid/configs/MOT17/AGW_S50.yml +11 -0
  53. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R101-ibn.yml +12 -0
  54. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50-ibn.yml +11 -0
  55. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50.yml +7 -0
  56. dnt/third_party/fast-reid/configs/MOT17/bagtricks_S50.yml +11 -0
  57. dnt/third_party/fast-reid/configs/MOT17/mgn_R50-ibn.yml +11 -0
  58. dnt/third_party/fast-reid/configs/MOT17/sbs_R101-ibn.yml +12 -0
  59. dnt/third_party/fast-reid/configs/MOT17/sbs_R50-ibn.yml +11 -0
  60. dnt/third_party/fast-reid/configs/MOT17/sbs_R50.yml +7 -0
  61. dnt/third_party/fast-reid/configs/MOT17/sbs_S50.yml +11 -0
  62. dnt/third_party/fast-reid/configs/MOT20/AGW_R101-ibn.yml +12 -0
  63. dnt/third_party/fast-reid/configs/MOT20/AGW_R50-ibn.yml +11 -0
  64. dnt/third_party/fast-reid/configs/MOT20/AGW_R50.yml +7 -0
  65. dnt/third_party/fast-reid/configs/MOT20/AGW_S50.yml +11 -0
  66. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R101-ibn.yml +12 -0
  67. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50-ibn.yml +11 -0
  68. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50.yml +7 -0
  69. dnt/third_party/fast-reid/configs/MOT20/bagtricks_S50.yml +11 -0
  70. dnt/third_party/fast-reid/configs/MOT20/mgn_R50-ibn.yml +11 -0
  71. dnt/third_party/fast-reid/configs/MOT20/sbs_R101-ibn.yml +12 -0
  72. dnt/third_party/fast-reid/configs/MOT20/sbs_R50-ibn.yml +11 -0
  73. dnt/third_party/fast-reid/configs/MOT20/sbs_R50.yml +7 -0
  74. dnt/third_party/fast-reid/configs/MOT20/sbs_S50.yml +11 -0
  75. dnt/third_party/fast-reid/configs/MSMT17/AGW_R101-ibn.yml +12 -0
  76. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50-ibn.yml +11 -0
  77. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50.yml +7 -0
  78. dnt/third_party/fast-reid/configs/MSMT17/AGW_S50.yml +11 -0
  79. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R101-ibn.yml +13 -0
  80. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50-ibn.yml +12 -0
  81. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50.yml +7 -0
  82. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_S50.yml +12 -0
  83. dnt/third_party/fast-reid/configs/MSMT17/mgn_R50-ibn.yml +11 -0
  84. dnt/third_party/fast-reid/configs/MSMT17/sbs_R101-ibn.yml +12 -0
  85. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50-ibn.yml +11 -0
  86. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50.yml +7 -0
  87. dnt/third_party/fast-reid/configs/MSMT17/sbs_S50.yml +11 -0
  88. dnt/third_party/fast-reid/configs/Market1501/AGW_R101-ibn.yml +12 -0
  89. dnt/third_party/fast-reid/configs/Market1501/AGW_R50-ibn.yml +11 -0
  90. dnt/third_party/fast-reid/configs/Market1501/AGW_R50.yml +7 -0
  91. dnt/third_party/fast-reid/configs/Market1501/AGW_S50.yml +11 -0
  92. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R101-ibn.yml +12 -0
  93. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50-ibn.yml +11 -0
  94. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50.yml +7 -0
  95. dnt/third_party/fast-reid/configs/Market1501/bagtricks_S50.yml +11 -0
  96. dnt/third_party/fast-reid/configs/Market1501/bagtricks_vit.yml +88 -0
  97. dnt/third_party/fast-reid/configs/Market1501/mgn_R50-ibn.yml +11 -0
  98. dnt/third_party/fast-reid/configs/Market1501/sbs_R101-ibn.yml +12 -0
  99. dnt/third_party/fast-reid/configs/Market1501/sbs_R50-ibn.yml +11 -0
  100. dnt/third_party/fast-reid/configs/Market1501/sbs_R50.yml +7 -0
  101. dnt/third_party/fast-reid/configs/Market1501/sbs_S50.yml +11 -0
  102. dnt/third_party/fast-reid/configs/VERIWild/bagtricks_R50-ibn.yml +35 -0
  103. dnt/third_party/fast-reid/configs/VeRi/sbs_R50-ibn.yml +35 -0
  104. dnt/third_party/fast-reid/configs/VehicleID/bagtricks_R50-ibn.yml +36 -0
  105. dnt/third_party/fast-reid/configs/__init__.py +0 -0
  106. dnt/third_party/fast-reid/fast_reid_interfece.py +175 -0
  107. dnt/third_party/fast-reid/fastreid/__init__.py +6 -0
  108. dnt/third_party/fast-reid/fastreid/config/__init__.py +15 -0
  109. dnt/third_party/fast-reid/fastreid/config/config.py +319 -0
  110. dnt/third_party/fast-reid/fastreid/config/defaults.py +329 -0
  111. dnt/third_party/fast-reid/fastreid/data/__init__.py +17 -0
  112. dnt/third_party/fast-reid/fastreid/data/build.py +194 -0
  113. dnt/third_party/fast-reid/fastreid/data/common.py +58 -0
  114. dnt/third_party/fast-reid/fastreid/data/data_utils.py +202 -0
  115. dnt/third_party/fast-reid/fastreid/data/datasets/AirportALERT.py +50 -0
  116. dnt/third_party/fast-reid/fastreid/data/datasets/__init__.py +43 -0
  117. dnt/third_party/fast-reid/fastreid/data/datasets/bases.py +183 -0
  118. dnt/third_party/fast-reid/fastreid/data/datasets/caviara.py +44 -0
  119. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk03.py +274 -0
  120. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk_sysu.py +58 -0
  121. dnt/third_party/fast-reid/fastreid/data/datasets/dukemtmcreid.py +70 -0
  122. dnt/third_party/fast-reid/fastreid/data/datasets/grid.py +44 -0
  123. dnt/third_party/fast-reid/fastreid/data/datasets/iLIDS.py +45 -0
  124. dnt/third_party/fast-reid/fastreid/data/datasets/lpw.py +49 -0
  125. dnt/third_party/fast-reid/fastreid/data/datasets/market1501.py +89 -0
  126. dnt/third_party/fast-reid/fastreid/data/datasets/msmt17.py +114 -0
  127. dnt/third_party/fast-reid/fastreid/data/datasets/pes3d.py +44 -0
  128. dnt/third_party/fast-reid/fastreid/data/datasets/pku.py +44 -0
  129. dnt/third_party/fast-reid/fastreid/data/datasets/prai.py +43 -0
  130. dnt/third_party/fast-reid/fastreid/data/datasets/prid.py +41 -0
  131. dnt/third_party/fast-reid/fastreid/data/datasets/saivt.py +47 -0
  132. dnt/third_party/fast-reid/fastreid/data/datasets/sensereid.py +47 -0
  133. dnt/third_party/fast-reid/fastreid/data/datasets/shinpuhkan.py +48 -0
  134. dnt/third_party/fast-reid/fastreid/data/datasets/sysu_mm.py +47 -0
  135. dnt/third_party/fast-reid/fastreid/data/datasets/thermalworld.py +43 -0
  136. dnt/third_party/fast-reid/fastreid/data/datasets/vehicleid.py +126 -0
  137. dnt/third_party/fast-reid/fastreid/data/datasets/veri.py +69 -0
  138. dnt/third_party/fast-reid/fastreid/data/datasets/veriwild.py +140 -0
  139. dnt/third_party/fast-reid/fastreid/data/datasets/viper.py +45 -0
  140. dnt/third_party/fast-reid/fastreid/data/datasets/wildtracker.py +59 -0
  141. dnt/third_party/fast-reid/fastreid/data/samplers/__init__.py +18 -0
  142. dnt/third_party/fast-reid/fastreid/data/samplers/data_sampler.py +85 -0
  143. dnt/third_party/fast-reid/fastreid/data/samplers/imbalance_sampler.py +67 -0
  144. dnt/third_party/fast-reid/fastreid/data/samplers/triplet_sampler.py +260 -0
  145. dnt/third_party/fast-reid/fastreid/data/transforms/__init__.py +11 -0
  146. dnt/third_party/fast-reid/fastreid/data/transforms/autoaugment.py +806 -0
  147. dnt/third_party/fast-reid/fastreid/data/transforms/build.py +100 -0
  148. dnt/third_party/fast-reid/fastreid/data/transforms/functional.py +180 -0
  149. dnt/third_party/fast-reid/fastreid/data/transforms/transforms.py +161 -0
  150. dnt/third_party/fast-reid/fastreid/engine/__init__.py +15 -0
  151. dnt/third_party/fast-reid/fastreid/engine/defaults.py +490 -0
  152. dnt/third_party/fast-reid/fastreid/engine/hooks.py +534 -0
  153. dnt/third_party/fast-reid/fastreid/engine/launch.py +103 -0
  154. dnt/third_party/fast-reid/fastreid/engine/train_loop.py +357 -0
  155. dnt/third_party/fast-reid/fastreid/evaluation/__init__.py +6 -0
  156. dnt/third_party/fast-reid/fastreid/evaluation/clas_evaluator.py +81 -0
  157. dnt/third_party/fast-reid/fastreid/evaluation/evaluator.py +176 -0
  158. dnt/third_party/fast-reid/fastreid/evaluation/query_expansion.py +46 -0
  159. dnt/third_party/fast-reid/fastreid/evaluation/rank.py +200 -0
  160. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/__init__.py +20 -0
  161. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/setup.py +32 -0
  162. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/test_cython.py +106 -0
  163. dnt/third_party/fast-reid/fastreid/evaluation/reid_evaluation.py +143 -0
  164. dnt/third_party/fast-reid/fastreid/evaluation/rerank.py +73 -0
  165. dnt/third_party/fast-reid/fastreid/evaluation/roc.py +90 -0
  166. dnt/third_party/fast-reid/fastreid/evaluation/testing.py +88 -0
  167. dnt/third_party/fast-reid/fastreid/layers/__init__.py +19 -0
  168. dnt/third_party/fast-reid/fastreid/layers/activation.py +59 -0
  169. dnt/third_party/fast-reid/fastreid/layers/any_softmax.py +80 -0
  170. dnt/third_party/fast-reid/fastreid/layers/batch_norm.py +205 -0
  171. dnt/third_party/fast-reid/fastreid/layers/context_block.py +113 -0
  172. dnt/third_party/fast-reid/fastreid/layers/drop.py +161 -0
  173. dnt/third_party/fast-reid/fastreid/layers/frn.py +199 -0
  174. dnt/third_party/fast-reid/fastreid/layers/gather_layer.py +30 -0
  175. dnt/third_party/fast-reid/fastreid/layers/helpers.py +31 -0
  176. dnt/third_party/fast-reid/fastreid/layers/non_local.py +54 -0
  177. dnt/third_party/fast-reid/fastreid/layers/pooling.py +124 -0
  178. dnt/third_party/fast-reid/fastreid/layers/se_layer.py +25 -0
  179. dnt/third_party/fast-reid/fastreid/layers/splat.py +109 -0
  180. dnt/third_party/fast-reid/fastreid/layers/weight_init.py +122 -0
  181. dnt/third_party/fast-reid/fastreid/modeling/__init__.py +23 -0
  182. dnt/third_party/fast-reid/fastreid/modeling/backbones/__init__.py +18 -0
  183. dnt/third_party/fast-reid/fastreid/modeling/backbones/build.py +27 -0
  184. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenet.py +195 -0
  185. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenetv3.py +283 -0
  186. dnt/third_party/fast-reid/fastreid/modeling/backbones/osnet.py +525 -0
  187. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/__init__.py +4 -0
  188. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/config.py +396 -0
  189. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B0_dds_8gpu.yaml +27 -0
  190. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B1_dds_8gpu.yaml +27 -0
  191. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B2_dds_8gpu.yaml +27 -0
  192. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B3_dds_8gpu.yaml +27 -0
  193. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B4_dds_8gpu.yaml +27 -0
  194. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B5_dds_8gpu.yaml +27 -0
  195. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet.py +281 -0
  196. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnet.py +596 -0
  197. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-1.6GF_dds_8gpu.yaml +26 -0
  198. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-12GF_dds_8gpu.yaml +26 -0
  199. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-16GF_dds_8gpu.yaml +26 -0
  200. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-200MF_dds_8gpu.yaml +26 -0
  201. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-3.2GF_dds_8gpu.yaml +26 -0
  202. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-32GF_dds_8gpu.yaml +26 -0
  203. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-4.0GF_dds_8gpu.yaml +26 -0
  204. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-400MF_dds_8gpu.yaml +26 -0
  205. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-6.4GF_dds_8gpu.yaml +26 -0
  206. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-600MF_dds_8gpu.yaml +26 -0
  207. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-8.0GF_dds_8gpu.yaml +26 -0
  208. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-800MF_dds_8gpu.yaml +26 -0
  209. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-1.6GF_dds_8gpu.yaml +27 -0
  210. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-12GF_dds_8gpu.yaml +27 -0
  211. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-16GF_dds_8gpu.yaml +27 -0
  212. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-200MF_dds_8gpu.yaml +26 -0
  213. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-3.2GF_dds_8gpu.yaml +27 -0
  214. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-32GF_dds_8gpu.yaml +27 -0
  215. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-4.0GF_dds_8gpu.yaml +27 -0
  216. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-400MF_dds_8gpu.yaml +27 -0
  217. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-6.4GF_dds_8gpu.yaml +27 -0
  218. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-600MF_dds_8gpu.yaml +27 -0
  219. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-8.0GF_dds_8gpu.yaml +27 -0
  220. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-800MF_dds_8gpu.yaml +27 -0
  221. dnt/third_party/fast-reid/fastreid/modeling/backbones/repvgg.py +309 -0
  222. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnest.py +365 -0
  223. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnet.py +364 -0
  224. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnext.py +335 -0
  225. dnt/third_party/fast-reid/fastreid/modeling/backbones/shufflenet.py +203 -0
  226. dnt/third_party/fast-reid/fastreid/modeling/backbones/vision_transformer.py +399 -0
  227. dnt/third_party/fast-reid/fastreid/modeling/heads/__init__.py +11 -0
  228. dnt/third_party/fast-reid/fastreid/modeling/heads/build.py +25 -0
  229. dnt/third_party/fast-reid/fastreid/modeling/heads/clas_head.py +36 -0
  230. dnt/third_party/fast-reid/fastreid/modeling/heads/embedding_head.py +151 -0
  231. dnt/third_party/fast-reid/fastreid/modeling/losses/__init__.py +12 -0
  232. dnt/third_party/fast-reid/fastreid/modeling/losses/circle_loss.py +71 -0
  233. dnt/third_party/fast-reid/fastreid/modeling/losses/cross_entroy_loss.py +54 -0
  234. dnt/third_party/fast-reid/fastreid/modeling/losses/focal_loss.py +92 -0
  235. dnt/third_party/fast-reid/fastreid/modeling/losses/triplet_loss.py +113 -0
  236. dnt/third_party/fast-reid/fastreid/modeling/losses/utils.py +48 -0
  237. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/__init__.py +14 -0
  238. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/baseline.py +188 -0
  239. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/build.py +26 -0
  240. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/distiller.py +140 -0
  241. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/mgn.py +394 -0
  242. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/moco.py +126 -0
  243. dnt/third_party/fast-reid/fastreid/solver/__init__.py +8 -0
  244. dnt/third_party/fast-reid/fastreid/solver/build.py +348 -0
  245. dnt/third_party/fast-reid/fastreid/solver/lr_scheduler.py +66 -0
  246. dnt/third_party/fast-reid/fastreid/solver/optim/__init__.py +10 -0
  247. dnt/third_party/fast-reid/fastreid/solver/optim/lamb.py +123 -0
  248. dnt/third_party/fast-reid/fastreid/solver/optim/radam.py +149 -0
  249. dnt/third_party/fast-reid/fastreid/solver/optim/swa.py +246 -0
  250. dnt/third_party/fast-reid/fastreid/utils/__init__.py +6 -0
  251. dnt/third_party/fast-reid/fastreid/utils/checkpoint.py +503 -0
  252. dnt/third_party/fast-reid/fastreid/utils/collect_env.py +158 -0
  253. dnt/third_party/fast-reid/fastreid/utils/comm.py +255 -0
  254. dnt/third_party/fast-reid/fastreid/utils/compute_dist.py +200 -0
  255. dnt/third_party/fast-reid/fastreid/utils/env.py +119 -0
  256. dnt/third_party/fast-reid/fastreid/utils/events.py +461 -0
  257. dnt/third_party/fast-reid/fastreid/utils/faiss_utils.py +127 -0
  258. dnt/third_party/fast-reid/fastreid/utils/file_io.py +520 -0
  259. dnt/third_party/fast-reid/fastreid/utils/history_buffer.py +71 -0
  260. dnt/third_party/fast-reid/fastreid/utils/logger.py +211 -0
  261. dnt/third_party/fast-reid/fastreid/utils/params.py +103 -0
  262. dnt/third_party/fast-reid/fastreid/utils/precision_bn.py +94 -0
  263. dnt/third_party/fast-reid/fastreid/utils/registry.py +66 -0
  264. dnt/third_party/fast-reid/fastreid/utils/summary.py +120 -0
  265. dnt/third_party/fast-reid/fastreid/utils/timer.py +68 -0
  266. dnt/third_party/fast-reid/fastreid/utils/visualizer.py +278 -0
  267. dnt/track/__init__.py +3 -1
  268. dnt/track/botsort/__init__.py +4 -0
  269. dnt/track/botsort/bot_tracker/__init__.py +3 -0
  270. dnt/track/botsort/bot_tracker/basetrack.py +60 -0
  271. dnt/track/botsort/bot_tracker/bot_sort.py +473 -0
  272. dnt/track/botsort/bot_tracker/gmc.py +316 -0
  273. dnt/track/botsort/bot_tracker/kalman_filter.py +269 -0
  274. dnt/track/botsort/bot_tracker/matching.py +194 -0
  275. dnt/track/botsort/bot_tracker/mc_bot_sort.py +505 -0
  276. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/evaluation.py +14 -4
  277. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/io.py +19 -36
  278. dnt/track/botsort/bot_tracker/tracking_utils/timer.py +37 -0
  279. dnt/track/botsort/inference.py +96 -0
  280. dnt/track/config.py +120 -0
  281. dnt/track/dsort/configs/bagtricks_R50.yml +7 -0
  282. dnt/track/dsort/configs/deep_sort.yaml +0 -0
  283. dnt/track/dsort/configs/fastreid.yaml +1 -1
  284. dnt/track/dsort/deep_sort/deep/checkpoint/ckpt.t7 +0 -0
  285. dnt/track/dsort/deep_sort/deep/feature_extractor.py +87 -8
  286. dnt/track/dsort/deep_sort/deep_sort.py +31 -21
  287. dnt/track/dsort/deep_sort/sort/detection.py +2 -1
  288. dnt/track/dsort/deep_sort/sort/iou_matching.py +0 -2
  289. dnt/track/dsort/deep_sort/sort/linear_assignment.py +0 -3
  290. dnt/track/dsort/deep_sort/sort/nn_matching.py +5 -5
  291. dnt/track/dsort/deep_sort/sort/preprocessing.py +1 -2
  292. dnt/track/dsort/deep_sort/sort/track.py +2 -1
  293. dnt/track/dsort/deep_sort/sort/tracker.py +1 -1
  294. dnt/track/dsort/dsort.py +44 -27
  295. dnt/track/re_class.py +117 -0
  296. dnt/track/sort/sort.py +9 -7
  297. dnt/track/tracker.py +225 -20
  298. dnt-0.3.1.8.dist-info/METADATA +117 -0
  299. dnt-0.3.1.8.dist-info/RECORD +315 -0
  300. {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info}/WHEEL +1 -1
  301. dnt/track/dsort/deep_sort/deep/evaluate.py +0 -15
  302. dnt/track/dsort/deep_sort/deep/original_model.py +0 -106
  303. dnt/track/dsort/deep_sort/deep/test.py +0 -77
  304. dnt/track/dsort/deep_sort/deep/train.py +0 -189
  305. dnt/track/dsort/utils/asserts.py +0 -13
  306. dnt/track/dsort/utils/draw.py +0 -36
  307. dnt/track/dsort/utils/json_logger.py +0 -383
  308. dnt/track/dsort/utils/log.py +0 -17
  309. dnt/track/dsort/utils/parser.py +0 -35
  310. dnt/track/dsort/utils/tools.py +0 -39
  311. dnt-0.2.1.dist-info/METADATA +0 -35
  312. dnt-0.2.1.dist-info/RECORD +0 -60
  313. /dnt/{track/dsort/utils → third_party/fast-reid/checkpoint}/__init__.py +0 -0
  314. {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info/licenses}/LICENSE +0 -0
  315. {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,194 @@
1
+ import numpy as np
2
+ import scipy
3
+ import lap
4
+ from scipy.spatial.distance import cdist
5
+
6
+ from cython_bbox import bbox_overlaps as bbox_ious
7
+ from bot_tracker import kalman_filter
8
+
9
+ def merge_matches(m1, m2, shape):
10
+ O,P,Q = shape
11
+ m1 = np.asarray(m1)
12
+ m2 = np.asarray(m2)
13
+
14
+ M1 = scipy.sparse.coo_matrix((np.ones(len(m1)), (m1[:, 0], m1[:, 1])), shape=(O, P))
15
+ M2 = scipy.sparse.coo_matrix((np.ones(len(m2)), (m2[:, 0], m2[:, 1])), shape=(P, Q))
16
+
17
+ mask = M1*M2
18
+ match = mask.nonzero()
19
+ match = list(zip(match[0], match[1]))
20
+ unmatched_O = tuple(set(range(O)) - set([i for i, j in match]))
21
+ unmatched_Q = tuple(set(range(Q)) - set([j for i, j in match]))
22
+
23
+ return match, unmatched_O, unmatched_Q
24
+
25
+
26
+ def _indices_to_matches(cost_matrix, indices, thresh):
27
+ matched_cost = cost_matrix[tuple(zip(*indices))]
28
+ matched_mask = (matched_cost <= thresh)
29
+
30
+ matches = indices[matched_mask]
31
+ unmatched_a = tuple(set(range(cost_matrix.shape[0])) - set(matches[:, 0]))
32
+ unmatched_b = tuple(set(range(cost_matrix.shape[1])) - set(matches[:, 1]))
33
+
34
+ return matches, unmatched_a, unmatched_b
35
+
36
+ def linear_assignment(cost_matrix, thresh):
37
+ if cost_matrix.size == 0:
38
+ return np.empty((0, 2), dtype=int), tuple(range(cost_matrix.shape[0])), tuple(range(cost_matrix.shape[1]))
39
+ matches, unmatched_a, unmatched_b = [], [], []
40
+ cost, x, y = lap.lapjv(cost_matrix, extend_cost=True, cost_limit=thresh)
41
+ for ix, mx in enumerate(x):
42
+ if mx >= 0:
43
+ matches.append([ix, mx])
44
+ unmatched_a = np.where(x < 0)[0]
45
+ unmatched_b = np.where(y < 0)[0]
46
+ matches = np.asarray(matches)
47
+ return matches, unmatched_a, unmatched_b
48
+
49
+ def ious(atlbrs, btlbrs):
50
+ """
51
+ Compute cost based on IoU
52
+ :type atlbrs: list[tlbr] | np.ndarray
53
+ :type atlbrs: list[tlbr] | np.ndarray
54
+
55
+ :rtype ious np.ndarray
56
+ """
57
+ ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=float)
58
+ if ious.size == 0:
59
+ return ious
60
+
61
+ ious = bbox_ious(
62
+ np.ascontiguousarray(atlbrs, dtype=float),
63
+ np.ascontiguousarray(btlbrs, dtype=float)
64
+ )
65
+
66
+ return ious
67
+
68
+
69
+ def tlbr_expand(tlbr, scale=1.2):
70
+ w = tlbr[2] - tlbr[0]
71
+ h = tlbr[3] - tlbr[1]
72
+
73
+ half_scale = 0.5 * scale
74
+
75
+ tlbr[0] -= half_scale * w
76
+ tlbr[1] -= half_scale * h
77
+ tlbr[2] += half_scale * w
78
+ tlbr[3] += half_scale * h
79
+
80
+ return tlbr
81
+
82
+
83
+ def iou_distance(atracks, btracks):
84
+ """
85
+ Compute cost based on IoU
86
+ :type atracks: list[STrack]
87
+ :type btracks: list[STrack]
88
+
89
+ :rtype cost_matrix np.ndarray
90
+ """
91
+
92
+ if (len(atracks)>0 and isinstance(atracks[0], np.ndarray)) or (len(btracks) > 0 and isinstance(btracks[0], np.ndarray)):
93
+ atlbrs = atracks
94
+ btlbrs = btracks
95
+ else:
96
+ atlbrs = [track.tlbr for track in atracks]
97
+ btlbrs = [track.tlbr for track in btracks]
98
+ _ious = ious(atlbrs, btlbrs)
99
+ cost_matrix = 1 - _ious
100
+
101
+ return cost_matrix
102
+
103
+
104
+ def v_iou_distance(atracks, btracks):
105
+ """
106
+ Compute cost based on IoU
107
+ :type atracks: list[STrack]
108
+ :type btracks: list[STrack]
109
+
110
+ :rtype cost_matrix np.ndarray
111
+ """
112
+
113
+ if (len(atracks)>0 and isinstance(atracks[0], np.ndarray)) or (len(btracks) > 0 and isinstance(btracks[0], np.ndarray)):
114
+ atlbrs = atracks
115
+ btlbrs = btracks
116
+ else:
117
+ atlbrs = [track.tlwh_to_tlbr(track.pred_bbox) for track in atracks]
118
+ btlbrs = [track.tlwh_to_tlbr(track.pred_bbox) for track in btracks]
119
+ _ious = ious(atlbrs, btlbrs)
120
+ cost_matrix = 1 - _ious
121
+
122
+ return cost_matrix
123
+
124
+ def embedding_distance(tracks, detections, metric='cosine'):
125
+ """
126
+ :param tracks: list[STrack]
127
+ :param detections: list[BaseTrack]
128
+ :param metric:
129
+ :return: cost_matrix np.ndarray
130
+ """
131
+
132
+ cost_matrix = np.zeros((len(tracks), len(detections)), dtype=float)
133
+ if cost_matrix.size == 0:
134
+ return cost_matrix
135
+ det_features = np.asarray([track.curr_feat for track in detections], dtype=float)
136
+ track_features = np.asarray([track.smooth_feat for track in tracks], dtype=float)
137
+
138
+ #det_features = np.array([track.curr_feat for track in detections], dtype=np.float128)
139
+ #track_features = np.array([track.smooth_feat for track in tracks], dtype=np.float128)
140
+
141
+ cost_matrix = np.maximum(0.0, cdist(track_features, det_features, metric)) # / 2.0 # Nomalized features
142
+ return cost_matrix
143
+
144
+
145
+ def gate_cost_matrix(kf, cost_matrix, tracks, detections, only_position=False):
146
+ if cost_matrix.size == 0:
147
+ return cost_matrix
148
+ gating_dim = 2 if only_position else 4
149
+ gating_threshold = kalman_filter.chi2inv95[gating_dim]
150
+ # measurements = np.asarray([det.to_xyah() for det in detections])
151
+ measurements = np.asarray([det.to_xywh() for det in detections])
152
+ for row, track in enumerate(tracks):
153
+ gating_distance = kf.gating_distance(
154
+ track.mean, track.covariance, measurements, only_position)
155
+ cost_matrix[row, gating_distance > gating_threshold] = np.inf
156
+ return cost_matrix
157
+
158
+
159
+ def fuse_motion(kf, cost_matrix, tracks, detections, only_position=False, lambda_=0.98):
160
+ if cost_matrix.size == 0:
161
+ return cost_matrix
162
+ gating_dim = 2 if only_position else 4
163
+ gating_threshold = kalman_filter.chi2inv95[gating_dim]
164
+ # measurements = np.asarray([det.to_xyah() for det in detections])
165
+ measurements = np.asarray([det.to_xywh() for det in detections])
166
+ for row, track in enumerate(tracks):
167
+ gating_distance = kf.gating_distance(
168
+ track.mean, track.covariance, measurements, only_position, metric='maha')
169
+ cost_matrix[row, gating_distance > gating_threshold] = np.inf
170
+ cost_matrix[row] = lambda_ * cost_matrix[row] + (1 - lambda_) * gating_distance
171
+ return cost_matrix
172
+
173
+ def fuse_iou(cost_matrix, tracks, detections):
174
+ if cost_matrix.size == 0:
175
+ return cost_matrix
176
+ reid_sim = 1 - cost_matrix
177
+ iou_dist = iou_distance(tracks, detections)
178
+ iou_sim = 1 - iou_dist
179
+ fuse_sim = reid_sim * (1 + iou_sim) / 2
180
+ det_scores = np.array([det.score for det in detections])
181
+ det_scores = np.expand_dims(det_scores, axis=0).repeat(cost_matrix.shape[0], axis=0)
182
+ #fuse_sim = fuse_sim * (1 + det_scores) / 2
183
+ fuse_cost = 1 - fuse_sim
184
+ return fuse_cost
185
+
186
+ def fuse_score(cost_matrix, detections):
187
+ if cost_matrix.size == 0:
188
+ return cost_matrix
189
+ iou_sim = 1 - cost_matrix
190
+ det_scores = np.array([det.score for det in detections])
191
+ det_scores = np.expand_dims(det_scores, axis=0).repeat(cost_matrix.shape[0], axis=0)
192
+ fuse_sim = iou_sim * det_scores
193
+ fuse_cost = 1 - fuse_sim
194
+ return fuse_cost
@@ -0,0 +1,505 @@
1
+ import os, sys
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+ from collections import deque
5
+
6
+ from bot_tracker import matching
7
+ from bot_tracker.gmc import GMC
8
+ from bot_tracker.basetrack import BaseTrack, TrackState
9
+ from bot_tracker.kalman_filter import KalmanFilter
10
+
11
+ from tqdm import tqdm
12
+ import requests
13
+
14
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../third_party/fast-reid")))
15
+
16
+ from fast_reid_interfece import FastReIDInterface #type: ignore
17
+
18
+ class STrack(BaseTrack):
19
+ shared_kalman = KalmanFilter()
20
+
21
+ def __init__(self, tlwh, score, cls, feat=None, feat_history=50):
22
+
23
+ # wait activate
24
+ self._tlwh = np.asarray(tlwh, dtype=float)
25
+ self.kalman_filter = None
26
+ self.mean, self.covariance = None, None
27
+ self.is_activated = False
28
+
29
+ self.cls = -1
30
+ self.cls_hist = [] # (cls id, freq)
31
+ self.update_cls(cls, score)
32
+
33
+ self.score = score
34
+ self.tracklet_len = 0
35
+
36
+ self.smooth_feat = None
37
+ self.curr_feat = None
38
+ if feat is not None:
39
+ self.update_features(feat)
40
+ self.features = deque([], maxlen=feat_history)
41
+ self.alpha = 0.9
42
+
43
+ def update_features(self, feat):
44
+ feat /= np.linalg.norm(feat)
45
+ self.curr_feat = feat
46
+ if self.smooth_feat is None:
47
+ self.smooth_feat = feat
48
+ else:
49
+ self.smooth_feat = self.alpha * self.smooth_feat + (1 - self.alpha) * feat
50
+ self.features.append(feat)
51
+ self.smooth_feat /= np.linalg.norm(self.smooth_feat)
52
+
53
+ def update_cls(self, cls, score):
54
+ if len(self.cls_hist) > 0:
55
+ max_freq = 0
56
+ found = False
57
+ for c in self.cls_hist:
58
+ if cls == c[0]:
59
+ c[1] += score
60
+ found = True
61
+
62
+ if c[1] > max_freq:
63
+ max_freq = c[1]
64
+ self.cls = c[0]
65
+ if not found:
66
+ self.cls_hist.append([cls, score])
67
+ self.cls = cls
68
+ else:
69
+ self.cls_hist.append([cls, score])
70
+ self.cls = cls
71
+
72
+ def predict(self):
73
+ mean_state = self.mean.copy()
74
+ if self.state != TrackState.Tracked:
75
+ mean_state[6] = 0
76
+ mean_state[7] = 0
77
+
78
+ self.mean, self.covariance = self.kalman_filter.predict(mean_state, self.covariance)
79
+
80
+ @staticmethod
81
+ def multi_predict(stracks):
82
+ if len(stracks) > 0:
83
+ multi_mean = np.asarray([st.mean.copy() for st in stracks])
84
+ multi_covariance = np.asarray([st.covariance for st in stracks])
85
+ for i, st in enumerate(stracks):
86
+ if st.state != TrackState.Tracked:
87
+ multi_mean[i][6] = 0
88
+ multi_mean[i][7] = 0
89
+ multi_mean, multi_covariance = STrack.shared_kalman.multi_predict(multi_mean, multi_covariance)
90
+ for i, (mean, cov) in enumerate(zip(multi_mean, multi_covariance)):
91
+ stracks[i].mean = mean
92
+ stracks[i].covariance = cov
93
+
94
+ @staticmethod
95
+ def multi_gmc(stracks, H=np.eye(2, 3)):
96
+ if len(stracks) > 0:
97
+ multi_mean = np.asarray([st.mean.copy() for st in stracks])
98
+ multi_covariance = np.asarray([st.covariance for st in stracks])
99
+
100
+ R = H[:2, :2]
101
+ R8x8 = np.kron(np.eye(4, dtype=float), R)
102
+ t = H[:2, 2]
103
+
104
+ for i, (mean, cov) in enumerate(zip(multi_mean, multi_covariance)):
105
+ mean = R8x8.dot(mean)
106
+ mean[:2] += t
107
+ cov = R8x8.dot(cov).dot(R8x8.transpose())
108
+
109
+ stracks[i].mean = mean
110
+ stracks[i].covariance = cov
111
+
112
+ def activate(self, kalman_filter, frame_id):
113
+ """Start a new tracklet"""
114
+ self.kalman_filter = kalman_filter
115
+ self.track_id = self.next_id()
116
+
117
+ self.mean, self.covariance = self.kalman_filter.initiate(self.tlwh_to_xywh(self._tlwh))
118
+
119
+ self.tracklet_len = 0
120
+ self.state = TrackState.Tracked
121
+ if frame_id == 1:
122
+ self.is_activated = True
123
+ self.frame_id = frame_id
124
+ self.start_frame = frame_id
125
+
126
+ def re_activate(self, new_track, frame_id, new_id=False):
127
+
128
+ self.mean, self.covariance = self.kalman_filter.update(self.mean, self.covariance, self.tlwh_to_xywh(new_track.tlwh))
129
+ if new_track.curr_feat is not None:
130
+ self.update_features(new_track.curr_feat)
131
+ self.tracklet_len = 0
132
+ self.state = TrackState.Tracked
133
+ self.is_activated = True
134
+ self.frame_id = frame_id
135
+ if new_id:
136
+ self.track_id = self.next_id()
137
+ self.score = new_track.score
138
+
139
+ self.update_cls(new_track.cls, new_track.score)
140
+
141
+ def update(self, new_track, frame_id):
142
+ """
143
+ Update a matched track
144
+ :type new_track: STrack
145
+ :type frame_id: int
146
+ :type update_feature: bool
147
+ :return:
148
+ """
149
+ self.frame_id = frame_id
150
+ self.tracklet_len += 1
151
+
152
+ new_tlwh = new_track.tlwh
153
+
154
+ self.mean, self.covariance = self.kalman_filter.update(self.mean, self.covariance, self.tlwh_to_xywh(new_tlwh))
155
+
156
+ if new_track.curr_feat is not None:
157
+ self.update_features(new_track.curr_feat)
158
+
159
+ self.state = TrackState.Tracked
160
+ self.is_activated = True
161
+
162
+ self.score = new_track.score
163
+ self.update_cls(new_track.cls, new_track.score)
164
+
165
+ @property
166
+ def tlwh(self):
167
+ """Get current position in bounding box format `(top left x, top left y,
168
+ width, height)`.
169
+ """
170
+ if self.mean is None:
171
+ return self._tlwh.copy()
172
+ ret = self.mean[:4].copy()
173
+ ret[:2] -= ret[2:] / 2
174
+ return ret
175
+
176
+ @property
177
+ def tlbr(self):
178
+ """Convert bounding box to format `(min x, min y, max x, max y)`, i.e.,
179
+ `(top left, bottom right)`.
180
+ """
181
+ ret = self.tlwh.copy()
182
+ ret[2:] += ret[:2]
183
+ return ret
184
+
185
+ @property
186
+ def xywh(self):
187
+ """Convert bounding box to format `(min x, min y, max x, max y)`, i.e.,
188
+ `(top left, bottom right)`.
189
+ """
190
+ ret = self.tlwh.copy()
191
+ ret[:2] += ret[2:] / 2.0
192
+ return ret
193
+
194
+ @staticmethod
195
+ def tlwh_to_xyah(tlwh):
196
+ """Convert bounding box to format `(center x, center y, aspect ratio,
197
+ height)`, where the aspect ratio is `width / height`.
198
+ """
199
+ ret = np.asarray(tlwh).copy()
200
+ ret[:2] += ret[2:] / 2
201
+ ret[2] /= ret[3]
202
+ return ret
203
+
204
+ @staticmethod
205
+ def tlwh_to_xywh(tlwh):
206
+ """Convert bounding box to format `(center x, center y, width,
207
+ height)`.
208
+ """
209
+ ret = np.asarray(tlwh).copy()
210
+ ret[:2] += ret[2:] / 2
211
+ return ret
212
+
213
+ def to_xywh(self):
214
+ return self.tlwh_to_xywh(self.tlwh)
215
+
216
+ @staticmethod
217
+ def tlbr_to_tlwh(tlbr):
218
+ ret = np.asarray(tlbr).copy()
219
+ ret[2:] -= ret[:2]
220
+ return ret
221
+
222
+ @staticmethod
223
+ def tlwh_to_tlbr(tlwh):
224
+ ret = np.asarray(tlwh).copy()
225
+ ret[2:] += ret[:2]
226
+ return ret
227
+
228
+ def __repr__(self):
229
+ return 'OT_{}_({}-{})'.format(self.track_id, self.start_frame, self.end_frame)
230
+
231
+ class BoTSORT(object):
232
+ def __init__(self, args, frame_rate=30):
233
+
234
+ self.tracked_stracks = [] # type: list[STrack]
235
+ self.lost_stracks = [] # type: list[STrack]
236
+ self.removed_stracks = [] # type: list[STrack]
237
+ BaseTrack.clear_count()
238
+
239
+ self.frame_id = 0
240
+ self.args = args
241
+
242
+ self.track_high_thresh = args['track_high_thresh']
243
+ self.track_low_thresh = args['track_low_thresh']
244
+ self.new_track_thresh = args['new_track_thresh']
245
+
246
+ self.buffer_size = int(frame_rate / 30.0 * args['track_buffer'])
247
+ self.max_time_lost = self.buffer_size
248
+ self.kalman_filter = KalmanFilter()
249
+
250
+ # ReID module
251
+ self.proximity_thresh = args['proximity_thresh']
252
+ self.appearance_thresh = args['appearance_thresh']
253
+
254
+ cfg_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../third_party/fast-reid/configs", args['fast_reid_config']))
255
+ weight_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../third_party/fast-reid/checkpoint", args['fast_reid_weights']))
256
+
257
+ if args['with_reid']:
258
+ self.encoder = FastReIDInterface(config_file=cfg_path, weights_path=weight_path,
259
+ device=args['device'], half=args['half'])
260
+
261
+ self.gmc = GMC(method=args['cmc_method'], verbose=[args['name'], args['ablation']])
262
+
263
+ def update(self, det_results:np.array, img:np.array):
264
+ '''
265
+ Parameters:
266
+ det_results: np.array
267
+ detections in the format [x1, y1, x2, y2, score, class, features], tlrb format
268
+ img: np.array
269
+ image to extract features from
270
+ '''
271
+ self.frame_id += 1
272
+ activated_starcks = []
273
+ refind_stracks = []
274
+ lost_stracks = []
275
+ removed_stracks = []
276
+
277
+ if len(det_results):
278
+ bboxes = det_results[:, :4] # x1, y1, x2, y2
279
+ scores = det_results[:, 4] # detection confidence
280
+ classes = det_results[:, 5] # class
281
+ features = det_results[:, 6:] # fast-reid features
282
+
283
+ # Remove bad detections
284
+ lowest_inds = scores > self.track_low_thresh # remove low confidence detections
285
+ bboxes = bboxes[lowest_inds]
286
+ scores = scores[lowest_inds]
287
+ classes = classes[lowest_inds]
288
+ features = features[lowest_inds]
289
+
290
+ # Find high threshold detections
291
+ remain_inds = scores > self.track_high_thresh
292
+ dets = bboxes[remain_inds]
293
+ scores_keep = scores[remain_inds]
294
+ classes_keep = classes[remain_inds]
295
+ features_keep = features[remain_inds]
296
+ else:
297
+ bboxes = []
298
+ scores = []
299
+ classes = []
300
+ dets = []
301
+ scores_keep = []
302
+ classes_keep = []
303
+
304
+ '''Extract embeddings '''
305
+ if self.args['with_reid']:
306
+ features_keep = self.encoder.inference(img, dets) # extract features for bbox from images
307
+
308
+ if len(dets) > 0:
309
+ '''Detections'''
310
+ if self.args['with_reid']:
311
+ detections = [STrack(STrack.tlbr_to_tlwh(tlbr), s, c, f) for
312
+ (tlbr, s, c, f) in zip(dets, scores_keep, classes_keep, features_keep)]
313
+ else:
314
+ detections = [STrack(STrack.tlbr_to_tlwh(tlbr), s, c) for
315
+ (tlbr, s, c) in zip(dets, scores_keep, classes_keep)]
316
+ else:
317
+ detections = []
318
+
319
+ ''' Add newly detected tracklets to tracked_stracks'''
320
+ unconfirmed = []
321
+ tracked_stracks = [] # type: list[STrack]
322
+ for track in self.tracked_stracks:
323
+ if not track.is_activated:
324
+ unconfirmed.append(track)
325
+ else:
326
+ tracked_stracks.append(track)
327
+
328
+ ''' Step 2: First association, with high score detection boxes'''
329
+ strack_pool = joint_stracks(tracked_stracks, self.lost_stracks)
330
+
331
+ # Predict the current location with KF
332
+ STrack.multi_predict(strack_pool)
333
+
334
+ # Fix camera motion
335
+ warp = self.gmc.apply(img, dets)
336
+ STrack.multi_gmc(strack_pool, warp)
337
+ STrack.multi_gmc(unconfirmed, warp)
338
+
339
+ # Associate with high score detection boxes
340
+ ious_dists = matching.iou_distance(strack_pool, detections)
341
+ ious_dists_mask = (ious_dists > self.proximity_thresh)
342
+
343
+ if not self.args['mot20']:
344
+ ious_dists = matching.fuse_score(ious_dists, detections)
345
+
346
+ if self.args['with_reid']:
347
+ emb_dists = matching.embedding_distance(strack_pool, detections) / 2.0
348
+ raw_emb_dists = emb_dists.copy()
349
+ emb_dists[emb_dists > self.appearance_thresh] = 1.0
350
+ emb_dists[ious_dists_mask] = 1.0
351
+ dists = np.minimum(ious_dists, emb_dists)
352
+
353
+ # Popular ReID method (JDE / FairMOT)
354
+ # raw_emb_dists = matching.embedding_distance(strack_pool, detections)
355
+ # dists = matching.fuse_motion(self.kalman_filter, raw_emb_dists, strack_pool, detections)
356
+ # emb_dists = dists
357
+
358
+ # IoU making ReID
359
+ # dists = matching.embedding_distance(strack_pool, detections)
360
+ # dists[ious_dists_mask] = 1.0
361
+ else:
362
+ dists = ious_dists
363
+
364
+ matches, u_track, u_detection = matching.linear_assignment(dists, thresh=self.args['match_thresh'])
365
+
366
+ for itracked, idet in matches:
367
+ track = strack_pool[itracked]
368
+ det = detections[idet]
369
+ if track.state == TrackState.Tracked:
370
+ track.update(detections[idet], self.frame_id)
371
+ activated_starcks.append(track)
372
+ else:
373
+ track.re_activate(det, self.frame_id, new_id=False)
374
+ refind_stracks.append(track)
375
+
376
+ ''' Step 3: Second association, with low score detection boxes'''
377
+ if len(scores):
378
+ inds_high = scores < self.args['track_high_thresh']
379
+ inds_low = scores > self.args['track_low_thresh']
380
+ inds_second = np.logical_and(inds_low, inds_high)
381
+ dets_second = bboxes[inds_second]
382
+ scores_second = scores[inds_second]
383
+ classes_second = classes[inds_second]
384
+ else:
385
+ dets_second = []
386
+ scores_second = []
387
+ classes_second = []
388
+
389
+ # association the untrack to the low score detections
390
+ if len(dets_second) > 0:
391
+ '''Detections'''
392
+ detections_second = [STrack(STrack.tlbr_to_tlwh(tlbr), s, c) for
393
+ (tlbr, s, c) in zip(dets_second, scores_second, classes_second)]
394
+ else:
395
+ detections_second = []
396
+
397
+ r_tracked_stracks = [strack_pool[i] for i in u_track if strack_pool[i].state == TrackState.Tracked]
398
+ dists = matching.iou_distance(r_tracked_stracks, detections_second)
399
+ matches, u_track, u_detection_second = matching.linear_assignment(dists, thresh=0.5)
400
+ for itracked, idet in matches:
401
+ track = r_tracked_stracks[itracked]
402
+ det = detections_second[idet]
403
+ if track.state == TrackState.Tracked:
404
+ track.update(det, self.frame_id)
405
+ activated_starcks.append(track)
406
+ else:
407
+ track.re_activate(det, self.frame_id, new_id=False)
408
+ refind_stracks.append(track)
409
+
410
+ for it in u_track:
411
+ track = r_tracked_stracks[it]
412
+ if not track.state == TrackState.Lost:
413
+ track.mark_lost()
414
+ lost_stracks.append(track)
415
+
416
+ '''Deal with unconfirmed tracks, usually tracks with only one beginning frame'''
417
+ detections = [detections[i] for i in u_detection]
418
+ dists = matching.iou_distance(unconfirmed, detections)
419
+ if not self.args['mot20']:
420
+ dists = matching.fuse_score(dists, detections)
421
+ matches, u_unconfirmed, u_detection = matching.linear_assignment(dists, thresh=0.7)
422
+ for itracked, idet in matches:
423
+ unconfirmed[itracked].update(detections[idet], self.frame_id)
424
+ activated_starcks.append(unconfirmed[itracked])
425
+ for it in u_unconfirmed:
426
+ track = unconfirmed[it]
427
+ track.mark_removed()
428
+ removed_stracks.append(track)
429
+
430
+ """ Step 4: Init new stracks"""
431
+ for inew in u_detection:
432
+ track = detections[inew]
433
+ if track.score < self.new_track_thresh:
434
+ continue
435
+
436
+ track.activate(self.kalman_filter, self.frame_id)
437
+ activated_starcks.append(track)
438
+
439
+ """ Step 5: Update state"""
440
+ for track in self.lost_stracks:
441
+ if self.frame_id - track.end_frame > self.max_time_lost:
442
+ track.mark_removed()
443
+ removed_stracks.append(track)
444
+
445
+ """ Merge """
446
+ self.tracked_stracks = [t for t in self.tracked_stracks if t.state == TrackState.Tracked]
447
+ self.tracked_stracks = joint_stracks(self.tracked_stracks, activated_starcks)
448
+ self.tracked_stracks = joint_stracks(self.tracked_stracks, refind_stracks)
449
+ self.lost_stracks = sub_stracks(self.lost_stracks, self.tracked_stracks)
450
+ self.lost_stracks.extend(lost_stracks)
451
+ self.lost_stracks = sub_stracks(self.lost_stracks, self.removed_stracks)
452
+ self.removed_stracks.extend(removed_stracks)
453
+ self.tracked_stracks, self.lost_stracks = remove_duplicate_stracks(self.tracked_stracks, self.lost_stracks)
454
+
455
+ # output_stracks = [track for track in self.tracked_stracks if track.is_activated]
456
+ output_stracks = [track for track in self.tracked_stracks]
457
+
458
+ return output_stracks
459
+
460
+
461
+ def joint_stracks(tlista, tlistb):
462
+ exists = {}
463
+ res = []
464
+ for t in tlista:
465
+ exists[t.track_id] = 1
466
+ res.append(t)
467
+ for t in tlistb:
468
+ tid = t.track_id
469
+ if not exists.get(tid, 0):
470
+ exists[tid] = 1
471
+ res.append(t)
472
+ return res
473
+
474
+
475
+ def sub_stracks(tlista, tlistb):
476
+ stracks = {}
477
+ for t in tlista:
478
+ stracks[t.track_id] = t
479
+ for t in tlistb:
480
+ tid = t.track_id
481
+ if stracks.get(tid, 0):
482
+ del stracks[tid]
483
+ return list(stracks.values())
484
+
485
+
486
+ def remove_duplicate_stracks(stracksa, stracksb):
487
+ pdist = matching.iou_distance(stracksa, stracksb)
488
+ pairs = np.where(pdist < 0.15)
489
+ dupa, dupb = list(), list()
490
+ for p, q in zip(*pairs):
491
+ timep = stracksa[p].frame_id - stracksa[p].start_frame
492
+ timeq = stracksb[q].frame_id - stracksb[q].start_frame
493
+ if timep > timeq:
494
+ dupb.append(q)
495
+ else:
496
+ dupa.append(p)
497
+ resa = [t for i, t in enumerate(stracksa) if not i in dupa]
498
+ resb = [t for i, t in enumerate(stracksb) if not i in dupb]
499
+ return resa, resb
500
+
501
+ def get_weights(url, output_file):
502
+ response = requests.get(url, stream=True)
503
+ with open(output_file, "wb") as handle:
504
+ for data in tqdm(response.iter_content(), desc="Downloading weights ..."):
505
+ handle.write(data)