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
dnt/__init__.py CHANGED
@@ -1,2 +1,5 @@
1
1
  import sys, os
2
- sys.path.append(os.path.join(os.path.dirname(__file__)))
2
+ sys.path.append(os.path.dirname(__file__))
3
+ sys.path.append(os.path.join(os.path.dirname(__file__), 'third_party/fast-reid'))
4
+
5
+ __version__='0.3.1.8'
dnt/analysis/__init__.py CHANGED
@@ -3,4 +3,6 @@ import sys
3
3
 
4
4
  sys.path.append(os.path.dirname(__file__))
5
5
 
6
- from stop import StopAnalyzer
6
+ from stop3 import StopAnalyzer
7
+ from count import Count
8
+ from interaction2 import YieldAnalyzer
dnt/analysis/count.py ADDED
@@ -0,0 +1,107 @@
1
+ # pylint: disable=too-many-arguments
2
+ '''
3
+ This script is used to count the number of tracks that passing a reference line for post-analysis
4
+ last modified: 2021-09-30
5
+ '''
6
+ from shapely.geometry import Polygon, LineString
7
+ import geopandas as gpd
8
+ import pandas as pd
9
+ from tqdm import tqdm
10
+ import numpy as np
11
+
12
+ class Count:
13
+ '''
14
+ Count tracks that passing a reference line for post-analysis
15
+ Methods:
16
+ __init__(): initialize the class
17
+ count_tracks_by_line():
18
+ count tracks that passing a reference line for post-analysis
19
+ '''
20
+ def __init__(self) -> None:
21
+ self.track_fields = ['frame', 'track_id', 'x', 'y', 'w', 'h', 'r1', 'r2', 'r3', 'r4']
22
+
23
+ def count_tracks_by_line(self,
24
+ tracks:pd.DataFrame=None,
25
+ track_file:str=None,
26
+ line: LineString=None,
27
+ video_index:int=None,
28
+ video_tot:int=None,
29
+ verbose:bool=True) -> pd.DataFrame:
30
+ '''
31
+ Count tracks that passing a reference line for post-analysis
32
+ Inputs:
33
+ tracks - a DataFrame of tracks, if None (default), read track_file
34
+ track_file - a txt file contains tracks,
35
+ line - the reference line, LineString(pointA, pointB)
36
+ video_index - the index of video for processing
37
+ video_tot - the total number of videos
38
+ verbose - if True, show progress bar
39
+ Return:
40
+ A DataFrame of track_id, frame, direction, count
41
+ '''
42
+ # Load tracks
43
+ if tracks is None:
44
+ tracks = pd.read_csv(track_file, header=None)
45
+ if len(tracks.columns) != len(self.track_fields):
46
+ raise Exception("The tracks format is incorrect!")
47
+ tracks.columns = self.track_fields
48
+ track_ids = tracks['track_id'].unique()
49
+
50
+ # Create a GeoDataFrame of tracks
51
+ geo = tracks.apply(lambda track: Polygon([(track['x'], track['y']),
52
+ (track['x'] + track['w'], track['y']),
53
+ (track['x'] + track['w'], track['y'] + track['h']),
54
+ (track['x'], track['y'] + track['h'])]),
55
+ axis =1)
56
+ geo_tracks = gpd.GeoDataFrame(tracks, geometry=geo)
57
+ point_a = np.array(line.coords[0])
58
+ point_b = np.array(line.coords[1])
59
+
60
+ # Interate through all tracks
61
+ if verbose:
62
+ pbar = tqdm(total=len(track_ids), unit=' tracks')
63
+ if video_index and video_tot:
64
+ pbar.set_description_str("Counting {} of {}".format(video_index, video_tot))
65
+ else:
66
+ pbar.set_description_str("Counting")
67
+ intersected_tracks = []
68
+ intersected_frames = []
69
+ intersected_direct = []
70
+
71
+ for track_id in track_ids:
72
+ selected = geo_tracks.loc[(geo_tracks['track_id']==track_id)].copy()
73
+ if len(selected)>0:
74
+ selected['intersected'] = line.intersects(selected.geometry).values.tolist()
75
+ intersected = selected.loc[(selected['intersected']==True)].copy()
76
+ if len(intersected) > 0:
77
+ intersected.sort_values(by='frame', inplace=True)
78
+ if not track_id in intersected_tracks:
79
+ intersected_tracks.append(track_id)
80
+ frame_pos = int(len(intersected)/2)
81
+ intersected_frames.append(intersected['frame'].values[frame_pos])
82
+
83
+ # center point of the first frame
84
+ point_c = np.array((intersected.iloc[0]['x'] + intersected.iloc[0]['w']/2,
85
+ intersected.iloc[0]['y'] + intersected.iloc[0]['h']/2))
86
+ d = 2 # right
87
+ if np.cross(point_c-point_a, point_b-point_a) < 0:
88
+ d = 1 # left
89
+ intersected_direct.append(d)
90
+ if verbose:
91
+ pbar.update()
92
+
93
+ if verbose:
94
+ pbar.close()
95
+
96
+ results = pd.DataFrame(
97
+ {
98
+ 'track_id': intersected_tracks,
99
+ 'frame': intersected_frames,
100
+ 'direction': intersected_direct,
101
+ }
102
+ )
103
+ results.sort_values(by='frame', inplace=True)
104
+ results = results.reset_index(drop=True)
105
+ results['count'] = results.index + 1
106
+
107
+ return results
@@ -0,0 +1,518 @@
1
+ """
2
+ This module is used to analyze the interaction between two tracks.
3
+ Author: Zhenyu Wang
4
+ Date: 2023/10/20
5
+ Email: wonstran@hotmail.com
6
+ Updates:
7
+ 2025/03/19: Add the function of nearmiss based on PET
8
+ 2023/10/20: Initial version
9
+ """
10
+ from shapely.geometry import Point, Polygon, LineString, box
11
+ from shapely import intersection, distance, intersects
12
+ from shapelysmooth import taubin_smooth, chaikin_smooth, catmull_rom_smooth
13
+ import geopandas as gpd, pandas as pd
14
+ from tqdm import tqdm
15
+ import numpy as np
16
+ from dnt.label.labeler2 import Labeler
17
+ import os
18
+
19
+ class YieldAnalyzer:
20
+ def __init__(self,
21
+ waiting_dist_p:int=600,
22
+ waiting_dist_y:int=300,
23
+ leading_p:bool=False,
24
+ leading_axis_p:str='y',
25
+ leading_y:bool=True,
26
+ leading_axis_y:str='x',
27
+ yield_gap:int=10,
28
+ fps:int=30,
29
+ ref_point='bc',
30
+ ref_offset:tuple=(0,0),
31
+ filter_buffer:int=0,
32
+ p_zone:Polygon=None,
33
+ y_zone:Polygon=None) -> None:
34
+ '''
35
+ Parameters:
36
+ threshold: the hyperparameter to determine if a yield event (frame difference <=yield_gap*fps), default is 3 seconds
37
+ fps: frames per sencond, default is 30
38
+ ref_point: the reference point for lane recognition
39
+ br (buttom-right, default), bl (bottom-left), bc (bottom-center)
40
+ tl (top-left), tr (top-right), tc (top-center)
41
+ cc (center-center), cl (center-left), cr (center-right)
42
+ ref_offset: the offset (x, y) for reference point, default is (0, 0)
43
+ filter_buffer: the buffer between two track frames, default is 0 means tracks will be paired only if two tracks are overlapped in time
44
+ '''
45
+ self.waiting_dist_p = waiting_dist_p
46
+ self.waiting_dist_y = waiting_dist_y
47
+ self.leading_p = leading_p
48
+ self.leading_axis_p = leading_axis_p
49
+ self.leading_y = leading_y
50
+ self.leading_axis_y = leading_axis_y
51
+ self.yield_gap = yield_gap
52
+ self.fps = fps
53
+ self.ref_point = ref_point
54
+ self.ref_offset = ref_offset
55
+ self.filter_buffer = filter_buffer
56
+ self.p_zone = p_zone
57
+ self.y_zone = y_zone
58
+
59
+ def analyze(self, tracks_p:pd.DataFrame, tracks_y:pd.DataFrame, name_p:str='', name_y:str=''):
60
+ '''
61
+ Parameters:
62
+ tracks_p: tracks with priority
63
+ tracks_y: tracks should yield to tracks_p
64
+ '''
65
+ tracks_p = YieldAnalyzer.add_field_names(tracks_p)
66
+ tracks_y = YieldAnalyzer.add_field_names(tracks_y)
67
+
68
+ tracks_p = self.gen_ref(tracks_p, info=name_p)
69
+ tracks_y = self.gen_ref(tracks_y, info=name_y)
70
+
71
+ trajectories_p = self.gen_trajectory(tracks_p, info=name_p)
72
+ trajectories_y = self.gen_trajectory(tracks_y, info=name_y)
73
+
74
+ intersect_pairs = self.scan_intersections(trajectories_p, trajectories_y)
75
+ if (self.p_zone is not None) and (self.y_zone is not None):
76
+ intersect_pairs = self.scan_yield_events_byzone(intersect_pairs, tracks_p, tracks_y)
77
+ else:
78
+ intersect_pairs = self.scan_yield_events(intersect_pairs, tracks_p, tracks_y)
79
+
80
+ return intersect_pairs
81
+
82
+ def gen_ref(self, tracks:pd.DataFrame, info:str='', video_index:int=None, video_tot:int=None)->pd.DataFrame:
83
+ if video_index and video_tot:
84
+ tqdm.pandas(desc='Generating ref {}, {} of {}'.format(info, video_index, video_tot), unit='frames')
85
+ else:
86
+ tqdm.pandas(desc='Generating ref {}'.format(info), unit='frames')
87
+
88
+ if self.ref_point == 'cc':
89
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + track['w']//2 + self.ref_offset[0],
90
+ track['y'] + track['h']//2 + self.ref_offset[1]]), axis=1)
91
+ elif self.ref_point == 'tc':
92
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + track['w']//2 + self.ref_offset[0],
93
+ track['y'] + self.ref_offset[1]]), axis=1)
94
+ elif self.ref_point == 'bc':
95
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + track['w']//2 + self.ref_offset[0],
96
+ track['y'] + track['h'] + self.ref_offset[1]]), axis=1)
97
+ elif self.ref_point == 'cl':
98
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + self.ref_offset[0],
99
+ track['y'] + track['h']//2 + self.ref_offset[1]]), axis=1)
100
+ elif self.ref_point == 'cr':
101
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + track['w'] + self.ref_offset[0],
102
+ track['y'] + track['h']//2 + self.ref_offset[1]]), axis=1)
103
+ elif self.ref_point == 'tl':
104
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + self.ref_offset[0],
105
+ track['y'] + self.ref_offset[1]]), axis=1)
106
+ elif self.ref_point == 'tr':
107
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + track['w'] + self.ref_offset[0],
108
+ track['y'] + self.ref_offset[1]]), axis=1)
109
+ elif self.ref_point == 'bl':
110
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + self.ref_offset[0],
111
+ track['y'] + tracks['h'] + self.ref_offset[1]]), axis=1)
112
+ elif self.ref_point == 'br':
113
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + track['w'] + self.ref_offset[0],
114
+ track['y'] + track['h'] + self.ref_offset[1]]), axis=1)
115
+ else:
116
+ tracks[['ref_x', 'ref_y']] = tracks.progress_apply(lambda track: pd.Series([track['x'] + track['w']//2 + self.ref_offset[0],
117
+ track['y'] + track['h'] + self.ref_offset[1]]), axis=1)
118
+
119
+ return tracks
120
+
121
+ def gen_trajectory(self, tracks:pd.DataFrame, info:str='', video_index:int=None, video_tot:int=None)->gpd.GeoDataFrame:
122
+
123
+ ids = tracks['track'].unique()
124
+ results = []
125
+ lines = []
126
+ pbar = tqdm(total=len(ids), unit='track')
127
+ if video_index and video_tot:
128
+ pbar.desc = 'Generating trajectory {}, {} of {}'.format(info, video_index, video_tot)
129
+ else:
130
+ pbar.desc = 'Generating trajectory {}'.format(info)
131
+
132
+ for id in ids:
133
+ frames = tracks[tracks['track']==id].sort_values(by=['frame'])
134
+ line = LineString(list(zip(frames['ref_x'].values.tolist(), frames['ref_y'].values.tolist())))
135
+ results.append([id, frames['frame'].values, frames['ref_x'].values, frames['ref_y'].values])
136
+ lines.append(line)
137
+ pbar.update()
138
+ pbar.close()
139
+
140
+ df = pd.DataFrame(results, columns=['track', 'frames', 'ref_x', 'ref_y'])
141
+ return gpd.GeoDataFrame(df, geometry=lines)
142
+
143
+ def scan_intersections(self, trajectories_p:gpd.GeoDataFrame, trajectories_y:gpd.GeoDataFrame,
144
+ video_index:int=None, video_tot:int=None):
145
+
146
+ results = []
147
+ points = []
148
+ buffer = self.filter_buffer*self.fps
149
+
150
+ pbar = tqdm(total=len(trajectories_p)*len(trajectories_y), unit=' pair')
151
+ if video_index and video_tot:
152
+ pbar.desc = 'Scan intesections {} of {}'.format(video_index, video_tot)
153
+ else:
154
+ pbar.desc = 'Scan intesections'
155
+ for index1, trj_p in trajectories_p.iterrows():
156
+ for index2, trj_y in trajectories_y.iterrows():
157
+ '''
158
+ if (trj_p['track'] == 511) and (trj_y['track'] == 132590):
159
+ print(trj_p['frames'].min(), trj_p['frames'].max())
160
+ print(trj_y['frames'].min(), trj_y['frames'].max())
161
+ input('...')
162
+ '''
163
+
164
+ if ((trj_p['frames'].min() > (trj_y['frames'].max() + buffer)) or
165
+ (trj_y['frames'].min() > (trj_p['frames'].max() + buffer))):
166
+ pass
167
+ else:
168
+ geo_intersect = intersection(trj_p.geometry, trj_y.geometry)
169
+ if not geo_intersect.is_empty:
170
+ point = self.__recursion(geo_intersect)
171
+ point_xy = np.array([point.x, point.y])
172
+ '''
173
+ if (trj_p['track'] == 2414) & (trj_y['track'] == 386456):
174
+ plt.gca().invert_yaxis()
175
+ plt.plot(*trj_p.geometry.xy, color='red')
176
+ plt.plot(*trj_y.geometry.xy, color='green')
177
+ plt.scatter(*point.xy)
178
+ plt.savefig('/mnt/d/a.jpg')
179
+
180
+ import cv2
181
+ img = cv2.imread('/mnt/d/b.png')
182
+ for x, y in list(zip(trj_p['ref_x'], trj_p['ref_y'])):
183
+ img = cv2.circle(img, (x, y), 1, (0, 0, 255))
184
+ for x, y in list(zip(trj_y['ref_x'], trj_y['ref_y'])):
185
+ img = cv2.circle(img, (x, y), 1, (0, 255, 0))
186
+ img = cv2.circle(img, (int(point.x), int(point.y)), 5, (255, 255, 255), thickness=-1)
187
+ print(int(point.x), int(point.y))
188
+ cv2.imwrite('/mnt/d/c.jpg', img)
189
+ input('...')
190
+ '''
191
+ ref_pxy = np.array(list(zip(trj_p['ref_x'], trj_p['ref_y'])))
192
+ index_p = self.__get_closest_index(ref_pxy, point_xy)
193
+ frame_p = trj_p['frames'][index_p]
194
+
195
+ ref_yxy = np.array(list(zip(trj_y['ref_x'], trj_y['ref_y'])))
196
+ index_y = self.__get_closest_index(ref_yxy, point_xy)
197
+ frame_y = trj_y['frames'][index_y]
198
+
199
+ results.append([trj_p['track'], frame_p, trj_y['track'], frame_y, frame_y-frame_p])
200
+ points.append(point)
201
+ pbar.update()
202
+
203
+ pbar.close()
204
+
205
+ df = pd.DataFrame(results, columns=['track_p', 'frame_p', 'track_y', 'frame_y', 'frame_gap'])
206
+ return gpd.GeoDataFrame(df, geometry=points)
207
+
208
+ def scan_yield_events(self, pairs:gpd.GeoDataFrame, tracks_p:gpd.GeoDataFrame, tracks_y:gpd.GeoDataFrame,
209
+ video_index:int=None, video_tot:int=None)->pd.DataFrame:
210
+
211
+ pbar = tqdm(total=len(pairs), unit=' pair')
212
+ if video_index and video_tot:
213
+ pbar.desc = 'Scan events {} of {}'.format(video_index, video_tot)
214
+ else:
215
+ pbar.desc = 'Scan events'
216
+ for index, pair in pairs.iterrows():
217
+
218
+ if pair['frame_p'] < pair['frame_y']:
219
+
220
+ selected = tracks_y[(tracks_y['track']==pair['track_y']) & (tracks_y['frame']<=pair['frame_y'])].copy() # find the frames for track_y before reaching conflict point
221
+ selected['dif'] = selected['frame'].apply(lambda f: abs(f - pair['frame_p'])) # calculate the frame difference between each before frame and the conflict frame
222
+ selected = selected[selected['dif']<=self.yield_gap] # the frame difference should <= self.yield_gap
223
+ closest = selected[selected['dif']==selected['dif'].min()] # find the closest frame
224
+ if len(closest)>0:
225
+ closest_point = Point(closest['x'].iloc[0]+closest['w'].iloc[0]/2,
226
+ closest['y'].iloc[0]+closest['h'].iloc[0]) # find the cloest point
227
+ dist = distance(closest_point, pair.geometry) # calculate the distance
228
+ pairs.at[index, 'dist_y'] = dist
229
+ inwaiting = 1 if dist<=self.waiting_dist_y else 0
230
+
231
+ if self.leading_y:
232
+ isleading = 1 if self.__is_leading(pair['track_y'], closest['frame'].iloc[0], closest['x'].iloc[0],
233
+ closest['y'].iloc[0], pair.geometry.x, pair.geometry.y, tracks_y, self.leading_axis_y) else 0
234
+ else:
235
+ isleading = 1
236
+
237
+ if (inwaiting == 1) and (isleading == 1):
238
+ pairs.at[index, 'event'] = 'yield'
239
+
240
+ pairs.at[index, 'closest_frame'] = closest['frame'].iloc[0]
241
+
242
+ elif pair['frame_p'] >= pair['frame_y']:
243
+ selected = tracks_p[(tracks_p['track']==pair['track_p']) & (tracks_p['frame']<=pair['frame_p'])].copy()
244
+ selected['dif'] = selected['frame'].apply(lambda f: abs(f - pair['frame_y']))
245
+ selected = selected[selected['dif']<=self.yield_gap]
246
+ closest = selected[selected['dif']==selected['dif'].min()]
247
+ if len(closest)>0:
248
+ closest_point = Point(closest['x'].iloc[0]+closest['w'].iloc[0]/2,
249
+ closest['y'].iloc[0]+closest['h'].iloc[0])
250
+ dist = distance(closest_point, pair.geometry)
251
+ inwaiting = 1 if dist<=self.waiting_dist_p else 0
252
+ pairs.at[index, 'dist_p'] = dist
253
+ if self.leading_p:
254
+ isleading = 1 if self.__is_leading(pair['track_p'], closest['frame'].iloc[0], closest['x'].iloc[0],
255
+ closest['y'].iloc[0], pair.geometry.x, pair.geometry.y, tracks_p, self.leading_axis_p) else 0
256
+ else:
257
+ isleading = 1
258
+
259
+ if (inwaiting == 1) and (isleading == 1):
260
+ pairs.at[index, 'event'] = 'not_yield'
261
+
262
+ pairs.at[index, 'closest_frame'] = closest['frame'].iloc[0]
263
+
264
+ pbar.update()
265
+
266
+ pbar.close()
267
+
268
+ return self.__export(pairs)
269
+
270
+ def scan_yield_events_byzone(self, pairs:gpd.GeoDataFrame, tracks_p:gpd.GeoDataFrame, tracks_y:gpd.GeoDataFrame,
271
+ video_index:int=None, video_tot:int=None)->pd.DataFrame:
272
+
273
+ pbar = tqdm(total=len(pairs), unit=' pair')
274
+ if video_index and video_tot:
275
+ pbar.desc = 'Scan events {} of {}'.format(video_index, video_tot)
276
+ else:
277
+ pbar.desc = 'Scan events'
278
+ for index, pair in pairs.iterrows():
279
+
280
+ if pair['frame_p'] < pair['frame_y']:
281
+
282
+ selected = tracks_y[(tracks_y['track']==pair['track_y']) & (tracks_y['frame']<=pair['frame_y'])].copy() # find the frames for track_y before reaching conflict point
283
+ selected['dif'] = selected['frame'].apply(lambda f: abs(f - pair['frame_p'])) # calculate the frame difference between each before frame and the conflict frame
284
+ selected = selected[selected['dif']<=self.yield_gap] # the frame difference should <= self.yield_gap
285
+ closest = selected[selected['dif']==selected['dif'].min()] # find the closest frame
286
+ if len(closest)>0:
287
+ x, y, w, h = closest['x'].iloc[0], closest['y'].iloc[0], closest['w'].iloc[0], closest['h'].iloc[0]
288
+ closest_bbox = Polygon([(x, y), (x + w, y), (x + w, y + h), (x, y + h)])
289
+
290
+ inwaiting = 1 if intersects(closest_bbox, self.y_zone) else 0
291
+ pairs.at[index, 'dist_y'] = -1
292
+ if self.leading_y:
293
+ isleading = 1 if self.__is_leading(pair['track_y'], closest['frame'].iloc[0], closest['x'].iloc[0],
294
+ closest['y'].iloc[0], pair.geometry.x, pair.geometry.y, tracks_y, self.leading_axis_y) else 0
295
+ else:
296
+ isleading = 1
297
+
298
+ if (inwaiting == 1) and (isleading == 1):
299
+ pairs.at[index, 'event'] = 'yield'
300
+
301
+ pairs.at[index, 'closest_frame'] = closest['frame'].iloc[0]
302
+
303
+ elif pair['frame_p'] >= pair['frame_y']:
304
+ selected = tracks_p[(tracks_p['track']==pair['track_p']) & (tracks_p['frame']<=pair['frame_p'])].copy()
305
+ selected['dif'] = selected['frame'].apply(lambda f: abs(f - pair['frame_y']))
306
+ selected = selected[selected['dif']<=self.yield_gap]
307
+ closest = selected[selected['dif']==selected['dif'].min()]
308
+ if len(closest)>0:
309
+ x, y, w, h = closest['x'].iloc[0], closest['y'].iloc[0], closest['w'].iloc[0], closest['h'].iloc[0]
310
+ closest_bbox = Polygon([(x, y), (x + w, y), (x + w, y + h), (x, y + h)])
311
+
312
+ inwaiting = 1 if intersects(closest_bbox, self.p_zone) else 0
313
+ pairs.at[index, 'dist_p'] = -1
314
+ if self.leading_p:
315
+ isleading = 1 if self.__is_leading(pair['track_p'], closest['frame'].iloc[0], closest['x'].iloc[0],
316
+ closest['y'].iloc[0], pair.geometry.x, pair.geometry.y, tracks_p, self.leading_axis_p) else 0
317
+ else:
318
+ isleading = 1
319
+
320
+ if (inwaiting == 1) and (isleading == 1):
321
+ pairs.at[index, 'event'] = 'not_yield'
322
+
323
+ pairs.at[index, 'closest_frame'] = closest['frame'].iloc[0]
324
+
325
+ pbar.update()
326
+
327
+ pbar.close()
328
+
329
+ return self.__export(pairs)
330
+
331
+
332
+ def __export(self, pairs:gpd.GeoDataFrame):
333
+ pairs['int_x'] = pairs.geometry.x
334
+ pairs['int_y'] = pairs.geometry.y
335
+ return pd.DataFrame(pairs.drop(columns=['geometry']))
336
+
337
+ def __recursion(self, intersect):
338
+ if intersect.geom_type == 'Point':
339
+ return Point(intersect.coords[0])
340
+
341
+ elif intersect.geom_type == 'MultiPoint':
342
+ return Point(intersect.geoms[0].x, intersect.geoms[0].y)
343
+
344
+ elif intersect.geom_type == 'LineString':
345
+ return Point(intersect.coords[0])
346
+
347
+ elif intersect.geom_type == 'MultiLineString':
348
+ return Point(intersect.geoms[0].coords[0])
349
+
350
+ else:
351
+ for geom in intersect.geoms:
352
+ return self.__recursion(geom)
353
+
354
+ def __get_closest_index(self, ref:np.array, point:np.array) -> int:
355
+ return np.argmin(np.sqrt(np.sum(np.square(ref - point), axis=1)))
356
+
357
+ def __is_leading(self, track_id:int, frame_close:int, close_x:int, close_y:int, int_x:int, int_y:int,
358
+ tracks:gpd.GeoDataFrame, leading_axis:str):
359
+
360
+ min_x = min(close_x, int_x)
361
+ max_x = max(close_x, int_x)
362
+ min_y = min(close_y, int_y)
363
+ max_y = max(close_y, int_y)
364
+ if leading_axis == 'x':
365
+ leadings = tracks[(tracks['track']!=track_id) & (tracks['frame']==frame_close) &
366
+ (tracks['ref_x']>=min_x) & (tracks['ref_x']<=max_x)]
367
+ elif leading_axis == 'y':
368
+ leadings = tracks[(tracks['track']!=track_id) & (tracks['frame']==frame_close) &
369
+ (tracks['ref_y']>=min_y) & (tracks['ref_y']<=max_y)]
370
+ elif leading_axis == 'xy':
371
+ leadings = tracks[(tracks['track']!=track_id) & (tracks['frame']==frame_close) &
372
+ (tracks['ref_x']>=min_x) & (tracks['ref_x']<=max_x) &
373
+ (tracks['ref_y']>=min_y) & (tracks['ref_y']<=max_y)]
374
+
375
+ if len(leadings) > 0:
376
+ return False
377
+ else:
378
+ return True
379
+
380
+ def __get_waiting_trj_y(self, track_id:int, frame_id_p:int, frame_id_y:int, intersect_point:Point, trajectories:gpd.GeoDataFrame) -> any:
381
+
382
+ result = -1
383
+ if frame_id_p < frame_id_y:
384
+ selected = trajectories[trajectories['track']==track_id]
385
+ df = pd.DataFrame(np.vstack((selected['frames'].tolist(), selected['ref_x'].tolist(), selected['ref_y'].tolist())).T,
386
+ columns=['frame', 'x', 'y'])
387
+ df = df.loc[df['frame']<=frame_id_y]
388
+ df['dif'] = df['frame'].apply(lambda f: abs((f - frame_id_p)))
389
+ closest = df[df['dif']==df['dif'].min()]
390
+ closest_point = Point(closest['x'].ioc[0], closest['y'].ioc[0])
391
+ dist = distance(closest, intersect_point)
392
+
393
+ return result
394
+
395
+ @staticmethod
396
+ def add_field_names(tracks: pd.DataFrame)->pd.DataFrame:
397
+ if len(tracks.columns)==10:
398
+ tracks.columns = ['frame', 'track', 'x', 'y', 'w', 'h', 'score', 'cls', 'r3','r4']
399
+ tracks['ref_x'] = -1
400
+ tracks['ref_y'] = -1
401
+ elif len(tracks.columns) == 12:
402
+ tracks.columns = ['frame', 'track', 'x', 'y', 'w', 'h', 'score', 'cls', 'r3','r4',
403
+ 'ref_x', 'ref_y']
404
+ else:
405
+ raise Exception('The number of fields is invalid.')
406
+ return tracks
407
+
408
+ @staticmethod
409
+ def draw_event_clips(yields:pd.DataFrame, tracks_p:pd.DataFrame, tracks_y:pd.DataFrame, input_video:str, out_path:str,
410
+ method:str='all', random_number:int=10, event_list:list=None, size:int=1, thick:int=2, padding:int=0,
411
+ show_track:bool=False, show_desc:bool=False, verbose:bool=True,
412
+ video_index:int=None, video_tot:int=None):
413
+ '''
414
+ Parameters:
415
+ - yields: the dataframe of stop events
416
+ - tracks_p: the dataframe of tracks with priority
417
+ - tracks_y: the dataframe of tracks should yield
418
+ - input_video: the raw video file, if None, generate the label files only
419
+ - out_path: the folder for outputing track clips
420
+ - method: 'all' (default) - all tracks, 'specify' - specify events,
421
+ 'yield' - yield events, 'not_yield' - non-yield events, 'none' - non interaction events
422
+ - random_number: the number of track ids if method == 'random'
423
+ - event_list: the list of events [(track_p_id, track_y_id)] if method == 'specify'
424
+ - size: font size, default is 1
425
+ - thick: line thinckness, defualt is 2
426
+ - padding: add addtional frames at beggining and ending, default is 0
427
+ - show_track: show track id, default is False
428
+ - show_desc: show event desc, default is Falase
429
+ - verbose: if show progressing bar, default is True
430
+ - video_idex: the index of the video in processing
431
+ - video_tot: the total number of videos
432
+
433
+ Return:
434
+ - A list of dataframes for labels, ['frame','type','coords','color','size','thick','desc']
435
+ '''
436
+
437
+ tracks_p = YieldAnalyzer.add_field_names(tracks_p)
438
+ tracks_y = YieldAnalyzer.add_field_names(tracks_y)
439
+
440
+ tracks_p_grouped = tracks_p.groupby('track')
441
+ tracks_y_grouped = tracks_y.groupby('track')
442
+
443
+
444
+ if method == 'all':
445
+ events = yields
446
+ elif method == 'specify':
447
+ events = []
448
+ for p, y in event_list:
449
+ events.append(yields[(yields['track_p']==p) & (yields['track_y']==y)])
450
+ events = pd.concat(events)
451
+ elif method == 'yield':
452
+ events = yields[yields['event']=='yield'].copy()
453
+ elif method == 'not_yield':
454
+ events = yields[yields['event']=='not_yield'].copy()
455
+ elif method == 'event':
456
+ events = yields[yields['event'].isin(['yield', 'not_yield'])].copy()
457
+ elif method == 'none':
458
+ events = yields[~yields['event'].isin(['yield', 'not_yield'])].copy()
459
+
460
+ pbar = tqdm(total= len(events) , unit='event')
461
+ if video_index and video_tot:
462
+ pbar.set_description_str("Generating labeles for yielding events {} of {}".format(video_index, video_tot))
463
+ else:
464
+ pbar.set_description_str("Generating labels for yielding events")
465
+
466
+ labeler = Labeler()
467
+ for index, event in events.iterrows():
468
+ result = []
469
+ track_p_id = event['track_p']
470
+ track_y_id = event['track_y']
471
+ int_x = int(event['int_x'])
472
+ int_y = int(event['int_y'])
473
+
474
+ if event['event'] == 'yield':
475
+ desc = 'yield'
476
+ color = (0, 255, 0)
477
+ elif event['event'] == 'not_yield':
478
+ desc = 'not yield'
479
+ color = (0, 0, 255)
480
+ else:
481
+ desc = 'no interaction'
482
+ color = (255, 0, 0)
483
+
484
+ frames_p = tracks_p_grouped.get_group(track_p_id)
485
+ frames_y = tracks_y_grouped.get_group(track_y_id)
486
+ frames = pd.concat([frames_p, frames_y])
487
+ for index2, frame in frames.iterrows():
488
+ label_text = ''
489
+ if show_track:
490
+ label_text+='| T:'+str(int(frame['track']))
491
+
492
+ if show_desc:
493
+ label_text+= ' | '+desc
494
+
495
+ result.append([frame['frame'], 'bbox', [(frame['x'], frame['y']), (frame['x']+frame['w'], frame['y']+frame['h'])],
496
+ color, size, thick, label_text])
497
+ result.append([frame['frame'], 'box', [(int_x - 5, int_y - 5), (int_x + 5, int_y + 5)],
498
+ (255, 255, 0), size, thick, ''])
499
+
500
+ df = pd.DataFrame(result, columns=['frame','type','coords','color','size','thick','desc'])
501
+
502
+ if out_path:
503
+ file_name = os.path.join(out_path, str(track_p_id)+'-'+str(track_y_id)+'_label.csv')
504
+ df.to_csv(file_name, index=False)
505
+
506
+ if input_video:
507
+ file_name = os.path.join(out_path, str(track_p_id)+'-'+str(track_y_id)+'_label.mp4')
508
+ min_frame = df['frame'].min() - padding
509
+ max_frame = df['frame'].max() + padding
510
+ labeler.draw(input_video=input_video, output_video=file_name, draws=df,
511
+ start_frame=min_frame, end_frame=max_frame, verbose=False)
512
+
513
+ if verbose:
514
+ pbar.update()
515
+
516
+ pbar.close()
517
+
518
+
@@ -0,0 +1,12 @@
1
+ from shapely.geometry import Point, Polygon, LineString, box
2
+ import geopandas as gpd, pandas as pd
3
+ import datetime
4
+ from tqdm import tqdm
5
+ from ultralytics import YOLO
6
+
7
+ class Positioner():
8
+ def __init__(self) -> None:
9
+ pass
10
+
11
+
12
+