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
@@ -0,0 +1,255 @@
1
+ """
2
+ This file contains primitives for multi-gpu communication.
3
+ This is useful when doing distributed training.
4
+ """
5
+
6
+ import functools
7
+ import logging
8
+ import numpy as np
9
+ import pickle
10
+ import torch
11
+ import torch.distributed as dist
12
+
13
+ _LOCAL_PROCESS_GROUP = None
14
+ """
15
+ A torch process group which only includes processes that on the same machine as the current process.
16
+ This variable is set when processes are spawned by `launch()` in "engine/launch.py".
17
+ """
18
+
19
+
20
+ def get_world_size() -> int:
21
+ if not dist.is_available():
22
+ return 1
23
+ if not dist.is_initialized():
24
+ return 1
25
+ return dist.get_world_size()
26
+
27
+
28
+ def get_rank() -> int:
29
+ if not dist.is_available():
30
+ return 0
31
+ if not dist.is_initialized():
32
+ return 0
33
+ return dist.get_rank()
34
+
35
+
36
+ def get_local_rank() -> int:
37
+ """
38
+ Returns:
39
+ The rank of the current process within the local (per-machine) process group.
40
+ """
41
+ if not dist.is_available():
42
+ return 0
43
+ if not dist.is_initialized():
44
+ return 0
45
+ assert _LOCAL_PROCESS_GROUP is not None
46
+ return dist.get_rank(group=_LOCAL_PROCESS_GROUP)
47
+
48
+
49
+ def get_local_size() -> int:
50
+ """
51
+ Returns:
52
+ The size of the per-machine process group,
53
+ i.e. the number of processes per machine.
54
+ """
55
+ if not dist.is_available():
56
+ return 1
57
+ if not dist.is_initialized():
58
+ return 1
59
+ return dist.get_world_size(group=_LOCAL_PROCESS_GROUP)
60
+
61
+
62
+ def is_main_process() -> bool:
63
+ return get_rank() == 0
64
+
65
+
66
+ def synchronize():
67
+ """
68
+ Helper function to synchronize (barrier) among all processes when
69
+ using distributed training
70
+ """
71
+ if not dist.is_available():
72
+ return
73
+ if not dist.is_initialized():
74
+ return
75
+ world_size = dist.get_world_size()
76
+ if world_size == 1:
77
+ return
78
+ dist.barrier()
79
+
80
+
81
+ @functools.lru_cache()
82
+ def _get_global_gloo_group():
83
+ """
84
+ Return a process group based on gloo backend, containing all the ranks
85
+ The result is cached.
86
+ """
87
+ if dist.get_backend() == "nccl":
88
+ return dist.new_group(backend="gloo")
89
+ else:
90
+ return dist.group.WORLD
91
+
92
+
93
+ def _serialize_to_tensor(data, group):
94
+ backend = dist.get_backend(group)
95
+ assert backend in ["gloo", "nccl"]
96
+ device = torch.device("cpu" if backend == "gloo" else "cuda")
97
+
98
+ buffer = pickle.dumps(data)
99
+ if len(buffer) > 1024 ** 3:
100
+ logger = logging.getLogger(__name__)
101
+ logger.warning(
102
+ "Rank {} trying to all-gather {:.2f} GB of data on device {}".format(
103
+ get_rank(), len(buffer) / (1024 ** 3), device
104
+ )
105
+ )
106
+ storage = torch.ByteStorage.from_buffer(buffer)
107
+ tensor = torch.ByteTensor(storage).to(device=device)
108
+ return tensor
109
+
110
+
111
+ def _pad_to_largest_tensor(tensor, group):
112
+ """
113
+ Returns:
114
+ list[int]: size of the tensor, on each rank
115
+ Tensor: padded tensor that has the max size
116
+ """
117
+ world_size = dist.get_world_size(group=group)
118
+ assert (
119
+ world_size >= 1
120
+ ), "comm.gather/all_gather must be called from ranks within the given group!"
121
+ local_size = torch.tensor([tensor.numel()], dtype=torch.int64, device=tensor.device)
122
+ size_list = [
123
+ torch.zeros([1], dtype=torch.int64, device=tensor.device) for _ in range(world_size)
124
+ ]
125
+ dist.all_gather(size_list, local_size, group=group)
126
+ size_list = [int(size.item()) for size in size_list]
127
+
128
+ max_size = max(size_list)
129
+
130
+ # we pad the tensor because torch all_gather does not support
131
+ # gathering tensors of different shapes
132
+ if local_size != max_size:
133
+ padding = torch.zeros((max_size - local_size,), dtype=torch.uint8, device=tensor.device)
134
+ tensor = torch.cat((tensor, padding), dim=0)
135
+ return size_list, tensor
136
+
137
+
138
+ def all_gather(data, group=None):
139
+ """
140
+ Run all_gather on arbitrary picklable data (not necessarily tensors).
141
+ Args:
142
+ data: any picklable object
143
+ group: a torch process group. By default, will use a group which
144
+ contains all ranks on gloo backend.
145
+ Returns:
146
+ list[data]: list of data gathered from each rank
147
+ """
148
+ if get_world_size() == 1:
149
+ return [data]
150
+ if group is None:
151
+ group = _get_global_gloo_group()
152
+ if dist.get_world_size(group) == 1:
153
+ return [data]
154
+
155
+ tensor = _serialize_to_tensor(data, group)
156
+
157
+ size_list, tensor = _pad_to_largest_tensor(tensor, group)
158
+ max_size = max(size_list)
159
+
160
+ # receiving Tensor from all ranks
161
+ tensor_list = [
162
+ torch.empty((max_size,), dtype=torch.uint8, device=tensor.device) for _ in size_list
163
+ ]
164
+ dist.all_gather(tensor_list, tensor, group=group)
165
+
166
+ data_list = []
167
+ for size, tensor in zip(size_list, tensor_list):
168
+ buffer = tensor.cpu().numpy().tobytes()[:size]
169
+ data_list.append(pickle.loads(buffer))
170
+
171
+ return data_list
172
+
173
+
174
+ def gather(data, dst=0, group=None):
175
+ """
176
+ Run gather on arbitrary picklable data (not necessarily tensors).
177
+ Args:
178
+ data: any picklable object
179
+ dst (int): destination rank
180
+ group: a torch process group. By default, will use a group which
181
+ contains all ranks on gloo backend.
182
+ Returns:
183
+ list[data]: on dst, a list of data gathered from each rank. Otherwise,
184
+ an empty list.
185
+ """
186
+ if get_world_size() == 1:
187
+ return [data]
188
+ if group is None:
189
+ group = _get_global_gloo_group()
190
+ if dist.get_world_size(group=group) == 1:
191
+ return [data]
192
+ rank = dist.get_rank(group=group)
193
+
194
+ tensor = _serialize_to_tensor(data, group)
195
+ size_list, tensor = _pad_to_largest_tensor(tensor, group)
196
+
197
+ # receiving Tensor from all ranks
198
+ if rank == dst:
199
+ max_size = max(size_list)
200
+ tensor_list = [
201
+ torch.empty((max_size,), dtype=torch.uint8, device=tensor.device) for _ in size_list
202
+ ]
203
+ dist.gather(tensor, tensor_list, dst=dst, group=group)
204
+
205
+ data_list = []
206
+ for size, tensor in zip(size_list, tensor_list):
207
+ buffer = tensor.cpu().numpy().tobytes()[:size]
208
+ data_list.append(pickle.loads(buffer))
209
+ return data_list
210
+ else:
211
+ dist.gather(tensor, [], dst=dst, group=group)
212
+ return []
213
+
214
+
215
+ def shared_random_seed():
216
+ """
217
+ Returns:
218
+ int: a random number that is the same across all workers.
219
+ If workers need a shared RNG, they can use this shared seed to
220
+ create one.
221
+ All workers must call this function, otherwise it will deadlock.
222
+ """
223
+ ints = np.random.randint(2 ** 31)
224
+ all_ints = all_gather(ints)
225
+ return all_ints[0]
226
+
227
+
228
+ def reduce_dict(input_dict, average=True):
229
+ """
230
+ Reduce the values in the dictionary from all processes so that process with rank
231
+ 0 has the reduced results.
232
+ Args:
233
+ input_dict (dict): inputs to be reduced. All the values must be scalar CUDA Tensor.
234
+ average (bool): whether to do average or sum
235
+ Returns:
236
+ a dict with the same keys as input_dict, after reduction.
237
+ """
238
+ world_size = get_world_size()
239
+ if world_size < 2:
240
+ return input_dict
241
+ with torch.no_grad():
242
+ names = []
243
+ values = []
244
+ # sort the keys so that they are consistent across processes
245
+ for k in sorted(input_dict.keys()):
246
+ names.append(k)
247
+ values.append(input_dict[k])
248
+ values = torch.stack(values, dim=0)
249
+ dist.reduce(values, dst=0)
250
+ if dist.get_rank() == 0 and average:
251
+ # only main process gets accumulated, so only divide by
252
+ # world_size in this case
253
+ values /= world_size
254
+ reduced_dict = {k: v for k, v in zip(names, values)}
255
+ return reduced_dict
@@ -0,0 +1,200 @@
1
+ # encoding: utf-8
2
+ """
3
+ @author: xingyu liao
4
+ @contact: sherlockliao01@gmail.com
5
+ """
6
+
7
+ # Modified from: https://github.com/open-mmlab/OpenUnReID/blob/66bb2ae0b00575b80fbe8915f4d4f4739cc21206/openunreid/core/utils/compute_dist.py
8
+
9
+
10
+ import faiss
11
+ import numpy as np
12
+ import torch
13
+ import torch.nn.functional as F
14
+
15
+ from .faiss_utils import (
16
+ index_init_cpu,
17
+ index_init_gpu,
18
+ search_index_pytorch,
19
+ search_raw_array_pytorch,
20
+ )
21
+
22
+ __all__ = [
23
+ "build_dist",
24
+ "compute_jaccard_distance",
25
+ "compute_euclidean_distance",
26
+ "compute_cosine_distance",
27
+ ]
28
+
29
+
30
+ @torch.no_grad()
31
+ def build_dist(feat_1: torch.Tensor, feat_2: torch.Tensor, metric: str = "euclidean", **kwargs) -> np.ndarray:
32
+ r"""Compute distance between two feature embeddings.
33
+
34
+ Args:
35
+ feat_1 (torch.Tensor): 2-D feature with batch dimension.
36
+ feat_2 (torch.Tensor): 2-D feature with batch dimension.
37
+ metric:
38
+
39
+ Returns:
40
+ numpy.ndarray: distance matrix.
41
+ """
42
+ assert metric in ["cosine", "euclidean", "jaccard"], "Expected metrics are cosine, euclidean and jaccard, " \
43
+ "but got {}".format(metric)
44
+
45
+ if metric == "euclidean":
46
+ return compute_euclidean_distance(feat_1, feat_2)
47
+
48
+ elif metric == "cosine":
49
+ return compute_cosine_distance(feat_1, feat_2)
50
+
51
+ elif metric == "jaccard":
52
+ feat = torch.cat((feat_1, feat_2), dim=0)
53
+ dist = compute_jaccard_distance(feat, k1=kwargs["k1"], k2=kwargs["k2"], search_option=0)
54
+ return dist[: feat_1.size(0), feat_1.size(0):]
55
+
56
+
57
+ def k_reciprocal_neigh(initial_rank, i, k1):
58
+ forward_k_neigh_index = initial_rank[i, : k1 + 1]
59
+ backward_k_neigh_index = initial_rank[forward_k_neigh_index, : k1 + 1]
60
+ fi = np.where(backward_k_neigh_index == i)[0]
61
+ return forward_k_neigh_index[fi]
62
+
63
+
64
+ @torch.no_grad()
65
+ def compute_jaccard_distance(features, k1=20, k2=6, search_option=0, fp16=False):
66
+ if search_option < 3:
67
+ # torch.cuda.empty_cache()
68
+ features = features.cuda()
69
+
70
+ ngpus = faiss.get_num_gpus()
71
+ N = features.size(0)
72
+ mat_type = np.float16 if fp16 else np.float32
73
+
74
+ if search_option == 0:
75
+ # GPU + PyTorch CUDA Tensors (1)
76
+ res = faiss.StandardGpuResources()
77
+ res.setDefaultNullStreamAllDevices()
78
+ _, initial_rank = search_raw_array_pytorch(res, features, features, k1)
79
+ initial_rank = initial_rank.cpu().numpy()
80
+ elif search_option == 1:
81
+ # GPU + PyTorch CUDA Tensors (2)
82
+ res = faiss.StandardGpuResources()
83
+ index = faiss.GpuIndexFlatL2(res, features.size(-1))
84
+ index.add(features.cpu().numpy())
85
+ _, initial_rank = search_index_pytorch(index, features, k1)
86
+ res.syncDefaultStreamCurrentDevice()
87
+ initial_rank = initial_rank.cpu().numpy()
88
+ elif search_option == 2:
89
+ # GPU
90
+ index = index_init_gpu(ngpus, features.size(-1))
91
+ index.add(features.cpu().numpy())
92
+ _, initial_rank = index.search(features.cpu().numpy(), k1)
93
+ else:
94
+ # CPU
95
+ index = index_init_cpu(features.size(-1))
96
+ index.add(features.cpu().numpy())
97
+ _, initial_rank = index.search(features.cpu().numpy(), k1)
98
+
99
+ nn_k1 = []
100
+ nn_k1_half = []
101
+ for i in range(N):
102
+ nn_k1.append(k_reciprocal_neigh(initial_rank, i, k1))
103
+ nn_k1_half.append(k_reciprocal_neigh(initial_rank, i, int(np.around(k1 / 2))))
104
+
105
+ V = np.zeros((N, N), dtype=mat_type)
106
+ for i in range(N):
107
+ k_reciprocal_index = nn_k1[i]
108
+ k_reciprocal_expansion_index = k_reciprocal_index
109
+ for candidate in k_reciprocal_index:
110
+ candidate_k_reciprocal_index = nn_k1_half[candidate]
111
+ if len(
112
+ np.intersect1d(candidate_k_reciprocal_index, k_reciprocal_index)
113
+ ) > 2 / 3 * len(candidate_k_reciprocal_index):
114
+ k_reciprocal_expansion_index = np.append(
115
+ k_reciprocal_expansion_index, candidate_k_reciprocal_index
116
+ )
117
+
118
+ k_reciprocal_expansion_index = np.unique(
119
+ k_reciprocal_expansion_index
120
+ ) # element-wise unique
121
+
122
+ x = features[i].unsqueeze(0).contiguous()
123
+ y = features[k_reciprocal_expansion_index]
124
+ m, n = x.size(0), y.size(0)
125
+ dist = (
126
+ torch.pow(x, 2).sum(dim=1, keepdim=True).expand(m, n)
127
+ + torch.pow(y, 2).sum(dim=1, keepdim=True).expand(n, m).t()
128
+ )
129
+ dist.addmm_(x, y.t(), beta=1, alpha=-2)
130
+
131
+ if fp16:
132
+ V[i, k_reciprocal_expansion_index] = (
133
+ F.softmax(-dist, dim=1).view(-1).cpu().numpy().astype(mat_type)
134
+ )
135
+ else:
136
+ V[i, k_reciprocal_expansion_index] = (
137
+ F.softmax(-dist, dim=1).view(-1).cpu().numpy()
138
+ )
139
+
140
+ del nn_k1, nn_k1_half, x, y
141
+ features = features.cpu()
142
+
143
+ if k2 != 1:
144
+ V_qe = np.zeros_like(V, dtype=mat_type)
145
+ for i in range(N):
146
+ V_qe[i, :] = np.mean(V[initial_rank[i, :k2], :], axis=0)
147
+ V = V_qe
148
+ del V_qe
149
+
150
+ del initial_rank
151
+
152
+ invIndex = []
153
+ for i in range(N):
154
+ invIndex.append(np.where(V[:, i] != 0)[0]) # len(invIndex)=all_num
155
+
156
+ jaccard_dist = np.zeros((N, N), dtype=mat_type)
157
+ for i in range(N):
158
+ temp_min = np.zeros((1, N), dtype=mat_type)
159
+ indNonZero = np.where(V[i, :] != 0)[0]
160
+ indImages = [invIndex[ind] for ind in indNonZero]
161
+ for j in range(len(indNonZero)):
162
+ temp_min[0, indImages[j]] = temp_min[0, indImages[j]] + np.minimum(
163
+ V[i, indNonZero[j]], V[indImages[j], indNonZero[j]]
164
+ )
165
+
166
+ jaccard_dist[i] = 1 - temp_min / (2 - temp_min)
167
+
168
+ del invIndex, V
169
+
170
+ pos_bool = jaccard_dist < 0
171
+ jaccard_dist[pos_bool] = 0.0
172
+
173
+ return jaccard_dist
174
+
175
+
176
+ @torch.no_grad()
177
+ def compute_euclidean_distance(features, others):
178
+ m, n = features.size(0), others.size(0)
179
+ dist_m = (
180
+ torch.pow(features, 2).sum(dim=1, keepdim=True).expand(m, n)
181
+ + torch.pow(others, 2).sum(dim=1, keepdim=True).expand(n, m).t()
182
+ )
183
+ dist_m.addmm_(1, -2, features, others.t())
184
+
185
+ return dist_m.cpu().numpy()
186
+
187
+
188
+ @torch.no_grad()
189
+ def compute_cosine_distance(features, others):
190
+ """Computes cosine distance.
191
+ Args:
192
+ features (torch.Tensor): 2-D feature matrix.
193
+ others (torch.Tensor): 2-D feature matrix.
194
+ Returns:
195
+ torch.Tensor: distance matrix.
196
+ """
197
+ features = F.normalize(features, p=2, dim=1)
198
+ others = F.normalize(others, p=2, dim=1)
199
+ dist_m = 1 - torch.mm(features, others.t())
200
+ return dist_m.cpu().numpy()
@@ -0,0 +1,119 @@
1
+ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
2
+ import importlib
3
+ import importlib.util
4
+ import logging
5
+ import numpy as np
6
+ import os
7
+ import random
8
+ import sys
9
+ from datetime import datetime
10
+ import torch
11
+
12
+ __all__ = ["seed_all_rng"]
13
+
14
+
15
+ TORCH_VERSION = tuple(int(x) for x in torch.__version__.split(".")[:2])
16
+ """
17
+ PyTorch version as a tuple of 2 ints. Useful for comparison.
18
+ """
19
+
20
+
21
+ def seed_all_rng(seed=None):
22
+ """
23
+ Set the random seed for the RNG in torch, numpy and python.
24
+ Args:
25
+ seed (int): if None, will use a strong random seed.
26
+ """
27
+ if seed is None:
28
+ seed = (
29
+ os.getpid()
30
+ + int(datetime.now().strftime("%S%f"))
31
+ + int.from_bytes(os.urandom(2), "big")
32
+ )
33
+ logger = logging.getLogger(__name__)
34
+ logger.info("Using a generated random seed {}".format(seed))
35
+ np.random.seed(seed)
36
+ torch.set_rng_state(torch.manual_seed(seed).get_state())
37
+ random.seed(seed)
38
+
39
+
40
+ # from https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path
41
+ def _import_file(module_name, file_path, make_importable=False):
42
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
43
+ module = importlib.util.module_from_spec(spec)
44
+ spec.loader.exec_module(module)
45
+ if make_importable:
46
+ sys.modules[module_name] = module
47
+ return module
48
+
49
+
50
+ def _configure_libraries():
51
+ """
52
+ Configurations for some libraries.
53
+ """
54
+ # An environment option to disable `import cv2` globally,
55
+ # in case it leads to negative performance impact
56
+ disable_cv2 = int(os.environ.get("DETECTRON2_DISABLE_CV2", False))
57
+ if disable_cv2:
58
+ sys.modules["cv2"] = None
59
+ else:
60
+ # Disable opencl in opencv since its interaction with cuda often has negative effects
61
+ # This envvar is supported after OpenCV 3.4.0
62
+ os.environ["OPENCV_OPENCL_RUNTIME"] = "disabled"
63
+ try:
64
+ import cv2
65
+
66
+ if int(cv2.__version__.split(".")[0]) >= 3:
67
+ cv2.ocl.setUseOpenCL(False)
68
+ except ImportError:
69
+ pass
70
+
71
+ def get_version(module, digit=2):
72
+ return tuple(map(int, module.__version__.split(".")[:digit]))
73
+
74
+ # fmt: off
75
+ assert get_version(torch) >= (1, 4), "Requires torch>=1.4"
76
+ import yaml
77
+ assert get_version(yaml) >= (5, 1), "Requires pyyaml>=5.1"
78
+ # fmt: on
79
+
80
+
81
+ _ENV_SETUP_DONE = False
82
+
83
+
84
+ def setup_environment():
85
+ """Perform environment setup work. The default setup is a no-op, but this
86
+ function allows the user to specify a Python source file or a module in
87
+ the $FASTREID_ENV_MODULE environment variable, that performs
88
+ custom setup work that may be necessary to their computing environment.
89
+ """
90
+ global _ENV_SETUP_DONE
91
+ if _ENV_SETUP_DONE:
92
+ return
93
+ _ENV_SETUP_DONE = True
94
+
95
+ _configure_libraries()
96
+
97
+ custom_module_path = os.environ.get("FASTREID_ENV_MODULE")
98
+
99
+ if custom_module_path:
100
+ setup_custom_environment(custom_module_path)
101
+ else:
102
+ # The default setup is a no-op
103
+ pass
104
+
105
+
106
+ def setup_custom_environment(custom_module):
107
+ """
108
+ Load custom environment setup by importing a Python source file or a
109
+ module, and run the setup function.
110
+ """
111
+ if custom_module.endswith(".py"):
112
+ module = _import_file("fastreid.utils.env.custom_module", custom_module)
113
+ else:
114
+ module = importlib.import_module(custom_module)
115
+ assert hasattr(module, "setup_environment") and callable(module.setup_environment), (
116
+ "Custom environment module defined in {} does not have the "
117
+ "required callable attribute 'setup_environment'."
118
+ ).format(custom_module)
119
+ module.setup_environment()