dnt 0.2.4__py3-none-any.whl → 0.3.1.7__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.

Potentially problematic release.


This version of dnt might be problematic. Click here for more details.

Files changed (311) hide show
  1. dnt/__init__.py +3 -2
  2. dnt/analysis/__init__.py +3 -2
  3. dnt/analysis/count.py +54 -37
  4. dnt/analysis/interaction2.py +518 -0
  5. dnt/analysis/stop.py +22 -17
  6. dnt/analysis/stop2.py +289 -0
  7. dnt/analysis/stop3.py +758 -0
  8. dnt/detect/signal/detector.py +326 -0
  9. dnt/detect/timestamp.py +105 -0
  10. dnt/detect/yolov8/detector.py +179 -36
  11. dnt/detect/yolov8/segmentor.py +60 -2
  12. dnt/engine/__init__.py +8 -0
  13. dnt/engine/bbox_interp.py +83 -0
  14. dnt/engine/bbox_iou.py +20 -0
  15. dnt/engine/cluster.py +31 -0
  16. dnt/engine/iob.py +66 -0
  17. dnt/filter/filter.py +333 -2
  18. dnt/label/labeler.py +4 -4
  19. dnt/label/labeler2.py +605 -0
  20. dnt/shared/__init__.py +2 -1
  21. dnt/shared/data/coco.names +0 -0
  22. dnt/shared/data/openimages.names +0 -0
  23. dnt/shared/data/voc.names +0 -0
  24. dnt/shared/download.py +12 -0
  25. dnt/shared/synhcro.py +150 -0
  26. dnt/shared/util.py +17 -4
  27. dnt/third_party/fast-reid/__init__.py +1 -0
  28. dnt/third_party/fast-reid/configs/Base-AGW.yml +19 -0
  29. dnt/third_party/fast-reid/configs/Base-MGN.yml +12 -0
  30. dnt/third_party/fast-reid/configs/Base-SBS.yml +63 -0
  31. dnt/third_party/fast-reid/configs/Base-bagtricks.yml +76 -0
  32. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R101-ibn.yml +12 -0
  33. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50-ibn.yml +11 -0
  34. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50.yml +7 -0
  35. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_S50.yml +11 -0
  36. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R101-ibn.yml +12 -0
  37. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50-ibn.yml +11 -0
  38. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50.yml +7 -0
  39. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_S50.yml +11 -0
  40. dnt/third_party/fast-reid/configs/DukeMTMC/mgn_R50-ibn.yml +11 -0
  41. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R101-ibn.yml +12 -0
  42. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50-ibn.yml +11 -0
  43. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50.yml +7 -0
  44. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_S50.yml +11 -0
  45. dnt/third_party/fast-reid/configs/MOT17/AGW_R101-ibn.yml +12 -0
  46. dnt/third_party/fast-reid/configs/MOT17/AGW_R50-ibn.yml +11 -0
  47. dnt/third_party/fast-reid/configs/MOT17/AGW_R50.yml +7 -0
  48. dnt/third_party/fast-reid/configs/MOT17/AGW_S50.yml +11 -0
  49. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R101-ibn.yml +12 -0
  50. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50-ibn.yml +11 -0
  51. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50.yml +7 -0
  52. dnt/third_party/fast-reid/configs/MOT17/bagtricks_S50.yml +11 -0
  53. dnt/third_party/fast-reid/configs/MOT17/mgn_R50-ibn.yml +11 -0
  54. dnt/third_party/fast-reid/configs/MOT17/sbs_R101-ibn.yml +12 -0
  55. dnt/third_party/fast-reid/configs/MOT17/sbs_R50-ibn.yml +11 -0
  56. dnt/third_party/fast-reid/configs/MOT17/sbs_R50.yml +7 -0
  57. dnt/third_party/fast-reid/configs/MOT17/sbs_S50.yml +11 -0
  58. dnt/third_party/fast-reid/configs/MOT20/AGW_R101-ibn.yml +12 -0
  59. dnt/third_party/fast-reid/configs/MOT20/AGW_R50-ibn.yml +11 -0
  60. dnt/third_party/fast-reid/configs/MOT20/AGW_R50.yml +7 -0
  61. dnt/third_party/fast-reid/configs/MOT20/AGW_S50.yml +11 -0
  62. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R101-ibn.yml +12 -0
  63. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50-ibn.yml +11 -0
  64. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50.yml +7 -0
  65. dnt/third_party/fast-reid/configs/MOT20/bagtricks_S50.yml +11 -0
  66. dnt/third_party/fast-reid/configs/MOT20/mgn_R50-ibn.yml +11 -0
  67. dnt/third_party/fast-reid/configs/MOT20/sbs_R101-ibn.yml +12 -0
  68. dnt/third_party/fast-reid/configs/MOT20/sbs_R50-ibn.yml +11 -0
  69. dnt/third_party/fast-reid/configs/MOT20/sbs_R50.yml +7 -0
  70. dnt/third_party/fast-reid/configs/MOT20/sbs_S50.yml +11 -0
  71. dnt/third_party/fast-reid/configs/MSMT17/AGW_R101-ibn.yml +12 -0
  72. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50-ibn.yml +11 -0
  73. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50.yml +7 -0
  74. dnt/third_party/fast-reid/configs/MSMT17/AGW_S50.yml +11 -0
  75. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R101-ibn.yml +13 -0
  76. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50-ibn.yml +12 -0
  77. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50.yml +7 -0
  78. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_S50.yml +12 -0
  79. dnt/third_party/fast-reid/configs/MSMT17/mgn_R50-ibn.yml +11 -0
  80. dnt/third_party/fast-reid/configs/MSMT17/sbs_R101-ibn.yml +12 -0
  81. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50-ibn.yml +11 -0
  82. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50.yml +7 -0
  83. dnt/third_party/fast-reid/configs/MSMT17/sbs_S50.yml +11 -0
  84. dnt/third_party/fast-reid/configs/Market1501/AGW_R101-ibn.yml +12 -0
  85. dnt/third_party/fast-reid/configs/Market1501/AGW_R50-ibn.yml +11 -0
  86. dnt/third_party/fast-reid/configs/Market1501/AGW_R50.yml +7 -0
  87. dnt/third_party/fast-reid/configs/Market1501/AGW_S50.yml +11 -0
  88. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R101-ibn.yml +12 -0
  89. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50-ibn.yml +11 -0
  90. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50.yml +7 -0
  91. dnt/third_party/fast-reid/configs/Market1501/bagtricks_S50.yml +11 -0
  92. dnt/third_party/fast-reid/configs/Market1501/bagtricks_vit.yml +88 -0
  93. dnt/third_party/fast-reid/configs/Market1501/mgn_R50-ibn.yml +11 -0
  94. dnt/third_party/fast-reid/configs/Market1501/sbs_R101-ibn.yml +12 -0
  95. dnt/third_party/fast-reid/configs/Market1501/sbs_R50-ibn.yml +11 -0
  96. dnt/third_party/fast-reid/configs/Market1501/sbs_R50.yml +7 -0
  97. dnt/third_party/fast-reid/configs/Market1501/sbs_S50.yml +11 -0
  98. dnt/third_party/fast-reid/configs/VERIWild/bagtricks_R50-ibn.yml +35 -0
  99. dnt/third_party/fast-reid/configs/VeRi/sbs_R50-ibn.yml +35 -0
  100. dnt/third_party/fast-reid/configs/VehicleID/bagtricks_R50-ibn.yml +36 -0
  101. dnt/third_party/fast-reid/configs/__init__.py +0 -0
  102. dnt/third_party/fast-reid/fast_reid_interfece.py +175 -0
  103. dnt/third_party/fast-reid/fastreid/__init__.py +6 -0
  104. dnt/third_party/fast-reid/fastreid/config/__init__.py +15 -0
  105. dnt/third_party/fast-reid/fastreid/config/config.py +319 -0
  106. dnt/third_party/fast-reid/fastreid/config/defaults.py +329 -0
  107. dnt/third_party/fast-reid/fastreid/data/__init__.py +17 -0
  108. dnt/third_party/fast-reid/fastreid/data/build.py +194 -0
  109. dnt/third_party/fast-reid/fastreid/data/common.py +58 -0
  110. dnt/third_party/fast-reid/fastreid/data/data_utils.py +202 -0
  111. dnt/third_party/fast-reid/fastreid/data/datasets/AirportALERT.py +50 -0
  112. dnt/third_party/fast-reid/fastreid/data/datasets/__init__.py +43 -0
  113. dnt/third_party/fast-reid/fastreid/data/datasets/bases.py +183 -0
  114. dnt/third_party/fast-reid/fastreid/data/datasets/caviara.py +44 -0
  115. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk03.py +274 -0
  116. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk_sysu.py +58 -0
  117. dnt/third_party/fast-reid/fastreid/data/datasets/dukemtmcreid.py +70 -0
  118. dnt/third_party/fast-reid/fastreid/data/datasets/grid.py +44 -0
  119. dnt/third_party/fast-reid/fastreid/data/datasets/iLIDS.py +45 -0
  120. dnt/third_party/fast-reid/fastreid/data/datasets/lpw.py +49 -0
  121. dnt/third_party/fast-reid/fastreid/data/datasets/market1501.py +89 -0
  122. dnt/third_party/fast-reid/fastreid/data/datasets/msmt17.py +114 -0
  123. dnt/third_party/fast-reid/fastreid/data/datasets/pes3d.py +44 -0
  124. dnt/third_party/fast-reid/fastreid/data/datasets/pku.py +44 -0
  125. dnt/third_party/fast-reid/fastreid/data/datasets/prai.py +43 -0
  126. dnt/third_party/fast-reid/fastreid/data/datasets/prid.py +41 -0
  127. dnt/third_party/fast-reid/fastreid/data/datasets/saivt.py +47 -0
  128. dnt/third_party/fast-reid/fastreid/data/datasets/sensereid.py +47 -0
  129. dnt/third_party/fast-reid/fastreid/data/datasets/shinpuhkan.py +48 -0
  130. dnt/third_party/fast-reid/fastreid/data/datasets/sysu_mm.py +47 -0
  131. dnt/third_party/fast-reid/fastreid/data/datasets/thermalworld.py +43 -0
  132. dnt/third_party/fast-reid/fastreid/data/datasets/vehicleid.py +126 -0
  133. dnt/third_party/fast-reid/fastreid/data/datasets/veri.py +69 -0
  134. dnt/third_party/fast-reid/fastreid/data/datasets/veriwild.py +140 -0
  135. dnt/third_party/fast-reid/fastreid/data/datasets/viper.py +45 -0
  136. dnt/third_party/fast-reid/fastreid/data/datasets/wildtracker.py +59 -0
  137. dnt/third_party/fast-reid/fastreid/data/samplers/__init__.py +18 -0
  138. dnt/third_party/fast-reid/fastreid/data/samplers/data_sampler.py +85 -0
  139. dnt/third_party/fast-reid/fastreid/data/samplers/imbalance_sampler.py +67 -0
  140. dnt/third_party/fast-reid/fastreid/data/samplers/triplet_sampler.py +260 -0
  141. dnt/third_party/fast-reid/fastreid/data/transforms/__init__.py +11 -0
  142. dnt/third_party/fast-reid/fastreid/data/transforms/autoaugment.py +806 -0
  143. dnt/third_party/fast-reid/fastreid/data/transforms/build.py +100 -0
  144. dnt/third_party/fast-reid/fastreid/data/transforms/functional.py +180 -0
  145. dnt/third_party/fast-reid/fastreid/data/transforms/transforms.py +161 -0
  146. dnt/third_party/fast-reid/fastreid/engine/__init__.py +15 -0
  147. dnt/third_party/fast-reid/fastreid/engine/defaults.py +490 -0
  148. dnt/third_party/fast-reid/fastreid/engine/hooks.py +534 -0
  149. dnt/third_party/fast-reid/fastreid/engine/launch.py +103 -0
  150. dnt/third_party/fast-reid/fastreid/engine/train_loop.py +357 -0
  151. dnt/third_party/fast-reid/fastreid/evaluation/__init__.py +6 -0
  152. dnt/third_party/fast-reid/fastreid/evaluation/clas_evaluator.py +81 -0
  153. dnt/third_party/fast-reid/fastreid/evaluation/evaluator.py +176 -0
  154. dnt/third_party/fast-reid/fastreid/evaluation/query_expansion.py +46 -0
  155. dnt/third_party/fast-reid/fastreid/evaluation/rank.py +200 -0
  156. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/__init__.py +20 -0
  157. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/setup.py +32 -0
  158. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/test_cython.py +106 -0
  159. dnt/third_party/fast-reid/fastreid/evaluation/reid_evaluation.py +143 -0
  160. dnt/third_party/fast-reid/fastreid/evaluation/rerank.py +73 -0
  161. dnt/third_party/fast-reid/fastreid/evaluation/roc.py +90 -0
  162. dnt/third_party/fast-reid/fastreid/evaluation/testing.py +88 -0
  163. dnt/third_party/fast-reid/fastreid/layers/__init__.py +19 -0
  164. dnt/third_party/fast-reid/fastreid/layers/activation.py +59 -0
  165. dnt/third_party/fast-reid/fastreid/layers/any_softmax.py +80 -0
  166. dnt/third_party/fast-reid/fastreid/layers/batch_norm.py +205 -0
  167. dnt/third_party/fast-reid/fastreid/layers/context_block.py +113 -0
  168. dnt/third_party/fast-reid/fastreid/layers/drop.py +161 -0
  169. dnt/third_party/fast-reid/fastreid/layers/frn.py +199 -0
  170. dnt/third_party/fast-reid/fastreid/layers/gather_layer.py +30 -0
  171. dnt/third_party/fast-reid/fastreid/layers/helpers.py +31 -0
  172. dnt/third_party/fast-reid/fastreid/layers/non_local.py +54 -0
  173. dnt/third_party/fast-reid/fastreid/layers/pooling.py +124 -0
  174. dnt/third_party/fast-reid/fastreid/layers/se_layer.py +25 -0
  175. dnt/third_party/fast-reid/fastreid/layers/splat.py +109 -0
  176. dnt/third_party/fast-reid/fastreid/layers/weight_init.py +122 -0
  177. dnt/third_party/fast-reid/fastreid/modeling/__init__.py +23 -0
  178. dnt/third_party/fast-reid/fastreid/modeling/backbones/__init__.py +18 -0
  179. dnt/third_party/fast-reid/fastreid/modeling/backbones/build.py +27 -0
  180. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenet.py +195 -0
  181. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenetv3.py +283 -0
  182. dnt/third_party/fast-reid/fastreid/modeling/backbones/osnet.py +525 -0
  183. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/__init__.py +4 -0
  184. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/config.py +396 -0
  185. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B0_dds_8gpu.yaml +27 -0
  186. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B1_dds_8gpu.yaml +27 -0
  187. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B2_dds_8gpu.yaml +27 -0
  188. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B3_dds_8gpu.yaml +27 -0
  189. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B4_dds_8gpu.yaml +27 -0
  190. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B5_dds_8gpu.yaml +27 -0
  191. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet.py +281 -0
  192. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnet.py +596 -0
  193. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-1.6GF_dds_8gpu.yaml +26 -0
  194. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-12GF_dds_8gpu.yaml +26 -0
  195. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-16GF_dds_8gpu.yaml +26 -0
  196. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-200MF_dds_8gpu.yaml +26 -0
  197. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-3.2GF_dds_8gpu.yaml +26 -0
  198. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-32GF_dds_8gpu.yaml +26 -0
  199. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-4.0GF_dds_8gpu.yaml +26 -0
  200. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-400MF_dds_8gpu.yaml +26 -0
  201. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-6.4GF_dds_8gpu.yaml +26 -0
  202. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-600MF_dds_8gpu.yaml +26 -0
  203. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-8.0GF_dds_8gpu.yaml +26 -0
  204. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-800MF_dds_8gpu.yaml +26 -0
  205. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-1.6GF_dds_8gpu.yaml +27 -0
  206. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-12GF_dds_8gpu.yaml +27 -0
  207. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-16GF_dds_8gpu.yaml +27 -0
  208. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-200MF_dds_8gpu.yaml +26 -0
  209. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-3.2GF_dds_8gpu.yaml +27 -0
  210. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-32GF_dds_8gpu.yaml +27 -0
  211. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-4.0GF_dds_8gpu.yaml +27 -0
  212. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-400MF_dds_8gpu.yaml +27 -0
  213. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-6.4GF_dds_8gpu.yaml +27 -0
  214. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-600MF_dds_8gpu.yaml +27 -0
  215. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-8.0GF_dds_8gpu.yaml +27 -0
  216. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-800MF_dds_8gpu.yaml +27 -0
  217. dnt/third_party/fast-reid/fastreid/modeling/backbones/repvgg.py +309 -0
  218. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnest.py +365 -0
  219. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnet.py +364 -0
  220. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnext.py +335 -0
  221. dnt/third_party/fast-reid/fastreid/modeling/backbones/shufflenet.py +203 -0
  222. dnt/third_party/fast-reid/fastreid/modeling/backbones/vision_transformer.py +399 -0
  223. dnt/third_party/fast-reid/fastreid/modeling/heads/__init__.py +11 -0
  224. dnt/third_party/fast-reid/fastreid/modeling/heads/build.py +25 -0
  225. dnt/third_party/fast-reid/fastreid/modeling/heads/clas_head.py +36 -0
  226. dnt/third_party/fast-reid/fastreid/modeling/heads/embedding_head.py +151 -0
  227. dnt/third_party/fast-reid/fastreid/modeling/losses/__init__.py +12 -0
  228. dnt/third_party/fast-reid/fastreid/modeling/losses/circle_loss.py +71 -0
  229. dnt/third_party/fast-reid/fastreid/modeling/losses/cross_entroy_loss.py +54 -0
  230. dnt/third_party/fast-reid/fastreid/modeling/losses/focal_loss.py +92 -0
  231. dnt/third_party/fast-reid/fastreid/modeling/losses/triplet_loss.py +113 -0
  232. dnt/third_party/fast-reid/fastreid/modeling/losses/utils.py +48 -0
  233. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/__init__.py +14 -0
  234. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/baseline.py +188 -0
  235. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/build.py +26 -0
  236. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/distiller.py +140 -0
  237. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/mgn.py +394 -0
  238. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/moco.py +126 -0
  239. dnt/third_party/fast-reid/fastreid/solver/__init__.py +8 -0
  240. dnt/third_party/fast-reid/fastreid/solver/build.py +348 -0
  241. dnt/third_party/fast-reid/fastreid/solver/lr_scheduler.py +66 -0
  242. dnt/third_party/fast-reid/fastreid/solver/optim/__init__.py +10 -0
  243. dnt/third_party/fast-reid/fastreid/solver/optim/lamb.py +123 -0
  244. dnt/third_party/fast-reid/fastreid/solver/optim/radam.py +149 -0
  245. dnt/third_party/fast-reid/fastreid/solver/optim/swa.py +246 -0
  246. dnt/third_party/fast-reid/fastreid/utils/__init__.py +6 -0
  247. dnt/third_party/fast-reid/fastreid/utils/checkpoint.py +503 -0
  248. dnt/third_party/fast-reid/fastreid/utils/collect_env.py +158 -0
  249. dnt/third_party/fast-reid/fastreid/utils/comm.py +255 -0
  250. dnt/third_party/fast-reid/fastreid/utils/compute_dist.py +200 -0
  251. dnt/third_party/fast-reid/fastreid/utils/env.py +119 -0
  252. dnt/third_party/fast-reid/fastreid/utils/events.py +461 -0
  253. dnt/third_party/fast-reid/fastreid/utils/faiss_utils.py +127 -0
  254. dnt/third_party/fast-reid/fastreid/utils/file_io.py +520 -0
  255. dnt/third_party/fast-reid/fastreid/utils/history_buffer.py +71 -0
  256. dnt/third_party/fast-reid/fastreid/utils/logger.py +211 -0
  257. dnt/third_party/fast-reid/fastreid/utils/params.py +103 -0
  258. dnt/third_party/fast-reid/fastreid/utils/precision_bn.py +94 -0
  259. dnt/third_party/fast-reid/fastreid/utils/registry.py +66 -0
  260. dnt/third_party/fast-reid/fastreid/utils/summary.py +120 -0
  261. dnt/third_party/fast-reid/fastreid/utils/timer.py +68 -0
  262. dnt/third_party/fast-reid/fastreid/utils/visualizer.py +278 -0
  263. dnt/track/__init__.py +2 -0
  264. dnt/track/botsort/__init__.py +4 -0
  265. dnt/track/botsort/bot_tracker/__init__.py +3 -0
  266. dnt/track/botsort/bot_tracker/basetrack.py +60 -0
  267. dnt/track/botsort/bot_tracker/bot_sort.py +473 -0
  268. dnt/track/botsort/bot_tracker/gmc.py +316 -0
  269. dnt/track/botsort/bot_tracker/kalman_filter.py +269 -0
  270. dnt/track/botsort/bot_tracker/matching.py +194 -0
  271. dnt/track/botsort/bot_tracker/mc_bot_sort.py +505 -0
  272. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/evaluation.py +14 -4
  273. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/io.py +19 -36
  274. dnt/track/botsort/bot_tracker/tracking_utils/timer.py +37 -0
  275. dnt/track/botsort/inference.py +96 -0
  276. dnt/track/config.py +120 -0
  277. dnt/track/dsort/configs/bagtricks_R50.yml +7 -0
  278. dnt/track/dsort/configs/deep_sort.yaml +0 -0
  279. dnt/track/dsort/configs/fastreid.yaml +1 -1
  280. dnt/track/dsort/deep_sort/deep/checkpoint/ckpt.t7 +0 -0
  281. dnt/track/dsort/deep_sort/deep/feature_extractor.py +87 -8
  282. dnt/track/dsort/deep_sort/deep_sort.py +31 -20
  283. dnt/track/dsort/deep_sort/sort/detection.py +2 -1
  284. dnt/track/dsort/deep_sort/sort/iou_matching.py +0 -2
  285. dnt/track/dsort/deep_sort/sort/linear_assignment.py +0 -3
  286. dnt/track/dsort/deep_sort/sort/nn_matching.py +5 -5
  287. dnt/track/dsort/deep_sort/sort/preprocessing.py +1 -2
  288. dnt/track/dsort/deep_sort/sort/track.py +2 -1
  289. dnt/track/dsort/deep_sort/sort/tracker.py +1 -1
  290. dnt/track/dsort/dsort.py +43 -33
  291. dnt/track/re_class.py +117 -0
  292. dnt/track/sort/sort.py +9 -6
  293. dnt/track/tracker.py +213 -32
  294. {dnt-0.2.4.dist-info → dnt-0.3.1.7.dist-info}/METADATA +41 -13
  295. dnt-0.3.1.7.dist-info/RECORD +315 -0
  296. {dnt-0.2.4.dist-info → dnt-0.3.1.7.dist-info}/WHEEL +1 -1
  297. dnt/analysis/yield.py +0 -9
  298. dnt/track/dsort/deep_sort/deep/evaluate.py +0 -15
  299. dnt/track/dsort/deep_sort/deep/original_model.py +0 -106
  300. dnt/track/dsort/deep_sort/deep/test.py +0 -77
  301. dnt/track/dsort/deep_sort/deep/train.py +0 -189
  302. dnt/track/dsort/utils/asserts.py +0 -13
  303. dnt/track/dsort/utils/draw.py +0 -36
  304. dnt/track/dsort/utils/json_logger.py +0 -383
  305. dnt/track/dsort/utils/log.py +0 -17
  306. dnt/track/dsort/utils/parser.py +0 -35
  307. dnt/track/dsort/utils/tools.py +0 -39
  308. dnt-0.2.4.dist-info/RECORD +0 -64
  309. /dnt/{track/dsort/utils → third_party/fast-reid/checkpoint}/__init__.py +0 -0
  310. {dnt-0.2.4.dist-info → dnt-0.3.1.7.dist-info/licenses}/LICENSE +0 -0
  311. {dnt-0.2.4.dist-info → dnt-0.3.1.7.dist-info}/top_level.txt +0 -0
dnt/label/labeler2.py ADDED
@@ -0,0 +1,605 @@
1
+ import os, sys
2
+ sys.path.append(os.path.dirname(__file__))
3
+ sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
4
+
5
+ import cv2
6
+ import numpy as np
7
+ import matplotlib.pyplot as plt
8
+ from tqdm import tqdm
9
+ import pandas as pd
10
+ import itertools
11
+ from shared.util import load_classes
12
+ import random
13
+ import subprocess
14
+
15
+ class Labeler:
16
+ def __init__(self,
17
+ method:str='opencv',
18
+ encoder:str='libx264',
19
+ preset:str='medium',
20
+ crf:int=23,
21
+ pix_fmt:str='bgr24',
22
+ compress_message:bool=False,
23
+ nodraw_empty:bool=True):
24
+ '''
25
+ Parameters:\n
26
+ - method: 'opencv' (default) - use opencv to draw labels),
27
+ 'ffmpeg' - use ffmpeg to draw labels
28
+ - encoder: 'libx264' (default) - use libx264 encoder for ffmpeg,
29
+ 'libx265' - use libx265 encoder for ffmpeg
30
+ 'h264_nvenc' - use h264_nvenc encoder for ffmpeg
31
+ 'hevc_nvenc' - use hevc_nvenc encoder for ffmpeg
32
+ - preset: 'medium' (default) - use medium preset for ffmpeg
33
+ 'slow' - use slow preset for ffmpeg
34
+ 'fast' - use fast preset for ffmpeg
35
+ - crf: 23 (default) - use 23 crf for ffmpeg, lower is better quality
36
+ - compress_message: False (default) - show compress message in progress bar
37
+ - nodraw_empty: True (default) - not draw empty frames
38
+ '''
39
+ self.method = method
40
+ self.encoder = encoder
41
+ self.preset = preset
42
+ self.crf = crf
43
+ self.pix_fmt = pix_fmt
44
+ self.compress_message=compress_message
45
+ self.nodraw_empty = nodraw_empty
46
+
47
+ def draw(self,
48
+ input_video:str,
49
+ output_video:str,
50
+ draws:pd.DataFrame=None,
51
+ draw_file:str=None,
52
+ start_frame:int=None,
53
+ end_frame:int=None,
54
+ video_index:int=None,
55
+ video_tot:int=None,
56
+ verbose:bool=True):
57
+ '''
58
+ General labeling function\n
59
+ Inputs:\n
60
+ draws: a DataFrame contains labeling information, if None, read label_file
61
+ label_file: a txt file with a header ['frame','type','coords','color','size','thick','desc']
62
+ input_video: raw video
63
+ output_video: labeled video
64
+ start_frame: starting frame
65
+ end_frame: ending frame
66
+ video_index: display video index in batch processing
67
+ video_tot: display total video number in batch processing
68
+ '''
69
+ if draws is not None:
70
+ data = draws
71
+ else:
72
+ data = pd.read_csv(draw_file,
73
+ dtype={'frame':int,
74
+ 'type':str,
75
+ 'size':float,
76
+ 'desc':str,
77
+ 'thick':int},
78
+ converters={'coords': lambda x:list(eval(x)), 'color': lambda x:eval(x)})
79
+
80
+ cmap = plt.get_cmap('tab20b')
81
+ colors = [cmap(i)[:3] for i in np.linspace(0, 1, 20)]
82
+
83
+ cap = cv2.VideoCapture(input_video)
84
+ if not cap.isOpened():
85
+ raise IOError("Couldn't open webcam or video")
86
+
87
+ if start_frame is None:
88
+ start_frame = 0
89
+ if end_frame is None:
90
+ end_frame = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1
91
+
92
+ tot_frames = end_frame - start_frame + 1
93
+ fps = int(cap.get(cv2.CAP_PROP_FPS))
94
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
95
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
96
+
97
+ if self.method == 'ffmpeg':
98
+ # FFmpeg command to write H.265 encoded video
99
+ ffmpeg_cmd = [
100
+ "ffmpeg",
101
+ "-y", # Overwrite output file if it exists
102
+ "-f", "rawvideo",
103
+ "-vcodec", "rawvideo",
104
+ "-pix_fmt", self.pix_fmt,
105
+ "-s", f"{width}x{height}",
106
+ "-r", str(fps),
107
+ "-i", "-", # Read input from stdin
108
+ "-c:v", self.encoder, # H.265 codec
109
+ "-preset", self.preset, # Adjust preset as needed (ultrafast, fast, medium, slow, etc.)
110
+ "-crf", str(self.crf), # Constant Rate Factor (higher = more compression, lower = better quality)
111
+ output_video]
112
+
113
+ # Start FFmpeg process
114
+ process = subprocess.Popen(ffmpeg_cmd,
115
+ stdin=subprocess.PIPE,
116
+ stdout=subprocess.DEVNULL,
117
+ stderr=subprocess.DEVNULL)
118
+ else:
119
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
120
+ writer = cv2.VideoWriter(output_video, fourcc, fps, (width, height))
121
+
122
+ if verbose:
123
+ pbar = tqdm(total=tot_frames, unit=" frames")
124
+ if self.compress_message:
125
+ pbar.set_description_str("Labeling")
126
+ else:
127
+ if video_index and video_tot:
128
+ pbar.set_description_str("Labeling {} of {}".format(video_index, video_tot))
129
+ else:
130
+ pbar.set_description_str("Labeling {} ".format(input_video))
131
+
132
+ cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
133
+ while cap.isOpened():
134
+ pos_frame = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
135
+ ret, frame = cap.read()
136
+ if (not ret) or (pos_frame>end_frame):
137
+ break
138
+
139
+ elements = data.loc[data['frame']==pos_frame]
140
+
141
+ for index, element in elements.iterrows():
142
+ if element['type'] == 'txt':
143
+ label_txt = element['desc']
144
+ color = element['color']
145
+ size = element['size']
146
+ thick = element['thick']
147
+ cv2.putText(frame, label_txt, tuple(map(int, element['coords'][0])), 0, size, color, thick)
148
+
149
+ elif element['type'] == 'line':
150
+ coords = element['coords']
151
+ color = element['color']
152
+ thick = element['thick']
153
+ cv2.line(frame, tuple(map(int, coords[0])), tuple(map(int, coords[1])), color, thick)
154
+
155
+ elif element['type'] == 'box':
156
+ coords = element['coords']
157
+ color = element['color']
158
+ thick = element['thick']
159
+ cv2.rectangle(frame, tuple(map(int, coords[0])), tuple(map(int, coords[1])), color, thick)
160
+
161
+ elif element['type'] == 'bbox':
162
+ coords = element['coords']
163
+ color = element['color']
164
+ thick = element['thick']
165
+ label_txt = element['desc']
166
+ size = element['size']
167
+
168
+ cv2.rectangle(frame, tuple(map(int, coords[0])), tuple(map(int, coords[1])), color, thick)
169
+ cv2.putText(frame, str(label_txt), (int(coords[0][0]), int(coords[0][1]-int(10*size))),
170
+ cv2.FONT_HERSHEY_SIMPLEX, size, color, thick)
171
+
172
+ elif element['type'] == 'circle':
173
+ coords = element['coords']
174
+ color = element['color']
175
+ thick = element['thick']
176
+ label_txt = element['desc']
177
+ radius = int(element['size'])
178
+
179
+ cv2.circle(frame, tuple(map(int, coords[0])), radius=radius, color=color, thickness=thick)
180
+
181
+ elif element['type'] == 'polygon':
182
+ coords = element['coords']
183
+ color = element['color']
184
+ thick = element['thick']
185
+ cv2.polylines(frame, [np.array(coords)], isClosed=True, color=color, thickness=thick)
186
+
187
+ elif element['type'] == 'polylines':
188
+ coords = element['coords']
189
+ color = element['color']
190
+ thick = element['thick']
191
+ cv2.polylines(frame, [np.array(coords)], isClosed=False, color=color, thickness=thick)
192
+
193
+ if self.method == 'ffmpeg':
194
+ process.stdin.write(frame.tobytes())
195
+ else:
196
+ writer.write(frame)
197
+
198
+ if verbose:
199
+ pbar.update()
200
+
201
+ if verbose:
202
+ pbar.close()
203
+ #cv2.destroyAllWindows()
204
+ cap.release()
205
+ if self.method == 'ffmpeg':
206
+ process.stdin.close()
207
+ process.wait()
208
+ else:
209
+ writer.release()
210
+
211
+ def draw_track_clips(self,
212
+ input_video:str,
213
+ output_path:str,
214
+ tracks:pd.DataFrame=None,
215
+ track_file:str = None,
216
+ method:str='all',
217
+ random_number:int=10,
218
+ track_ids:list=None,
219
+ start_frame_offset:int=0,
220
+ end_frame_offset:int=0,
221
+ tail:int=0,
222
+ prefix:bool=False,
223
+ size:int=1,
224
+ thick:int=1,
225
+ video_index:int=None,
226
+ video_tot:int=None,
227
+ verbose:bool=True):
228
+ '''
229
+ Parameters:\n
230
+ input_video: the raw video file
231
+ outputh_path: the folder for outputing track clips
232
+ tracks: the dataframe of tracks
233
+ track_file: the track file if tracks are none
234
+ method: 'all' (default) - all tracks, 'random' - random select tracks, 'specify' - specify track ids
235
+ random_number: the number of track ids if method == 'random'
236
+ track_ids: the list of track ids if method == 'specify'
237
+ start_frame_offset: the offset of start frame, default is 0
238
+ end_frame_offset: the offset of end frame, default is 0
239
+ tail: the length of tail, default is 0
240
+ prefix: if add the video file name as the prefix in output file names, default is False
241
+ size: font size, default is 1
242
+ thick: line thinckness, defualt is 1
243
+ verbose: if show progressing bar, default is True
244
+ '''
245
+
246
+ if tracks is None:
247
+ tracks = pd.read_csv(track_file, header=None, dtype={0:int, 1:int, 2:int, 3:int, 4:int, 5:int, 6:float, 7:int, 8:int, 9:int})
248
+ tracks.columns = ['frame', 'track', 'x', 'y', 'w', 'h', 'score', 'cls', 'r3', 'r4']
249
+
250
+ if method == 'random':
251
+ track_ids = tracks['track'].unique().tolist()
252
+ if random_number<=0:
253
+ random_number = 10
254
+ track_ids = random.sample(track_ids, random_number)
255
+ elif method == 'specify':
256
+ if (track_ids is None) or (len(track_ids)==0):
257
+ print('No tracks are provided!')
258
+ return pd.DataFrame()
259
+ else:
260
+ track_ids = tracks['track'].unique().tolist()
261
+
262
+ #pbar = tqdm(total=len(track_ids), desc='Labeling tracks ', unit='clips')
263
+ for id in track_ids:
264
+ selected_tracks = tracks[tracks['track']==id].copy()
265
+ start_frame = max(selected_tracks['frame'].min() - start_frame_offset, 0)
266
+ end_frame = min(selected_tracks['frame'].max() + end_frame_offset,
267
+ cv2.VideoCapture(input_video).get(cv2.CAP_PROP_FRAME_COUNT)-1)
268
+ if prefix:
269
+ out_video = os.path.join(output_path, os.path.splitext(os.path.basename(input_video))[0]+"_"+str(id)+'.mp4')
270
+ else:
271
+ out_video = os.path.join(output_path, str(id)+'.mp4')
272
+
273
+ self.draw_tracks(input_video=input_video,
274
+ output_video=out_video,
275
+ tracks=selected_tracks,
276
+ start_frame=start_frame,
277
+ end_frame=end_frame,
278
+ verbose=verbose,
279
+ tail=tail,
280
+ thick=thick,
281
+ size=size,
282
+ video_index=video_index,
283
+ video_tot=video_tot)
284
+
285
+ #pbar.update()
286
+ #pbar.close()
287
+
288
+ def draw_tracks(self,
289
+ input_video:str,
290
+ output_video:str,
291
+ tracks:pd.DataFrame=None,
292
+ track_file:str=None,
293
+ label_file:str=None,
294
+ color=None,
295
+ tail:int=0,
296
+ thick:int=2,
297
+ size:int=1,
298
+ class_name=False,
299
+ start_frame:int=None,
300
+ end_frame:int=None,
301
+ video_index:int=None,
302
+ video_tot:int=None,
303
+ verbose:bool=True):
304
+
305
+ if tracks is None:
306
+ tracks = pd.read_csv(track_file,
307
+ header=None,
308
+ dtype={0:int, 1:int, 2:int, 3:int, 4:int, 5:int, 6:float, 7:int, 8:int, 9:int})
309
+ tracks.columns = ['frame', 'track', 'x', 'y', 'w', 'h', 'score', 'cls', 'r3', 'r4']
310
+
311
+ cmap = plt.get_cmap('tab20b')
312
+ colors = [cmap(i)[:3] for i in np.linspace(0, 1, 20)]
313
+
314
+ cap = cv2.VideoCapture(input_video)
315
+ if not cap.isOpened():
316
+ raise IOError("Couldn't open webcam or video")
317
+
318
+ if start_frame is None:
319
+ start_frame = 0
320
+ if end_frame is None:
321
+ end_frame = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1
322
+
323
+ selected_tracks = tracks.loc[(tracks['frame']>=start_frame) & (tracks['frame']<=end_frame)].copy()
324
+
325
+ pbar_desc = ""
326
+ if self.compress_message:
327
+ pbar_desc = "Generating labels"
328
+ else:
329
+ if video_index and video_tot:
330
+ pbar_desc = "Generating labels {} of {}".format(video_index, video_tot)
331
+ else:
332
+ pbar_desc = "Generating labels {} ".format(input_video)
333
+
334
+ pbar = tqdm(total=len(selected_tracks), unit=" frames", desc=pbar_desc)
335
+ results = []
336
+ for _, track in selected_tracks.iterrows():
337
+
338
+ if color is None:
339
+ final_color = colors[int(track['track']) % len(colors)]
340
+ final_color = [i * 255 for i in final_color]
341
+ else:
342
+ final_color = color
343
+
344
+ if class_name == True:
345
+ label_str = str(int(track['track'])) + ' ' + str(int(track['cls']))
346
+ else:
347
+ label_str = str(int(track['track']))
348
+ results.append([track['frame'], 'bbox', [(track['x'], track['y']), (track['x'] + track['w'], track['y'] + track['h'])],
349
+ final_color, size, thick, label_str])
350
+ if tail>0:
351
+ frames = [*range(int(track['frame'])-tail, int(track['frame']))]
352
+ pre_boxes = tracks.loc[(tracks['frame'].isin(frames)) & (tracks['track']==track['track'])].values.tolist()
353
+
354
+ if len(pre_boxes)>0:
355
+ for pre_box in pre_boxes:
356
+ xc = int(pre_box[2]) + int(pre_box[4]/2)
357
+ yc = int(pre_box[3]) + int(pre_box[5]/2)
358
+ results.append([track['frame'], 'circle', [(xc, yc)],
359
+ final_color, 0, -1, ''])
360
+
361
+ if verbose:
362
+ pbar.update()
363
+
364
+ if verbose:
365
+ pbar.close()
366
+
367
+ results.sort()
368
+ results = list(results for results,_ in itertools.groupby(results))
369
+ df = pd.DataFrame(results, columns=['frame','type','coords','color','size','thick','desc'])
370
+ df.sort_values(by='frame', inplace=True)
371
+
372
+ if output_video:
373
+ self.draw(input_video = input_video, output_video = output_video,
374
+ draws = df, start_frame = start_frame, end_frame = end_frame,
375
+ video_index = video_index, video_tot = video_tot, verbose=verbose)
376
+
377
+ if label_file:
378
+ df.to_csv(label_file, index=False)
379
+
380
+ return df
381
+
382
+ def draw_dets(self, input_video:str, output_video:str,
383
+ dets:pd.DataFrame = None, det_file:str = None, label_file:str=None,
384
+ color = None, class_name = False,
385
+ start_frame:int=None, end_frame:int=None,
386
+ video_index:int=None, video_tot:int=None):
387
+
388
+ if dets is None:
389
+ dets = pd.read_csv(det_file, header=None)
390
+
391
+ names = load_classes()
392
+
393
+ cmap = plt.get_cmap('tab20b')
394
+ colors = [cmap(i)[:3] for i in np.linspace(0, 1, 20)]
395
+
396
+ cap = cv2.VideoCapture(input_video)
397
+ if not cap.isOpened():
398
+ raise IOError("Couldn't open webcam or video")
399
+
400
+ if start_frame is None:
401
+ start_frame = 0
402
+ if end_frame is None:
403
+ end_frame = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1
404
+
405
+ tot_frames = end_frame - start_frame + 1
406
+ selected_dets = dets.loc[(dets[0]>=start_frame) & (dets[0]<=end_frame)].copy()
407
+
408
+ pbar = tqdm(total=len(selected_dets), unit=" dets")
409
+ if self.compress_message:
410
+ pbar.set_description_str("Generating labels")
411
+ else:
412
+ if video_index and video_tot:
413
+ pbar.set_description_str("Generating labels {} of {}".format(video_index, video_tot))
414
+ else:
415
+ pbar.set_description_str("Generating labels {} ".format(input_video))
416
+
417
+ results = []
418
+ for index, det in selected_dets.iterrows():
419
+
420
+ if color is None:
421
+ final_color = colors[int(det[7]) % len(colors)]
422
+ final_color = [i * 255 for i in final_color]
423
+ else:
424
+ final_color = color
425
+
426
+ if class_name == True:
427
+ desc = names[int(det[7])]
428
+ else:
429
+ desc = str(int(det[7]))
430
+
431
+ results.append([det[0], 'bbox', [(det[2], det[3]), (det[2]+det[4], det[3]+det[5])],
432
+ final_color, 0.8, 1, desc])
433
+ pbar.update()
434
+
435
+ results.sort()
436
+ results = list(results for results,_ in itertools.groupby(results))
437
+ df = pd.DataFrame(results, columns=['frame','type','coords','color','size','thick','desc'])
438
+ df.sort_values(by='frame', inplace=True)
439
+
440
+ if output_video:
441
+ self.draw(input_video = input_video, output_video = output_video,
442
+ draws = df, start_frame = start_frame, end_frame = end_frame,
443
+ video_index = video_index, video_tot = video_tot)
444
+
445
+ if label_file:
446
+ df.to_csv(label_file, index=False)
447
+
448
+ return df
449
+
450
+ def clip(self, input_video:str, output_video:str, start_frame:int=None, end_frame:int=None):
451
+ cap = cv2.VideoCapture(input_video)
452
+ if not cap.isOpened():
453
+ raise IOError("Couldn't open webcam or video")
454
+
455
+ if start_frame is None:
456
+ start_frame = 0
457
+ if end_frame is None:
458
+ end_frame = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1
459
+
460
+ tot_frames = end_frame - start_frame + 1
461
+ fps = int(cap.get(cv2.CAP_PROP_FPS))
462
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
463
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
464
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
465
+ writer = cv2.VideoWriter(output_video, fourcc, fps, (width, height))
466
+
467
+ pbar = tqdm(total=tot_frames, unit=" frames")
468
+ if self.compress_message:
469
+ pbar.set_description_str("Cutting")
470
+ else:
471
+ pbar.set_description_str("Cutting {} ".format(input_video))
472
+
473
+ cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
474
+ while cap.isOpened():
475
+ pos_frame = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
476
+ ret, frame = cap.read()
477
+ if (not ret) or (pos_frame>end_frame):
478
+ break
479
+
480
+ writer.write(frame)
481
+ key = cv2.waitKey(1) & 0xFF
482
+ if key == ord("q"):
483
+ break
484
+
485
+ pbar.update()
486
+
487
+ cv2.destroyAllWindows()
488
+ cap.release()
489
+ writer.release()
490
+
491
+ @staticmethod
492
+ def export_frames(input_video:str, frames:list[int], output_path:str, prefix:str=None):
493
+
494
+ cap = cv2.VideoCapture(input_video)
495
+ if not cap.isOpened():
496
+ raise IOError("Couldn't open webcam or video")
497
+
498
+ pbar = tqdm(total=len(frames), unit=" frames")
499
+ pbar.set_description_str("Extracting frame")
500
+
501
+ for frame in frames:
502
+ cap.set(cv2.CAP_PROP_POS_FRAMES, frame)
503
+ ret, frame_read = cap.read()
504
+
505
+ if prefix is None:
506
+ frame_file = os.path.join(output_path, str(frame)+'.jpg')
507
+ else:
508
+ frame_file = os.path.join(output_path, prefix+'-'+str(frame)+'.jpg')
509
+
510
+ if ret:
511
+ cv2.imwrite(frame_file, frame_read)
512
+ else:
513
+ break
514
+
515
+ pbar.update()
516
+
517
+ pbar.close()
518
+ cap.release()
519
+
520
+ print("Writing frames to {}".format(output_path))
521
+
522
+ @staticmethod
523
+ def export_track_frames(input_video:str, tracks:pd.DataFrame, output_path:str, bbox = True, prefix:str=None, thick:int=2):
524
+
525
+ if (tracks is None) or (len(tracks.columns)<10):
526
+ raise Exception("Invalid tracks!")
527
+ tracks.columns = ['frame', 'track', 'x', 'y', 'w', 'h', 'score', 'cls', 'r3', 'r4']
528
+ ids = tracks['track'].unique()
529
+
530
+ cap = cv2.VideoCapture(input_video)
531
+ if not cap.isOpened():
532
+ raise IOError("Couldn't open webcam or video")
533
+
534
+ cmap = plt.get_cmap('tab20b')
535
+ colors = [cmap(i)[:3] for i in np.linspace(0, 1, 20)]
536
+
537
+ pbar = tqdm(total=len(ids), unit=' frame')
538
+ for id in ids:
539
+ pbar.desc = "Extracting track: "+str(id)
540
+ selected = tracks[tracks['track']==id]
541
+ if len(selected) > 0:
542
+ for index, track in selected.iterrows():
543
+ frame = track['frame']
544
+ cap.set(cv2.CAP_PROP_POS_FRAMES, frame)
545
+ ret, img = cap.read()
546
+
547
+ if ret:
548
+ if bbox == True:
549
+ x1 = track['x']
550
+ y1 = track['y']
551
+ x2 = track['x'] + track['w']
552
+ y2 = track['y'] + track['h']
553
+ final_color = colors[int(id) % len(colors)]
554
+ final_color = [i * 255 for i in final_color]
555
+ cv2.rectangle(img, (int(x1), int(y1) ), (int(x2), int(y2)), final_color, thick)
556
+
557
+ if prefix is None:
558
+ frame_file = os.path.join(output_path, str(id)+'_'+str(frame)+'.jpg')
559
+ else:
560
+ frame_file = os.path.join(output_path, prefix+'-'+str(id)+'_'+str(frame)+'.jpg')
561
+
562
+ cv2.imwrite(frame_file, img)
563
+ else:
564
+ break
565
+
566
+ pbar.update()
567
+
568
+ pbar.close()
569
+ cap.release()
570
+
571
+ print("Writing frames to {}".format(output_path))
572
+
573
+ @staticmethod
574
+ def time2frame(input_video:str, time:float):
575
+ cap = cv2.VideoCapture(input_video)
576
+ if not cap.isOpened():
577
+ raise IOError("Couldn't open webcam or video")
578
+
579
+ video_fps = int(cap.get(cv2.CAP_PROP_FPS)) #original fps
580
+ frame = int(video_fps * time)
581
+ return frame
582
+
583
+ class LabelGenerator():
584
+ def __init__(self) -> None:
585
+ self.draws = []
586
+
587
+
588
+ if __name__=='__main__':
589
+
590
+ video_file = "/mnt/d/videos/sample/traffic.mp4"
591
+ iou_file = "/mnt/d/videos/sample/dets/traffic_iou.txt"
592
+ track_file = "/mnt/d/videos/sample/tracks/traffic_track.txt"
593
+ label_video = "/mnt/d/videos/sample/labels/traffic_track-ffmpeg.mp4"
594
+ label_file = "/mnt/d/videos/sample/labels/traffic_track.txt"
595
+
596
+ labeler = Labeler(method='ffmpeg',
597
+ encoder='hevc_nvenc',
598
+ preset='medium',
599
+ crf=23,
600
+ compress_message=True)
601
+ labeler.draw_tracks(input_video=video_file,
602
+ output_video=label_video,
603
+ track_file=track_file)
604
+
605
+
dnt/shared/__init__.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import os
2
2
  import sys
3
3
 
4
- sys.path.append(os.path.dirname(__file__))
4
+ sys.path.append(os.path.dirname(__file__))
5
+ from .synhcro import Synchronizer
File without changes
File without changes
dnt/shared/data/voc.names CHANGED
File without changes
dnt/shared/download.py ADDED
@@ -0,0 +1,12 @@
1
+ import requests
2
+
3
+ def download_file(url, destination, verbose=True):
4
+ response = requests.get(url, stream=True)
5
+ response.raise_for_status() # Check if the request was successful
6
+
7
+ with open(destination, 'wb') as file:
8
+ for chunk in response.iter_content(chunk_size=8192):
9
+ file.write(chunk)
10
+
11
+ if verbose:
12
+ print(f"Downloaded {url} to {destination}")