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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. dnt/__init__.py +4 -1
  2. dnt/analysis/__init__.py +3 -1
  3. dnt/analysis/count.py +107 -0
  4. dnt/analysis/interaction2.py +518 -0
  5. dnt/analysis/position.py +12 -0
  6. dnt/analysis/stop.py +92 -33
  7. dnt/analysis/stop2.py +289 -0
  8. dnt/analysis/stop3.py +758 -0
  9. dnt/detect/__init__.py +1 -1
  10. dnt/detect/signal/detector.py +326 -0
  11. dnt/detect/timestamp.py +105 -0
  12. dnt/detect/yolov8/detector.py +182 -35
  13. dnt/detect/yolov8/segmentor.py +171 -0
  14. dnt/engine/__init__.py +8 -0
  15. dnt/engine/bbox_interp.py +83 -0
  16. dnt/engine/bbox_iou.py +20 -0
  17. dnt/engine/cluster.py +31 -0
  18. dnt/engine/iob.py +66 -0
  19. dnt/filter/__init__.py +4 -0
  20. dnt/filter/filter.py +450 -21
  21. dnt/label/__init__.py +1 -1
  22. dnt/label/labeler.py +215 -14
  23. dnt/label/labeler2.py +631 -0
  24. dnt/shared/__init__.py +2 -1
  25. dnt/shared/data/coco.names +0 -0
  26. dnt/shared/data/openimages.names +0 -0
  27. dnt/shared/data/voc.names +0 -0
  28. dnt/shared/download.py +12 -0
  29. dnt/shared/synhcro.py +150 -0
  30. dnt/shared/util.py +17 -4
  31. dnt/third_party/fast-reid/__init__.py +1 -0
  32. dnt/third_party/fast-reid/configs/Base-AGW.yml +19 -0
  33. dnt/third_party/fast-reid/configs/Base-MGN.yml +12 -0
  34. dnt/third_party/fast-reid/configs/Base-SBS.yml +63 -0
  35. dnt/third_party/fast-reid/configs/Base-bagtricks.yml +76 -0
  36. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R101-ibn.yml +12 -0
  37. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50-ibn.yml +11 -0
  38. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50.yml +7 -0
  39. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_S50.yml +11 -0
  40. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R101-ibn.yml +12 -0
  41. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50-ibn.yml +11 -0
  42. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50.yml +7 -0
  43. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_S50.yml +11 -0
  44. dnt/third_party/fast-reid/configs/DukeMTMC/mgn_R50-ibn.yml +11 -0
  45. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R101-ibn.yml +12 -0
  46. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50-ibn.yml +11 -0
  47. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50.yml +7 -0
  48. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_S50.yml +11 -0
  49. dnt/third_party/fast-reid/configs/MOT17/AGW_R101-ibn.yml +12 -0
  50. dnt/third_party/fast-reid/configs/MOT17/AGW_R50-ibn.yml +11 -0
  51. dnt/third_party/fast-reid/configs/MOT17/AGW_R50.yml +7 -0
  52. dnt/third_party/fast-reid/configs/MOT17/AGW_S50.yml +11 -0
  53. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R101-ibn.yml +12 -0
  54. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50-ibn.yml +11 -0
  55. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50.yml +7 -0
  56. dnt/third_party/fast-reid/configs/MOT17/bagtricks_S50.yml +11 -0
  57. dnt/third_party/fast-reid/configs/MOT17/mgn_R50-ibn.yml +11 -0
  58. dnt/third_party/fast-reid/configs/MOT17/sbs_R101-ibn.yml +12 -0
  59. dnt/third_party/fast-reid/configs/MOT17/sbs_R50-ibn.yml +11 -0
  60. dnt/third_party/fast-reid/configs/MOT17/sbs_R50.yml +7 -0
  61. dnt/third_party/fast-reid/configs/MOT17/sbs_S50.yml +11 -0
  62. dnt/third_party/fast-reid/configs/MOT20/AGW_R101-ibn.yml +12 -0
  63. dnt/third_party/fast-reid/configs/MOT20/AGW_R50-ibn.yml +11 -0
  64. dnt/third_party/fast-reid/configs/MOT20/AGW_R50.yml +7 -0
  65. dnt/third_party/fast-reid/configs/MOT20/AGW_S50.yml +11 -0
  66. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R101-ibn.yml +12 -0
  67. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50-ibn.yml +11 -0
  68. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50.yml +7 -0
  69. dnt/third_party/fast-reid/configs/MOT20/bagtricks_S50.yml +11 -0
  70. dnt/third_party/fast-reid/configs/MOT20/mgn_R50-ibn.yml +11 -0
  71. dnt/third_party/fast-reid/configs/MOT20/sbs_R101-ibn.yml +12 -0
  72. dnt/third_party/fast-reid/configs/MOT20/sbs_R50-ibn.yml +11 -0
  73. dnt/third_party/fast-reid/configs/MOT20/sbs_R50.yml +7 -0
  74. dnt/third_party/fast-reid/configs/MOT20/sbs_S50.yml +11 -0
  75. dnt/third_party/fast-reid/configs/MSMT17/AGW_R101-ibn.yml +12 -0
  76. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50-ibn.yml +11 -0
  77. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50.yml +7 -0
  78. dnt/third_party/fast-reid/configs/MSMT17/AGW_S50.yml +11 -0
  79. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R101-ibn.yml +13 -0
  80. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50-ibn.yml +12 -0
  81. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50.yml +7 -0
  82. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_S50.yml +12 -0
  83. dnt/third_party/fast-reid/configs/MSMT17/mgn_R50-ibn.yml +11 -0
  84. dnt/third_party/fast-reid/configs/MSMT17/sbs_R101-ibn.yml +12 -0
  85. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50-ibn.yml +11 -0
  86. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50.yml +7 -0
  87. dnt/third_party/fast-reid/configs/MSMT17/sbs_S50.yml +11 -0
  88. dnt/third_party/fast-reid/configs/Market1501/AGW_R101-ibn.yml +12 -0
  89. dnt/third_party/fast-reid/configs/Market1501/AGW_R50-ibn.yml +11 -0
  90. dnt/third_party/fast-reid/configs/Market1501/AGW_R50.yml +7 -0
  91. dnt/third_party/fast-reid/configs/Market1501/AGW_S50.yml +11 -0
  92. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R101-ibn.yml +12 -0
  93. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50-ibn.yml +11 -0
  94. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50.yml +7 -0
  95. dnt/third_party/fast-reid/configs/Market1501/bagtricks_S50.yml +11 -0
  96. dnt/third_party/fast-reid/configs/Market1501/bagtricks_vit.yml +88 -0
  97. dnt/third_party/fast-reid/configs/Market1501/mgn_R50-ibn.yml +11 -0
  98. dnt/third_party/fast-reid/configs/Market1501/sbs_R101-ibn.yml +12 -0
  99. dnt/third_party/fast-reid/configs/Market1501/sbs_R50-ibn.yml +11 -0
  100. dnt/third_party/fast-reid/configs/Market1501/sbs_R50.yml +7 -0
  101. dnt/third_party/fast-reid/configs/Market1501/sbs_S50.yml +11 -0
  102. dnt/third_party/fast-reid/configs/VERIWild/bagtricks_R50-ibn.yml +35 -0
  103. dnt/third_party/fast-reid/configs/VeRi/sbs_R50-ibn.yml +35 -0
  104. dnt/third_party/fast-reid/configs/VehicleID/bagtricks_R50-ibn.yml +36 -0
  105. dnt/third_party/fast-reid/configs/__init__.py +0 -0
  106. dnt/third_party/fast-reid/fast_reid_interfece.py +175 -0
  107. dnt/third_party/fast-reid/fastreid/__init__.py +6 -0
  108. dnt/third_party/fast-reid/fastreid/config/__init__.py +15 -0
  109. dnt/third_party/fast-reid/fastreid/config/config.py +319 -0
  110. dnt/third_party/fast-reid/fastreid/config/defaults.py +329 -0
  111. dnt/third_party/fast-reid/fastreid/data/__init__.py +17 -0
  112. dnt/third_party/fast-reid/fastreid/data/build.py +194 -0
  113. dnt/third_party/fast-reid/fastreid/data/common.py +58 -0
  114. dnt/third_party/fast-reid/fastreid/data/data_utils.py +202 -0
  115. dnt/third_party/fast-reid/fastreid/data/datasets/AirportALERT.py +50 -0
  116. dnt/third_party/fast-reid/fastreid/data/datasets/__init__.py +43 -0
  117. dnt/third_party/fast-reid/fastreid/data/datasets/bases.py +183 -0
  118. dnt/third_party/fast-reid/fastreid/data/datasets/caviara.py +44 -0
  119. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk03.py +274 -0
  120. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk_sysu.py +58 -0
  121. dnt/third_party/fast-reid/fastreid/data/datasets/dukemtmcreid.py +70 -0
  122. dnt/third_party/fast-reid/fastreid/data/datasets/grid.py +44 -0
  123. dnt/third_party/fast-reid/fastreid/data/datasets/iLIDS.py +45 -0
  124. dnt/third_party/fast-reid/fastreid/data/datasets/lpw.py +49 -0
  125. dnt/third_party/fast-reid/fastreid/data/datasets/market1501.py +89 -0
  126. dnt/third_party/fast-reid/fastreid/data/datasets/msmt17.py +114 -0
  127. dnt/third_party/fast-reid/fastreid/data/datasets/pes3d.py +44 -0
  128. dnt/third_party/fast-reid/fastreid/data/datasets/pku.py +44 -0
  129. dnt/third_party/fast-reid/fastreid/data/datasets/prai.py +43 -0
  130. dnt/third_party/fast-reid/fastreid/data/datasets/prid.py +41 -0
  131. dnt/third_party/fast-reid/fastreid/data/datasets/saivt.py +47 -0
  132. dnt/third_party/fast-reid/fastreid/data/datasets/sensereid.py +47 -0
  133. dnt/third_party/fast-reid/fastreid/data/datasets/shinpuhkan.py +48 -0
  134. dnt/third_party/fast-reid/fastreid/data/datasets/sysu_mm.py +47 -0
  135. dnt/third_party/fast-reid/fastreid/data/datasets/thermalworld.py +43 -0
  136. dnt/third_party/fast-reid/fastreid/data/datasets/vehicleid.py +126 -0
  137. dnt/third_party/fast-reid/fastreid/data/datasets/veri.py +69 -0
  138. dnt/third_party/fast-reid/fastreid/data/datasets/veriwild.py +140 -0
  139. dnt/third_party/fast-reid/fastreid/data/datasets/viper.py +45 -0
  140. dnt/third_party/fast-reid/fastreid/data/datasets/wildtracker.py +59 -0
  141. dnt/third_party/fast-reid/fastreid/data/samplers/__init__.py +18 -0
  142. dnt/third_party/fast-reid/fastreid/data/samplers/data_sampler.py +85 -0
  143. dnt/third_party/fast-reid/fastreid/data/samplers/imbalance_sampler.py +67 -0
  144. dnt/third_party/fast-reid/fastreid/data/samplers/triplet_sampler.py +260 -0
  145. dnt/third_party/fast-reid/fastreid/data/transforms/__init__.py +11 -0
  146. dnt/third_party/fast-reid/fastreid/data/transforms/autoaugment.py +806 -0
  147. dnt/third_party/fast-reid/fastreid/data/transforms/build.py +100 -0
  148. dnt/third_party/fast-reid/fastreid/data/transforms/functional.py +180 -0
  149. dnt/third_party/fast-reid/fastreid/data/transforms/transforms.py +161 -0
  150. dnt/third_party/fast-reid/fastreid/engine/__init__.py +15 -0
  151. dnt/third_party/fast-reid/fastreid/engine/defaults.py +490 -0
  152. dnt/third_party/fast-reid/fastreid/engine/hooks.py +534 -0
  153. dnt/third_party/fast-reid/fastreid/engine/launch.py +103 -0
  154. dnt/third_party/fast-reid/fastreid/engine/train_loop.py +357 -0
  155. dnt/third_party/fast-reid/fastreid/evaluation/__init__.py +6 -0
  156. dnt/third_party/fast-reid/fastreid/evaluation/clas_evaluator.py +81 -0
  157. dnt/third_party/fast-reid/fastreid/evaluation/evaluator.py +176 -0
  158. dnt/third_party/fast-reid/fastreid/evaluation/query_expansion.py +46 -0
  159. dnt/third_party/fast-reid/fastreid/evaluation/rank.py +200 -0
  160. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/__init__.py +20 -0
  161. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/setup.py +32 -0
  162. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/test_cython.py +106 -0
  163. dnt/third_party/fast-reid/fastreid/evaluation/reid_evaluation.py +143 -0
  164. dnt/third_party/fast-reid/fastreid/evaluation/rerank.py +73 -0
  165. dnt/third_party/fast-reid/fastreid/evaluation/roc.py +90 -0
  166. dnt/third_party/fast-reid/fastreid/evaluation/testing.py +88 -0
  167. dnt/third_party/fast-reid/fastreid/layers/__init__.py +19 -0
  168. dnt/third_party/fast-reid/fastreid/layers/activation.py +59 -0
  169. dnt/third_party/fast-reid/fastreid/layers/any_softmax.py +80 -0
  170. dnt/third_party/fast-reid/fastreid/layers/batch_norm.py +205 -0
  171. dnt/third_party/fast-reid/fastreid/layers/context_block.py +113 -0
  172. dnt/third_party/fast-reid/fastreid/layers/drop.py +161 -0
  173. dnt/third_party/fast-reid/fastreid/layers/frn.py +199 -0
  174. dnt/third_party/fast-reid/fastreid/layers/gather_layer.py +30 -0
  175. dnt/third_party/fast-reid/fastreid/layers/helpers.py +31 -0
  176. dnt/third_party/fast-reid/fastreid/layers/non_local.py +54 -0
  177. dnt/third_party/fast-reid/fastreid/layers/pooling.py +124 -0
  178. dnt/third_party/fast-reid/fastreid/layers/se_layer.py +25 -0
  179. dnt/third_party/fast-reid/fastreid/layers/splat.py +109 -0
  180. dnt/third_party/fast-reid/fastreid/layers/weight_init.py +122 -0
  181. dnt/third_party/fast-reid/fastreid/modeling/__init__.py +23 -0
  182. dnt/third_party/fast-reid/fastreid/modeling/backbones/__init__.py +18 -0
  183. dnt/third_party/fast-reid/fastreid/modeling/backbones/build.py +27 -0
  184. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenet.py +195 -0
  185. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenetv3.py +283 -0
  186. dnt/third_party/fast-reid/fastreid/modeling/backbones/osnet.py +525 -0
  187. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/__init__.py +4 -0
  188. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/config.py +396 -0
  189. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B0_dds_8gpu.yaml +27 -0
  190. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B1_dds_8gpu.yaml +27 -0
  191. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B2_dds_8gpu.yaml +27 -0
  192. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B3_dds_8gpu.yaml +27 -0
  193. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B4_dds_8gpu.yaml +27 -0
  194. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B5_dds_8gpu.yaml +27 -0
  195. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet.py +281 -0
  196. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnet.py +596 -0
  197. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-1.6GF_dds_8gpu.yaml +26 -0
  198. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-12GF_dds_8gpu.yaml +26 -0
  199. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-16GF_dds_8gpu.yaml +26 -0
  200. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-200MF_dds_8gpu.yaml +26 -0
  201. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-3.2GF_dds_8gpu.yaml +26 -0
  202. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-32GF_dds_8gpu.yaml +26 -0
  203. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-4.0GF_dds_8gpu.yaml +26 -0
  204. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-400MF_dds_8gpu.yaml +26 -0
  205. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-6.4GF_dds_8gpu.yaml +26 -0
  206. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-600MF_dds_8gpu.yaml +26 -0
  207. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-8.0GF_dds_8gpu.yaml +26 -0
  208. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-800MF_dds_8gpu.yaml +26 -0
  209. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-1.6GF_dds_8gpu.yaml +27 -0
  210. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-12GF_dds_8gpu.yaml +27 -0
  211. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-16GF_dds_8gpu.yaml +27 -0
  212. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-200MF_dds_8gpu.yaml +26 -0
  213. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-3.2GF_dds_8gpu.yaml +27 -0
  214. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-32GF_dds_8gpu.yaml +27 -0
  215. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-4.0GF_dds_8gpu.yaml +27 -0
  216. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-400MF_dds_8gpu.yaml +27 -0
  217. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-6.4GF_dds_8gpu.yaml +27 -0
  218. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-600MF_dds_8gpu.yaml +27 -0
  219. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-8.0GF_dds_8gpu.yaml +27 -0
  220. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-800MF_dds_8gpu.yaml +27 -0
  221. dnt/third_party/fast-reid/fastreid/modeling/backbones/repvgg.py +309 -0
  222. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnest.py +365 -0
  223. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnet.py +364 -0
  224. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnext.py +335 -0
  225. dnt/third_party/fast-reid/fastreid/modeling/backbones/shufflenet.py +203 -0
  226. dnt/third_party/fast-reid/fastreid/modeling/backbones/vision_transformer.py +399 -0
  227. dnt/third_party/fast-reid/fastreid/modeling/heads/__init__.py +11 -0
  228. dnt/third_party/fast-reid/fastreid/modeling/heads/build.py +25 -0
  229. dnt/third_party/fast-reid/fastreid/modeling/heads/clas_head.py +36 -0
  230. dnt/third_party/fast-reid/fastreid/modeling/heads/embedding_head.py +151 -0
  231. dnt/third_party/fast-reid/fastreid/modeling/losses/__init__.py +12 -0
  232. dnt/third_party/fast-reid/fastreid/modeling/losses/circle_loss.py +71 -0
  233. dnt/third_party/fast-reid/fastreid/modeling/losses/cross_entroy_loss.py +54 -0
  234. dnt/third_party/fast-reid/fastreid/modeling/losses/focal_loss.py +92 -0
  235. dnt/third_party/fast-reid/fastreid/modeling/losses/triplet_loss.py +113 -0
  236. dnt/third_party/fast-reid/fastreid/modeling/losses/utils.py +48 -0
  237. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/__init__.py +14 -0
  238. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/baseline.py +188 -0
  239. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/build.py +26 -0
  240. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/distiller.py +140 -0
  241. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/mgn.py +394 -0
  242. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/moco.py +126 -0
  243. dnt/third_party/fast-reid/fastreid/solver/__init__.py +8 -0
  244. dnt/third_party/fast-reid/fastreid/solver/build.py +348 -0
  245. dnt/third_party/fast-reid/fastreid/solver/lr_scheduler.py +66 -0
  246. dnt/third_party/fast-reid/fastreid/solver/optim/__init__.py +10 -0
  247. dnt/third_party/fast-reid/fastreid/solver/optim/lamb.py +123 -0
  248. dnt/third_party/fast-reid/fastreid/solver/optim/radam.py +149 -0
  249. dnt/third_party/fast-reid/fastreid/solver/optim/swa.py +246 -0
  250. dnt/third_party/fast-reid/fastreid/utils/__init__.py +6 -0
  251. dnt/third_party/fast-reid/fastreid/utils/checkpoint.py +503 -0
  252. dnt/third_party/fast-reid/fastreid/utils/collect_env.py +158 -0
  253. dnt/third_party/fast-reid/fastreid/utils/comm.py +255 -0
  254. dnt/third_party/fast-reid/fastreid/utils/compute_dist.py +200 -0
  255. dnt/third_party/fast-reid/fastreid/utils/env.py +119 -0
  256. dnt/third_party/fast-reid/fastreid/utils/events.py +461 -0
  257. dnt/third_party/fast-reid/fastreid/utils/faiss_utils.py +127 -0
  258. dnt/third_party/fast-reid/fastreid/utils/file_io.py +520 -0
  259. dnt/third_party/fast-reid/fastreid/utils/history_buffer.py +71 -0
  260. dnt/third_party/fast-reid/fastreid/utils/logger.py +211 -0
  261. dnt/third_party/fast-reid/fastreid/utils/params.py +103 -0
  262. dnt/third_party/fast-reid/fastreid/utils/precision_bn.py +94 -0
  263. dnt/third_party/fast-reid/fastreid/utils/registry.py +66 -0
  264. dnt/third_party/fast-reid/fastreid/utils/summary.py +120 -0
  265. dnt/third_party/fast-reid/fastreid/utils/timer.py +68 -0
  266. dnt/third_party/fast-reid/fastreid/utils/visualizer.py +278 -0
  267. dnt/track/__init__.py +3 -1
  268. dnt/track/botsort/__init__.py +4 -0
  269. dnt/track/botsort/bot_tracker/__init__.py +3 -0
  270. dnt/track/botsort/bot_tracker/basetrack.py +60 -0
  271. dnt/track/botsort/bot_tracker/bot_sort.py +473 -0
  272. dnt/track/botsort/bot_tracker/gmc.py +316 -0
  273. dnt/track/botsort/bot_tracker/kalman_filter.py +269 -0
  274. dnt/track/botsort/bot_tracker/matching.py +194 -0
  275. dnt/track/botsort/bot_tracker/mc_bot_sort.py +505 -0
  276. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/evaluation.py +14 -4
  277. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/io.py +19 -36
  278. dnt/track/botsort/bot_tracker/tracking_utils/timer.py +37 -0
  279. dnt/track/botsort/inference.py +96 -0
  280. dnt/track/config.py +120 -0
  281. dnt/track/dsort/configs/bagtricks_R50.yml +7 -0
  282. dnt/track/dsort/configs/deep_sort.yaml +0 -0
  283. dnt/track/dsort/configs/fastreid.yaml +1 -1
  284. dnt/track/dsort/deep_sort/deep/checkpoint/ckpt.t7 +0 -0
  285. dnt/track/dsort/deep_sort/deep/feature_extractor.py +87 -8
  286. dnt/track/dsort/deep_sort/deep_sort.py +31 -21
  287. dnt/track/dsort/deep_sort/sort/detection.py +2 -1
  288. dnt/track/dsort/deep_sort/sort/iou_matching.py +0 -2
  289. dnt/track/dsort/deep_sort/sort/linear_assignment.py +0 -3
  290. dnt/track/dsort/deep_sort/sort/nn_matching.py +5 -5
  291. dnt/track/dsort/deep_sort/sort/preprocessing.py +1 -2
  292. dnt/track/dsort/deep_sort/sort/track.py +2 -1
  293. dnt/track/dsort/deep_sort/sort/tracker.py +1 -1
  294. dnt/track/dsort/dsort.py +44 -27
  295. dnt/track/re_class.py +117 -0
  296. dnt/track/sort/sort.py +9 -7
  297. dnt/track/tracker.py +225 -20
  298. dnt-0.3.1.8.dist-info/METADATA +117 -0
  299. dnt-0.3.1.8.dist-info/RECORD +315 -0
  300. {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info}/WHEEL +1 -1
  301. dnt/track/dsort/deep_sort/deep/evaluate.py +0 -15
  302. dnt/track/dsort/deep_sort/deep/original_model.py +0 -106
  303. dnt/track/dsort/deep_sort/deep/test.py +0 -77
  304. dnt/track/dsort/deep_sort/deep/train.py +0 -189
  305. dnt/track/dsort/utils/asserts.py +0 -13
  306. dnt/track/dsort/utils/draw.py +0 -36
  307. dnt/track/dsort/utils/json_logger.py +0 -383
  308. dnt/track/dsort/utils/log.py +0 -17
  309. dnt/track/dsort/utils/parser.py +0 -35
  310. dnt/track/dsort/utils/tools.py +0 -39
  311. dnt-0.2.1.dist-info/METADATA +0 -35
  312. dnt-0.2.1.dist-info/RECORD +0 -60
  313. /dnt/{track/dsort/utils → third_party/fast-reid/checkpoint}/__init__.py +0 -0
  314. {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info/licenses}/LICENSE +0 -0
  315. {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,461 @@
1
+ # Copyright (c) Facebook, Inc. and its affiliates.
2
+ import datetime
3
+ import json
4
+ import logging
5
+ import os
6
+ import time
7
+ from collections import defaultdict
8
+ from contextlib import contextmanager
9
+ import torch
10
+ from .file_io import PathManager
11
+ from .history_buffer import HistoryBuffer
12
+
13
+ __all__ = [
14
+ "get_event_storage",
15
+ "JSONWriter",
16
+ "TensorboardXWriter",
17
+ "CommonMetricPrinter",
18
+ "EventStorage",
19
+ ]
20
+
21
+ _CURRENT_STORAGE_STACK = []
22
+
23
+
24
+ def get_event_storage():
25
+ """
26
+ Returns:
27
+ The :class:`EventStorage` object that's currently being used.
28
+ Throws an error if no :class:`EventStorage` is currently enabled.
29
+ """
30
+ assert len(
31
+ _CURRENT_STORAGE_STACK
32
+ ), "get_event_storage() has to be called inside a 'with EventStorage(...)' context!"
33
+ return _CURRENT_STORAGE_STACK[-1]
34
+
35
+
36
+ class EventWriter:
37
+ """
38
+ Base class for writers that obtain events from :class:`EventStorage` and process them.
39
+ """
40
+
41
+ def write(self):
42
+ raise NotImplementedError
43
+
44
+ def close(self):
45
+ pass
46
+
47
+
48
+ class JSONWriter(EventWriter):
49
+ """
50
+ Write scalars to a json file.
51
+ It saves scalars as one json per line (instead of a big json) for easy parsing.
52
+ Examples parsing such a json file:
53
+ ::
54
+ $ cat metrics.json | jq -s '.[0:2]'
55
+ [
56
+ {
57
+ "data_time": 0.008433341979980469,
58
+ "iteration": 19,
59
+ "loss": 1.9228371381759644,
60
+ "loss_box_reg": 0.050025828182697296,
61
+ "loss_classifier": 0.5316952466964722,
62
+ "loss_mask": 0.7236229181289673,
63
+ "loss_rpn_box": 0.0856662318110466,
64
+ "loss_rpn_cls": 0.48198649287223816,
65
+ "lr": 0.007173333333333333,
66
+ "time": 0.25401854515075684
67
+ },
68
+ {
69
+ "data_time": 0.007216215133666992,
70
+ "iteration": 39,
71
+ "loss": 1.282649278640747,
72
+ "loss_box_reg": 0.06222952902317047,
73
+ "loss_classifier": 0.30682939291000366,
74
+ "loss_mask": 0.6970193982124329,
75
+ "loss_rpn_box": 0.038663312792778015,
76
+ "loss_rpn_cls": 0.1471673548221588,
77
+ "lr": 0.007706666666666667,
78
+ "time": 0.2490077018737793
79
+ }
80
+ ]
81
+ $ cat metrics.json | jq '.loss_mask'
82
+ 0.7126231789588928
83
+ 0.689423680305481
84
+ 0.6776131987571716
85
+ ...
86
+ """
87
+
88
+ def __init__(self, json_file, window_size=20):
89
+ """
90
+ Args:
91
+ json_file (str): path to the json file. New data will be appended if the file exists.
92
+ window_size (int): the window size of median smoothing for the scalars whose
93
+ `smoothing_hint` are True.
94
+ """
95
+ self._file_handle = PathManager.open(json_file, "a")
96
+ self._window_size = window_size
97
+ self._last_write = -1
98
+
99
+ def write(self):
100
+ storage = get_event_storage()
101
+ to_save = defaultdict(dict)
102
+
103
+ for k, (v, iter) in storage.latest_with_smoothing_hint(self._window_size).items():
104
+ # keep scalars that have not been written
105
+ if iter <= self._last_write:
106
+ continue
107
+ to_save[iter][k] = v
108
+ if len(to_save):
109
+ all_iters = sorted(to_save.keys())
110
+ self._last_write = max(all_iters)
111
+
112
+ for itr, scalars_per_iter in to_save.items():
113
+ scalars_per_iter["iteration"] = itr
114
+ self._file_handle.write(json.dumps(scalars_per_iter, sort_keys=True) + "\n")
115
+ self._file_handle.flush()
116
+ try:
117
+ os.fsync(self._file_handle.fileno())
118
+ except AttributeError:
119
+ pass
120
+
121
+ def close(self):
122
+ self._file_handle.close()
123
+
124
+
125
+ class TensorboardXWriter(EventWriter):
126
+ """
127
+ Write all scalars to a tensorboard file.
128
+ """
129
+
130
+ def __init__(self, log_dir: str, window_size: int = 20, **kwargs):
131
+ """
132
+ Args:
133
+ log_dir (str): the directory to save the output events
134
+ window_size (int): the scalars will be median-smoothed by this window size
135
+ kwargs: other arguments passed to `torch.utils.tensorboard.SummaryWriter(...)`
136
+ """
137
+ self._window_size = window_size
138
+ from torch.utils.tensorboard import SummaryWriter
139
+
140
+ self._writer = SummaryWriter(log_dir, **kwargs)
141
+ self._last_write = -1
142
+
143
+ def write(self):
144
+ storage = get_event_storage()
145
+ new_last_write = self._last_write
146
+ for k, (v, iter) in storage.latest_with_smoothing_hint(self._window_size).items():
147
+ if iter > self._last_write:
148
+ self._writer.add_scalar(k, v, iter)
149
+ new_last_write = max(new_last_write, iter)
150
+ self._last_write = new_last_write
151
+
152
+ # storage.put_{image,histogram} is only meant to be used by
153
+ # tensorboard writer. So we access its internal fields directly from here.
154
+ if len(storage._vis_data) >= 1:
155
+ for img_name, img, step_num in storage._vis_data:
156
+ self._writer.add_image(img_name, img, step_num)
157
+ # Storage stores all image data and rely on this writer to clear them.
158
+ # As a result it assumes only one writer will use its image data.
159
+ # An alternative design is to let storage store limited recent
160
+ # data (e.g. only the most recent image) that all writers can access.
161
+ # In that case a writer may not see all image data if its period is long.
162
+ storage.clear_images()
163
+
164
+ if len(storage._histograms) >= 1:
165
+ for params in storage._histograms:
166
+ self._writer.add_histogram_raw(**params)
167
+ storage.clear_histograms()
168
+
169
+ def close(self):
170
+ if hasattr(self, "_writer"): # doesn't exist when the code fails at import
171
+ self._writer.close()
172
+
173
+
174
+ class CommonMetricPrinter(EventWriter):
175
+ """
176
+ Print **common** metrics to the terminal, including
177
+ iteration time, ETA, memory, all losses, and the learning rate.
178
+ It also applies smoothing using a window of 20 elements.
179
+ It's meant to print common metrics in common ways.
180
+ To print something in more customized ways, please implement a similar printer by yourself.
181
+ """
182
+
183
+ def __init__(self, max_iter):
184
+ """
185
+ Args:
186
+ max_iter (int): the maximum number of iterations to train.
187
+ Used to compute ETA.
188
+ """
189
+ self.logger = logging.getLogger(__name__)
190
+ self._max_iter = max_iter
191
+ self._last_write = None
192
+
193
+ def write(self):
194
+ storage = get_event_storage()
195
+ iteration = storage.iter
196
+ epoch = storage.epoch
197
+ if iteration == self._max_iter:
198
+ # This hook only reports training progress (loss, ETA, etc) but not other data,
199
+ # therefore do not write anything after training succeeds, even if this method
200
+ # is called.
201
+ return
202
+
203
+ try:
204
+ data_time = storage.history("data_time").avg(20)
205
+ except KeyError:
206
+ # they may not exist in the first few iterations (due to warmup)
207
+ # or when SimpleTrainer is not used
208
+ data_time = None
209
+
210
+ eta_string = None
211
+ try:
212
+ iter_time = storage.history("time").global_avg()
213
+ eta_seconds = storage.history("time").median(1000) * (self._max_iter - iteration - 1)
214
+ storage.put_scalar("eta_seconds", eta_seconds, smoothing_hint=False)
215
+ eta_string = str(datetime.timedelta(seconds=int(eta_seconds)))
216
+ except KeyError:
217
+ iter_time = None
218
+ # estimate eta on our own - more noisy
219
+ if self._last_write is not None:
220
+ estimate_iter_time = (time.perf_counter() - self._last_write[1]) / (
221
+ iteration - self._last_write[0]
222
+ )
223
+ eta_seconds = estimate_iter_time * (self._max_iter - iteration - 1)
224
+ eta_string = str(datetime.timedelta(seconds=int(eta_seconds)))
225
+ self._last_write = (iteration, time.perf_counter())
226
+
227
+ try:
228
+ lr = "{:.2e}".format(storage.history("lr").latest())
229
+ except KeyError:
230
+ lr = "N/A"
231
+
232
+ if torch.cuda.is_available():
233
+ max_mem_mb = torch.cuda.max_memory_allocated() / 1024.0 / 1024.0
234
+ else:
235
+ max_mem_mb = None
236
+
237
+ # NOTE: max_mem is parsed by grep in "dev/parse_results.sh"
238
+ self.logger.info(
239
+ " {eta}epoch/iter: {epoch}/{iter} {losses} {time}{data_time}lr: {lr} {memory}".format(
240
+ eta=f"eta: {eta_string} " if eta_string else "",
241
+ epoch=epoch,
242
+ iter=iteration,
243
+ losses=" ".join(
244
+ [
245
+ "{}: {:.4g}".format(k, v.median(200))
246
+ for k, v in storage.histories().items()
247
+ if "loss" in k
248
+ ]
249
+ ),
250
+ time="time: {:.4f} ".format(iter_time) if iter_time is not None else "",
251
+ data_time="data_time: {:.4f} ".format(data_time) if data_time is not None else "",
252
+ lr=lr,
253
+ memory="max_mem: {:.0f}M".format(max_mem_mb) if max_mem_mb is not None else "",
254
+ )
255
+ )
256
+
257
+
258
+ class EventStorage:
259
+ """
260
+ The user-facing class that provides metric storage functionalities.
261
+ In the future we may add support for storing / logging other types of data if needed.
262
+ """
263
+
264
+ def __init__(self, start_iter=0):
265
+ """
266
+ Args:
267
+ start_iter (int): the iteration number to start with
268
+ """
269
+ self._history = defaultdict(HistoryBuffer)
270
+ self._smoothing_hints = {}
271
+ self._latest_scalars = {}
272
+ self._iter = start_iter
273
+ self._current_prefix = ""
274
+ self._vis_data = []
275
+ self._histograms = []
276
+
277
+ def put_image(self, img_name, img_tensor):
278
+ """
279
+ Add an `img_tensor` associated with `img_name`, to be shown on
280
+ tensorboard.
281
+ Args:
282
+ img_name (str): The name of the image to put into tensorboard.
283
+ img_tensor (torch.Tensor or numpy.array): An `uint8` or `float`
284
+ Tensor of shape `[channel, height, width]` where `channel` is
285
+ 3. The image format should be RGB. The elements in img_tensor
286
+ can either have values in [0, 1] (float32) or [0, 255] (uint8).
287
+ The `img_tensor` will be visualized in tensorboard.
288
+ """
289
+ self._vis_data.append((img_name, img_tensor, self._iter))
290
+
291
+ def put_scalar(self, name, value, smoothing_hint=True):
292
+ """
293
+ Add a scalar `value` to the `HistoryBuffer` associated with `name`.
294
+ Args:
295
+ smoothing_hint (bool): a 'hint' on whether this scalar is noisy and should be
296
+ smoothed when logged. The hint will be accessible through
297
+ :meth:`EventStorage.smoothing_hints`. A writer may ignore the hint
298
+ and apply custom smoothing rule.
299
+ It defaults to True because most scalars we save need to be smoothed to
300
+ provide any useful signal.
301
+ """
302
+ name = self._current_prefix + name
303
+ history = self._history[name]
304
+ value = float(value)
305
+ history.update(value, self._iter)
306
+ self._latest_scalars[name] = (value, self._iter)
307
+
308
+ existing_hint = self._smoothing_hints.get(name)
309
+ if existing_hint is not None:
310
+ assert (
311
+ existing_hint == smoothing_hint
312
+ ), "Scalar {} was put with a different smoothing_hint!".format(name)
313
+ else:
314
+ self._smoothing_hints[name] = smoothing_hint
315
+
316
+ def put_scalars(self, *, smoothing_hint=True, **kwargs):
317
+ """
318
+ Put multiple scalars from keyword arguments.
319
+ Examples:
320
+ storage.put_scalars(loss=my_loss, accuracy=my_accuracy, smoothing_hint=True)
321
+ """
322
+ for k, v in kwargs.items():
323
+ self.put_scalar(k, v, smoothing_hint=smoothing_hint)
324
+
325
+ def put_histogram(self, hist_name, hist_tensor, bins=1000):
326
+ """
327
+ Create a histogram from a tensor.
328
+ Args:
329
+ hist_name (str): The name of the histogram to put into tensorboard.
330
+ hist_tensor (torch.Tensor): A Tensor of arbitrary shape to be converted
331
+ into a histogram.
332
+ bins (int): Number of histogram bins.
333
+ """
334
+ ht_min, ht_max = hist_tensor.min().item(), hist_tensor.max().item()
335
+
336
+ # Create a histogram with PyTorch
337
+ hist_counts = torch.histc(hist_tensor, bins=bins)
338
+ hist_edges = torch.linspace(start=ht_min, end=ht_max, steps=bins + 1, dtype=torch.float32)
339
+
340
+ # Parameter for the add_histogram_raw function of SummaryWriter
341
+ hist_params = dict(
342
+ tag=hist_name,
343
+ min=ht_min,
344
+ max=ht_max,
345
+ num=len(hist_tensor),
346
+ sum=float(hist_tensor.sum()),
347
+ sum_squares=float(torch.sum(hist_tensor ** 2)),
348
+ bucket_limits=hist_edges[1:].tolist(),
349
+ bucket_counts=hist_counts.tolist(),
350
+ global_step=self._iter,
351
+ )
352
+ self._histograms.append(hist_params)
353
+
354
+ def history(self, name):
355
+ """
356
+ Returns:
357
+ HistoryBuffer: the scalar history for name
358
+ """
359
+ ret = self._history.get(name, None)
360
+ if ret is None:
361
+ raise KeyError("No history metric available for {}!".format(name))
362
+ return ret
363
+
364
+ def histories(self):
365
+ """
366
+ Returns:
367
+ dict[name -> HistoryBuffer]: the HistoryBuffer for all scalars
368
+ """
369
+ return self._history
370
+
371
+ def latest(self):
372
+ """
373
+ Returns:
374
+ dict[str -> (float, int)]: mapping from the name of each scalar to the most
375
+ recent value and the iteration number its added.
376
+ """
377
+ return self._latest_scalars
378
+
379
+ def latest_with_smoothing_hint(self, window_size=20):
380
+ """
381
+ Similar to :meth:`latest`, but the returned values
382
+ are either the un-smoothed original latest value,
383
+ or a median of the given window_size,
384
+ depend on whether the smoothing_hint is True.
385
+ This provides a default behavior that other writers can use.
386
+ """
387
+ result = {}
388
+ for k, (v, itr) in self._latest_scalars.items():
389
+ result[k] = (
390
+ self._history[k].median(window_size) if self._smoothing_hints[k] else v,
391
+ itr,
392
+ )
393
+ return result
394
+
395
+ def smoothing_hints(self):
396
+ """
397
+ Returns:
398
+ dict[name -> bool]: the user-provided hint on whether the scalar
399
+ is noisy and needs smoothing.
400
+ """
401
+ return self._smoothing_hints
402
+
403
+ def step(self):
404
+ """
405
+ User should either: (1) Call this function to increment storage.iter when needed. Or
406
+ (2) Set `storage.iter` to the correct iteration number before each iteration.
407
+ The storage will then be able to associate the new data with an iteration number.
408
+ """
409
+ self._iter += 1
410
+
411
+ @property
412
+ def iter(self):
413
+ """
414
+ Returns:
415
+ int: The current iteration number. When used together with a trainer,
416
+ this is ensured to be the same as trainer.iter.
417
+ """
418
+ return self._iter
419
+
420
+ @iter.setter
421
+ def iter(self, val):
422
+ self._iter = int(val)
423
+
424
+ @property
425
+ def iteration(self):
426
+ # for backward compatibility
427
+ return self._iter
428
+
429
+ def __enter__(self):
430
+ _CURRENT_STORAGE_STACK.append(self)
431
+ return self
432
+
433
+ def __exit__(self, exc_type, exc_val, exc_tb):
434
+ assert _CURRENT_STORAGE_STACK[-1] == self
435
+ _CURRENT_STORAGE_STACK.pop()
436
+
437
+ @contextmanager
438
+ def name_scope(self, name):
439
+ """
440
+ Yields:
441
+ A context within which all the events added to this storage
442
+ will be prefixed by the name scope.
443
+ """
444
+ old_prefix = self._current_prefix
445
+ self._current_prefix = name.rstrip("/") + "/"
446
+ yield
447
+ self._current_prefix = old_prefix
448
+
449
+ def clear_images(self):
450
+ """
451
+ Delete all the stored images for visualization. This should be called
452
+ after images are written to tensorboard.
453
+ """
454
+ self._vis_data = []
455
+
456
+ def clear_histograms(self):
457
+ """
458
+ Delete all the stored histograms for visualization.
459
+ This should be called after histograms are written to tensorboard.
460
+ """
461
+ self._histograms = []
@@ -0,0 +1,127 @@
1
+ # encoding: utf-8
2
+ # copy from: https://github.com/open-mmlab/OpenUnReID/blob/66bb2ae0b00575b80fbe8915f4d4f4739cc21206/openunreid/core/utils/faiss_utils.py
3
+
4
+ import faiss
5
+ import torch
6
+
7
+
8
+ def swig_ptr_from_FloatTensor(x):
9
+ assert x.is_contiguous()
10
+ assert x.dtype == torch.float32
11
+ return faiss.cast_integer_to_float_ptr(
12
+ x.storage().data_ptr() + x.storage_offset() * 4
13
+ )
14
+
15
+
16
+ def swig_ptr_from_LongTensor(x):
17
+ assert x.is_contiguous()
18
+ assert x.dtype == torch.int64, "dtype=%s" % x.dtype
19
+ return faiss.cast_integer_to_long_ptr(
20
+ x.storage().data_ptr() + x.storage_offset() * 8
21
+ )
22
+
23
+
24
+ def search_index_pytorch(index, x, k, D=None, I=None):
25
+ """call the search function of an index with pytorch tensor I/O (CPU
26
+ and GPU supported)"""
27
+ assert x.is_contiguous()
28
+ n, d = x.size()
29
+ assert d == index.d
30
+
31
+ if D is None:
32
+ D = torch.empty((n, k), dtype=torch.float32, device=x.device)
33
+ else:
34
+ assert D.size() == (n, k)
35
+
36
+ if I is None:
37
+ I = torch.empty((n, k), dtype=torch.int64, device=x.device)
38
+ else:
39
+ assert I.size() == (n, k)
40
+ torch.cuda.synchronize()
41
+ xptr = swig_ptr_from_FloatTensor(x)
42
+ Iptr = swig_ptr_from_LongTensor(I)
43
+ Dptr = swig_ptr_from_FloatTensor(D)
44
+ index.search_c(n, xptr, k, Dptr, Iptr)
45
+ torch.cuda.synchronize()
46
+ return D, I
47
+
48
+
49
+ def search_raw_array_pytorch(res, xb, xq, k, D=None, I=None, metric=faiss.METRIC_L2):
50
+ assert xb.device == xq.device
51
+
52
+ nq, d = xq.size()
53
+ if xq.is_contiguous():
54
+ xq_row_major = True
55
+ elif xq.t().is_contiguous():
56
+ xq = xq.t() # I initially wrote xq:t(), Lua is still haunting me :-)
57
+ xq_row_major = False
58
+ else:
59
+ raise TypeError("matrix should be row or column-major")
60
+
61
+ xq_ptr = swig_ptr_from_FloatTensor(xq)
62
+
63
+ nb, d2 = xb.size()
64
+ assert d2 == d
65
+ if xb.is_contiguous():
66
+ xb_row_major = True
67
+ elif xb.t().is_contiguous():
68
+ xb = xb.t()
69
+ xb_row_major = False
70
+ else:
71
+ raise TypeError("matrix should be row or column-major")
72
+ xb_ptr = swig_ptr_from_FloatTensor(xb)
73
+
74
+ if D is None:
75
+ D = torch.empty(nq, k, device=xb.device, dtype=torch.float32)
76
+ else:
77
+ assert D.shape == (nq, k)
78
+ assert D.device == xb.device
79
+
80
+ if I is None:
81
+ I = torch.empty(nq, k, device=xb.device, dtype=torch.int64)
82
+ else:
83
+ assert I.shape == (nq, k)
84
+ assert I.device == xb.device
85
+
86
+ D_ptr = swig_ptr_from_FloatTensor(D)
87
+ I_ptr = swig_ptr_from_LongTensor(I)
88
+
89
+ faiss.bruteForceKnn(
90
+ res,
91
+ metric,
92
+ xb_ptr,
93
+ xb_row_major,
94
+ nb,
95
+ xq_ptr,
96
+ xq_row_major,
97
+ nq,
98
+ d,
99
+ k,
100
+ D_ptr,
101
+ I_ptr,
102
+ )
103
+
104
+ return D, I
105
+
106
+
107
+ def index_init_gpu(ngpus, feat_dim):
108
+ flat_config = []
109
+ for i in range(ngpus):
110
+ cfg = faiss.GpuIndexFlatConfig()
111
+ cfg.useFloat16 = False
112
+ cfg.device = i
113
+ flat_config.append(cfg)
114
+
115
+ res = [faiss.StandardGpuResources() for i in range(ngpus)]
116
+ indexes = [
117
+ faiss.GpuIndexFlatL2(res[i], feat_dim, flat_config[i]) for i in range(ngpus)
118
+ ]
119
+ index = faiss.IndexShards(feat_dim)
120
+ for sub_index in indexes:
121
+ index.add_shard(sub_index)
122
+ index.reset()
123
+ return index
124
+
125
+
126
+ def index_init_cpu(feat_dim):
127
+ return faiss.IndexFlatL2(feat_dim)