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,203 @@
1
+ """
2
+ Author: Guan'an Wang
3
+ Contact: guan.wang0706@gmail.com
4
+ """
5
+
6
+ import torch
7
+ from torch import nn
8
+ from collections import OrderedDict
9
+ import logging
10
+ from fastreid.utils.checkpoint import get_missing_parameters_message, get_unexpected_parameters_message
11
+
12
+ from fastreid.layers import get_norm
13
+ from fastreid.modeling.backbones import BACKBONE_REGISTRY
14
+
15
+ logger = logging.getLogger(__name__)
16
+
17
+
18
+ class ShuffleV2Block(nn.Module):
19
+ """
20
+ Reference:
21
+ https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV2
22
+ """
23
+
24
+ def __init__(self, bn_norm, inp, oup, mid_channels, *, ksize, stride):
25
+ super(ShuffleV2Block, self).__init__()
26
+ self.stride = stride
27
+ assert stride in [1, 2]
28
+
29
+ self.mid_channels = mid_channels
30
+ self.ksize = ksize
31
+ pad = ksize // 2
32
+ self.pad = pad
33
+ self.inp = inp
34
+
35
+ outputs = oup - inp
36
+
37
+ branch_main = [
38
+ # pw
39
+ nn.Conv2d(inp, mid_channels, 1, 1, 0, bias=False),
40
+ get_norm(bn_norm, mid_channels),
41
+ nn.ReLU(inplace=True),
42
+ # dw
43
+ nn.Conv2d(mid_channels, mid_channels, ksize, stride, pad, groups=mid_channels, bias=False),
44
+ get_norm(bn_norm, mid_channels),
45
+ # pw-linear
46
+ nn.Conv2d(mid_channels, outputs, 1, 1, 0, bias=False),
47
+ get_norm(bn_norm, outputs),
48
+ nn.ReLU(inplace=True),
49
+ ]
50
+ self.branch_main = nn.Sequential(*branch_main)
51
+
52
+ if stride == 2:
53
+ branch_proj = [
54
+ # dw
55
+ nn.Conv2d(inp, inp, ksize, stride, pad, groups=inp, bias=False),
56
+ get_norm(bn_norm, inp),
57
+ # pw-linear
58
+ nn.Conv2d(inp, inp, 1, 1, 0, bias=False),
59
+ get_norm(bn_norm, inp),
60
+ nn.ReLU(inplace=True),
61
+ ]
62
+ self.branch_proj = nn.Sequential(*branch_proj)
63
+ else:
64
+ self.branch_proj = None
65
+
66
+ def forward(self, old_x):
67
+ if self.stride == 1:
68
+ x_proj, x = self.channel_shuffle(old_x)
69
+ return torch.cat((x_proj, self.branch_main(x)), 1)
70
+ elif self.stride == 2:
71
+ x_proj = old_x
72
+ x = old_x
73
+ return torch.cat((self.branch_proj(x_proj), self.branch_main(x)), 1)
74
+
75
+ def channel_shuffle(self, x):
76
+ batchsize, num_channels, height, width = x.data.size()
77
+ assert (num_channels % 4 == 0)
78
+ x = x.reshape(batchsize * num_channels // 2, 2, height * width)
79
+ x = x.permute(1, 0, 2)
80
+ x = x.reshape(2, -1, num_channels // 2, height, width)
81
+ return x[0], x[1]
82
+
83
+
84
+ class ShuffleNetV2(nn.Module):
85
+ """
86
+ Reference:
87
+ https://github.com/megvii-model/ShuffleNet-Series/tree/master/ShuffleNetV2
88
+ """
89
+
90
+ def __init__(self, bn_norm, model_size='1.5x'):
91
+ super(ShuffleNetV2, self).__init__()
92
+
93
+ self.stage_repeats = [4, 8, 4]
94
+ self.model_size = model_size
95
+ if model_size == '0.5x':
96
+ self.stage_out_channels = [-1, 24, 48, 96, 192, 1024]
97
+ elif model_size == '1.0x':
98
+ self.stage_out_channels = [-1, 24, 116, 232, 464, 1024]
99
+ elif model_size == '1.5x':
100
+ self.stage_out_channels = [-1, 24, 176, 352, 704, 1024]
101
+ elif model_size == '2.0x':
102
+ self.stage_out_channels = [-1, 24, 244, 488, 976, 2048]
103
+ else:
104
+ raise NotImplementedError
105
+
106
+ # building first layer
107
+ input_channel = self.stage_out_channels[1]
108
+ self.first_conv = nn.Sequential(
109
+ nn.Conv2d(3, input_channel, 3, 2, 1, bias=False),
110
+ get_norm(bn_norm, input_channel),
111
+ nn.ReLU(inplace=True),
112
+ )
113
+
114
+ self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
115
+
116
+ self.features = []
117
+ for idxstage in range(len(self.stage_repeats)):
118
+ numrepeat = self.stage_repeats[idxstage]
119
+ output_channel = self.stage_out_channels[idxstage + 2]
120
+
121
+ for i in range(numrepeat):
122
+ if i == 0:
123
+ self.features.append(ShuffleV2Block(bn_norm, input_channel, output_channel,
124
+ mid_channels=output_channel // 2, ksize=3, stride=2))
125
+ else:
126
+ self.features.append(ShuffleV2Block(bn_norm, input_channel // 2, output_channel,
127
+ mid_channels=output_channel // 2, ksize=3, stride=1))
128
+
129
+ input_channel = output_channel
130
+
131
+ self.features = nn.Sequential(*self.features)
132
+
133
+ self.conv_last = nn.Sequential(
134
+ nn.Conv2d(input_channel, self.stage_out_channels[-1], 1, 1, 0, bias=False),
135
+ get_norm(bn_norm, self.stage_out_channels[-1]),
136
+ nn.ReLU(inplace=True)
137
+ )
138
+
139
+ self._initialize_weights()
140
+
141
+ def forward(self, x):
142
+ x = self.first_conv(x)
143
+ x = self.maxpool(x)
144
+ x = self.features(x)
145
+ x = self.conv_last(x)
146
+
147
+ return x
148
+
149
+ def _initialize_weights(self):
150
+ for name, m in self.named_modules():
151
+ if isinstance(m, nn.Conv2d):
152
+ if 'first' in name:
153
+ nn.init.normal_(m.weight, 0, 0.01)
154
+ else:
155
+ nn.init.normal_(m.weight, 0, 1.0 / m.weight.shape[1])
156
+ if m.bias is not None:
157
+ nn.init.constant_(m.bias, 0)
158
+ elif isinstance(m, nn.BatchNorm2d):
159
+ nn.init.constant_(m.weight, 1)
160
+ if m.bias is not None:
161
+ nn.init.constant_(m.bias, 0.0001)
162
+ nn.init.constant_(m.running_mean, 0)
163
+ elif isinstance(m, nn.BatchNorm1d):
164
+ nn.init.constant_(m.weight, 1)
165
+ if m.bias is not None:
166
+ nn.init.constant_(m.bias, 0.0001)
167
+ nn.init.constant_(m.running_mean, 0)
168
+ elif isinstance(m, nn.Linear):
169
+ nn.init.normal_(m.weight, 0, 0.01)
170
+ if m.bias is not None:
171
+ nn.init.constant_(m.bias, 0)
172
+
173
+
174
+ @BACKBONE_REGISTRY.register()
175
+ def build_shufflenetv2_backbone(cfg):
176
+ # fmt: off
177
+ pretrain = cfg.MODEL.BACKBONE.PRETRAIN
178
+ pretrain_path = cfg.MODEL.BACKBONE.PRETRAIN_PATH
179
+ bn_norm = cfg.MODEL.BACKBONE.NORM
180
+ model_size = cfg.MODEL.BACKBONE.DEPTH
181
+ # fmt: on
182
+
183
+ model = ShuffleNetV2(bn_norm, model_size=model_size)
184
+
185
+ if pretrain:
186
+ new_state_dict = OrderedDict()
187
+ state_dict = torch.load(pretrain_path)["state_dict"]
188
+ for k, v in state_dict.items():
189
+ if k[:7] == 'module.':
190
+ k = k[7:]
191
+ new_state_dict[k] = v
192
+
193
+ incompatible = model.load_state_dict(new_state_dict, strict=False)
194
+ if incompatible.missing_keys:
195
+ logger.info(
196
+ get_missing_parameters_message(incompatible.missing_keys)
197
+ )
198
+ if incompatible.unexpected_keys:
199
+ logger.info(
200
+ get_unexpected_parameters_message(incompatible.unexpected_keys)
201
+ )
202
+
203
+ return model
@@ -0,0 +1,399 @@
1
+ """ Vision Transformer (ViT) in PyTorch
2
+ A PyTorch implement of Vision Transformers as described in
3
+ 'An Image Is Worth 16 x 16 Words: Transformers for Image Recognition at Scale' - https://arxiv.org/abs/2010.11929
4
+ The official jax code is released and available at https://github.com/google-research/vision_transformer
5
+ Status/TODO:
6
+ * Models updated to be compatible with official impl. Args added to support backward compat for old PyTorch weights.
7
+ * Weights ported from official jax impl for 384x384 base and small models, 16x16 and 32x32 patches.
8
+ * Trained (supervised on ImageNet-1k) my custom 'small' patch model to 77.9, 'base' to 79.4 top-1 with this code.
9
+ * Hopefully find time and GPUs for SSL or unsupervised pretraining on OpenImages w/ ImageNet fine-tune in future.
10
+ Acknowledgments:
11
+ * The paper authors for releasing code and weights, thanks!
12
+ * I fixed my class token impl based on Phil Wang's https://github.com/lucidrains/vit-pytorch ... check it out
13
+ for some einops/einsum fun
14
+ * Simple transformer style inspired by Andrej Karpathy's https://github.com/karpathy/minGPT
15
+ * Bert reference code checks against Huggingface Transformers and Tensorflow Bert
16
+ Hacked together by / Copyright 2020 Ross Wightman
17
+ """
18
+
19
+ import logging
20
+ import math
21
+ from functools import partial
22
+
23
+ import torch
24
+ import torch.nn as nn
25
+ import torch.nn.functional as F
26
+
27
+ from fastreid.layers import DropPath, trunc_normal_, to_2tuple
28
+ from fastreid.utils.checkpoint import get_missing_parameters_message, get_unexpected_parameters_message
29
+ from .build import BACKBONE_REGISTRY
30
+
31
+ logger = logging.getLogger(__name__)
32
+
33
+
34
+ class Mlp(nn.Module):
35
+ def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.):
36
+ super().__init__()
37
+ out_features = out_features or in_features
38
+ hidden_features = hidden_features or in_features
39
+ self.fc1 = nn.Linear(in_features, hidden_features)
40
+ self.act = act_layer()
41
+ self.fc2 = nn.Linear(hidden_features, out_features)
42
+ self.drop = nn.Dropout(drop)
43
+
44
+ def forward(self, x):
45
+ x = self.fc1(x)
46
+ x = self.act(x)
47
+ x = self.drop(x)
48
+ x = self.fc2(x)
49
+ x = self.drop(x)
50
+ return x
51
+
52
+
53
+ class Attention(nn.Module):
54
+ def __init__(self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0., proj_drop=0.):
55
+ super().__init__()
56
+ self.num_heads = num_heads
57
+ head_dim = dim // num_heads
58
+ # NOTE scale factor was wrong in my original version, can set manually to be compat with prev weights
59
+ self.scale = qk_scale or head_dim ** -0.5
60
+
61
+ self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
62
+ self.attn_drop = nn.Dropout(attn_drop)
63
+ self.proj = nn.Linear(dim, dim)
64
+ self.proj_drop = nn.Dropout(proj_drop)
65
+
66
+ def forward(self, x):
67
+ B, N, C = x.shape
68
+ qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4)
69
+ q, k, v = qkv[0], qkv[1], qkv[2] # make torchscript happy (cannot use tensor as tuple)
70
+
71
+ attn = (q @ k.transpose(-2, -1)) * self.scale
72
+ attn = attn.softmax(dim=-1)
73
+ attn = self.attn_drop(attn)
74
+
75
+ x = (attn @ v).transpose(1, 2).reshape(B, N, C)
76
+ x = self.proj(x)
77
+ x = self.proj_drop(x)
78
+ return x
79
+
80
+
81
+ class Block(nn.Module):
82
+
83
+ def __init__(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_scale=None, drop=0., attn_drop=0.,
84
+ drop_path=0., act_layer=nn.GELU, norm_layer=nn.LayerNorm):
85
+ super().__init__()
86
+ self.norm1 = norm_layer(dim)
87
+ self.attn = Attention(
88
+ dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop)
89
+ # NOTE: drop path for stochastic depth, we shall see if this is better than dropout here
90
+ self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity()
91
+ self.norm2 = norm_layer(dim)
92
+ mlp_hidden_dim = int(dim * mlp_ratio)
93
+ self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop)
94
+
95
+ def forward(self, x):
96
+ x = x + self.drop_path(self.attn(self.norm1(x)))
97
+ x = x + self.drop_path(self.mlp(self.norm2(x)))
98
+ return x
99
+
100
+
101
+ class PatchEmbed(nn.Module):
102
+ """ Image to Patch Embedding
103
+ """
104
+
105
+ def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768):
106
+ super().__init__()
107
+ img_size = to_2tuple(img_size)
108
+ patch_size = to_2tuple(patch_size)
109
+ num_patches = (img_size[1] // patch_size[1]) * (img_size[0] // patch_size[0])
110
+ self.img_size = img_size
111
+ self.patch_size = patch_size
112
+ self.num_patches = num_patches
113
+
114
+ self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)
115
+
116
+ def forward(self, x):
117
+ B, C, H, W = x.shape
118
+ # FIXME look at relaxing size constraints
119
+ assert H == self.img_size[0] and W == self.img_size[1], \
120
+ f"Input image size ({H}*{W}) doesn't match model ({self.img_size[0]}*{self.img_size[1]})."
121
+ x = self.proj(x).flatten(2).transpose(1, 2)
122
+ return x
123
+
124
+
125
+ class HybridEmbed(nn.Module):
126
+ """ CNN Feature Map Embedding
127
+ Extract feature map from CNN, flatten, project to embedding dim.
128
+ """
129
+
130
+ def __init__(self, backbone, img_size=224, feature_size=None, in_chans=3, embed_dim=768):
131
+ super().__init__()
132
+ assert isinstance(backbone, nn.Module)
133
+ img_size = to_2tuple(img_size)
134
+ self.img_size = img_size
135
+ self.backbone = backbone
136
+ if feature_size is None:
137
+ with torch.no_grad():
138
+ # FIXME this is hacky, but most reliable way of determining the exact dim of the output feature
139
+ # map for all networks, the feature metadata has reliable channel and stride info, but using
140
+ # stride to calc feature dim requires info about padding of each stage that isn't captured.
141
+ training = backbone.training
142
+ if training:
143
+ backbone.eval()
144
+ o = self.backbone(torch.zeros(1, in_chans, img_size[0], img_size[1]))
145
+ if isinstance(o, (list, tuple)):
146
+ o = o[-1] # last feature if backbone outputs list/tuple of features
147
+ feature_size = o.shape[-2:]
148
+ feature_dim = o.shape[1]
149
+ backbone.train(training)
150
+ else:
151
+ feature_size = to_2tuple(feature_size)
152
+ if hasattr(self.backbone, 'feature_info'):
153
+ feature_dim = self.backbone.feature_info.channels()[-1]
154
+ else:
155
+ feature_dim = self.backbone.num_features
156
+ self.num_patches = feature_size[0] * feature_size[1]
157
+ self.proj = nn.Conv2d(feature_dim, embed_dim, 1)
158
+
159
+ def forward(self, x):
160
+ x = self.backbone(x)
161
+ if isinstance(x, (list, tuple)):
162
+ x = x[-1] # last feature if backbone outputs list/tuple of features
163
+ x = self.proj(x).flatten(2).transpose(1, 2)
164
+ return x
165
+
166
+
167
+ class PatchEmbed_overlap(nn.Module):
168
+ """ Image to Patch Embedding with overlapping patches
169
+ """
170
+
171
+ def __init__(self, img_size=224, patch_size=16, stride_size=20, in_chans=3, embed_dim=768):
172
+ super().__init__()
173
+ img_size = to_2tuple(img_size)
174
+ patch_size = to_2tuple(patch_size)
175
+ stride_size_tuple = to_2tuple(stride_size)
176
+ self.num_x = (img_size[1] - patch_size[1]) // stride_size_tuple[1] + 1
177
+ self.num_y = (img_size[0] - patch_size[0]) // stride_size_tuple[0] + 1
178
+ num_patches = self.num_x * self.num_y
179
+ self.img_size = img_size
180
+ self.patch_size = patch_size
181
+ self.num_patches = num_patches
182
+
183
+ self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=stride_size)
184
+ for m in self.modules():
185
+ if isinstance(m, nn.Conv2d):
186
+ n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
187
+ m.weight.data.normal_(0, math.sqrt(2. / n))
188
+ elif isinstance(m, nn.BatchNorm2d):
189
+ m.weight.data.fill_(1)
190
+ m.bias.data.zero_()
191
+ elif isinstance(m, nn.InstanceNorm2d):
192
+ m.weight.data.fill_(1)
193
+ m.bias.data.zero_()
194
+
195
+ def forward(self, x):
196
+ B, C, H, W = x.shape
197
+
198
+ # FIXME look at relaxing size constraints
199
+ assert H == self.img_size[0] and W == self.img_size[1], \
200
+ f"Input image size ({H}*{W}) doesn't match model ({self.img_size[0]}*{self.img_size[1]})."
201
+ x = self.proj(x)
202
+
203
+ x = x.flatten(2).transpose(1, 2) # [64, 8, 768]
204
+ return x
205
+
206
+
207
+ class VisionTransformer(nn.Module):
208
+ """ Vision Transformer
209
+ A PyTorch impl of : `An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale`
210
+ - https://arxiv.org/abs/2010.11929
211
+ Includes distillation token & head support for `DeiT: Data-efficient Image Transformers`
212
+ - https://arxiv.org/abs/2012.12877
213
+ """
214
+
215
+ def __init__(self, img_size=224, patch_size=16, stride_size=16, in_chans=3, embed_dim=768,
216
+ depth=12, num_heads=12, mlp_ratio=4., qkv_bias=False, qk_scale=None,
217
+ drop_rate=0., attn_drop_rate=0., camera=0, drop_path_rate=0., hybrid_backbone=None,
218
+ norm_layer=partial(nn.LayerNorm, eps=1e-6), sie_xishu=1.0):
219
+ super().__init__()
220
+ self.num_features = self.embed_dim = embed_dim # num_features for consistency with other models
221
+ if hybrid_backbone is not None:
222
+ self.patch_embed = HybridEmbed(
223
+ hybrid_backbone, img_size=img_size, in_chans=in_chans, embed_dim=embed_dim)
224
+ else:
225
+ self.patch_embed = PatchEmbed_overlap(
226
+ img_size=img_size, patch_size=patch_size, stride_size=stride_size, in_chans=in_chans,
227
+ embed_dim=embed_dim)
228
+
229
+ num_patches = self.patch_embed.num_patches
230
+
231
+ self.cls_token = nn.Parameter(torch.zeros(1, 1, embed_dim))
232
+ self.pos_embed = nn.Parameter(torch.zeros(1, num_patches + 1, embed_dim))
233
+ self.cam_num = camera
234
+ self.sie_xishu = sie_xishu
235
+ # Initialize SIE Embedding
236
+ if camera > 1:
237
+ self.sie_embed = nn.Parameter(torch.zeros(camera, 1, embed_dim))
238
+ trunc_normal_(self.sie_embed, std=.02)
239
+
240
+ self.pos_drop = nn.Dropout(p=drop_rate)
241
+ dpr = [x.item() for x in torch.linspace(0, drop_path_rate, depth)] # stochastic depth decay rule
242
+
243
+ self.blocks = nn.ModuleList([
244
+ Block(
245
+ dim=embed_dim, num_heads=num_heads, mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, qk_scale=qk_scale,
246
+ drop=drop_rate, attn_drop=attn_drop_rate, drop_path=dpr[i], norm_layer=norm_layer)
247
+ for i in range(depth)])
248
+
249
+ self.norm = norm_layer(embed_dim)
250
+
251
+ trunc_normal_(self.cls_token, std=.02)
252
+ trunc_normal_(self.pos_embed, std=.02)
253
+
254
+ self.apply(self._init_weights)
255
+
256
+ def _init_weights(self, m):
257
+ if isinstance(m, nn.Linear):
258
+ trunc_normal_(m.weight, std=.02)
259
+ if isinstance(m, nn.Linear) and m.bias is not None:
260
+ nn.init.constant_(m.bias, 0)
261
+ elif isinstance(m, nn.LayerNorm):
262
+ nn.init.constant_(m.bias, 0)
263
+ nn.init.constant_(m.weight, 1.0)
264
+
265
+ @torch.jit.ignore
266
+ def no_weight_decay(self):
267
+ return {'pos_embed', 'cls_token'}
268
+
269
+ def forward(self, x, camera_id=None):
270
+ B = x.shape[0]
271
+ x = self.patch_embed(x)
272
+
273
+ cls_tokens = self.cls_token.expand(B, -1, -1) # stole cls_tokens impl from Phil Wang, thanks
274
+ x = torch.cat((cls_tokens, x), dim=1)
275
+
276
+ if self.cam_num > 0:
277
+ x = x + self.pos_embed + self.sie_xishu * self.sie_embed[camera_id]
278
+ else:
279
+ x = x + self.pos_embed
280
+
281
+ x = self.pos_drop(x)
282
+
283
+ for blk in self.blocks:
284
+ x = blk(x)
285
+
286
+ x = self.norm(x)
287
+
288
+ return x[:, 0].reshape(x.shape[0], -1, 1, 1)
289
+
290
+
291
+ def resize_pos_embed(posemb, posemb_new, hight, width):
292
+ # Rescale the grid of position embeddings when loading from state_dict. Adapted from
293
+ # https://github.com/google-research/vision_transformer/blob/00883dd691c63a6830751563748663526e811cee/vit_jax/checkpoint.py#L224
294
+ ntok_new = posemb_new.shape[1]
295
+
296
+ posemb_token, posemb_grid = posemb[:, :1], posemb[0, 1:]
297
+ ntok_new -= 1
298
+
299
+ gs_old = int(math.sqrt(len(posemb_grid)))
300
+ logger.info('Resized position embedding from size:{} to size: {} with height:{} width: {}'.format(posemb.shape,
301
+ posemb_new.shape,
302
+ hight,
303
+ width))
304
+ posemb_grid = posemb_grid.reshape(1, gs_old, gs_old, -1).permute(0, 3, 1, 2)
305
+ posemb_grid = F.interpolate(posemb_grid, size=(hight, width), mode='bilinear')
306
+ posemb_grid = posemb_grid.permute(0, 2, 3, 1).reshape(1, hight * width, -1)
307
+ posemb = torch.cat([posemb_token, posemb_grid], dim=1)
308
+ return posemb
309
+
310
+
311
+ @BACKBONE_REGISTRY.register()
312
+ def build_vit_backbone(cfg):
313
+ """
314
+ Create a Vision Transformer instance from config.
315
+ Returns:
316
+ SwinTransformer: a :class:`SwinTransformer` instance.
317
+ """
318
+ # fmt: off
319
+ input_size = cfg.INPUT.SIZE_TRAIN
320
+ pretrain = cfg.MODEL.BACKBONE.PRETRAIN
321
+ pretrain_path = cfg.MODEL.BACKBONE.PRETRAIN_PATH
322
+ depth = cfg.MODEL.BACKBONE.DEPTH
323
+ sie_xishu = cfg.MODEL.BACKBONE.SIE_COE
324
+ stride_size = cfg.MODEL.BACKBONE.STRIDE_SIZE
325
+ drop_ratio = cfg.MODEL.BACKBONE.DROP_RATIO
326
+ drop_path_ratio = cfg.MODEL.BACKBONE.DROP_PATH_RATIO
327
+ attn_drop_rate = cfg.MODEL.BACKBONE.ATT_DROP_RATE
328
+ # fmt: on
329
+
330
+ num_depth = {
331
+ 'small': 8,
332
+ 'base': 12,
333
+ }[depth]
334
+
335
+ num_heads = {
336
+ 'small': 8,
337
+ 'base': 12,
338
+ }[depth]
339
+
340
+ mlp_ratio = {
341
+ 'small': 3.,
342
+ 'base': 4.
343
+ }[depth]
344
+
345
+ qkv_bias = {
346
+ 'small': False,
347
+ 'base': True
348
+ }[depth]
349
+
350
+ qk_scale = {
351
+ 'small': 768 ** -0.5,
352
+ 'base': None,
353
+ }[depth]
354
+
355
+ model = VisionTransformer(img_size=input_size, sie_xishu=sie_xishu, stride_size=stride_size, depth=num_depth,
356
+ num_heads=num_heads, mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, qk_scale=qk_scale,
357
+ drop_path_rate=drop_path_ratio, drop_rate=drop_ratio, attn_drop_rate=attn_drop_rate)
358
+
359
+ if pretrain:
360
+ try:
361
+ state_dict = torch.load(pretrain_path, map_location=torch.device('cpu'))
362
+ logger.info(f"Loading pretrained model from {pretrain_path}")
363
+
364
+ if 'model' in state_dict:
365
+ state_dict = state_dict.pop('model')
366
+ if 'state_dict' in state_dict:
367
+ state_dict = state_dict.pop('state_dict')
368
+ for k, v in state_dict.items():
369
+ if 'head' in k or 'dist' in k:
370
+ continue
371
+ if 'patch_embed.proj.weight' in k and len(v.shape) < 4:
372
+ # For old models that I trained prior to conv based patchification
373
+ O, I, H, W = model.patch_embed.proj.weight.shape
374
+ v = v.reshape(O, -1, H, W)
375
+ elif k == 'pos_embed' and v.shape != model.pos_embed.shape:
376
+ # To resize pos embedding when using model at different size from pretrained weights
377
+ if 'distilled' in pretrain_path:
378
+ logger.info("distill need to choose right cls token in the pth.")
379
+ v = torch.cat([v[:, 0:1], v[:, 2:]], dim=1)
380
+ v = resize_pos_embed(v, model.pos_embed.data, model.patch_embed.num_y, model.patch_embed.num_x)
381
+ state_dict[k] = v
382
+ except FileNotFoundError as e:
383
+ logger.info(f'{pretrain_path} is not found! Please check this path.')
384
+ raise e
385
+ except KeyError as e:
386
+ logger.info("State dict keys error! Please check the state dict.")
387
+ raise e
388
+
389
+ incompatible = model.load_state_dict(state_dict, strict=False)
390
+ if incompatible.missing_keys:
391
+ logger.info(
392
+ get_missing_parameters_message(incompatible.missing_keys)
393
+ )
394
+ if incompatible.unexpected_keys:
395
+ logger.info(
396
+ get_unexpected_parameters_message(incompatible.unexpected_keys)
397
+ )
398
+
399
+ return model
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ """
3
+ @author: liaoxingyu
4
+ @contact: sherlockliao01@gmail.com
5
+ """
6
+
7
+ from .build import REID_HEADS_REGISTRY, build_heads
8
+
9
+ # import all the meta_arch, so they will be registered
10
+ from .embedding_head import EmbeddingHead
11
+ from .clas_head import ClasHead
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ """
3
+ @author: liaoxingyu
4
+ @contact: sherlockliao01@gmail.com
5
+ """
6
+
7
+ from ...utils.registry import Registry
8
+
9
+ REID_HEADS_REGISTRY = Registry("HEADS")
10
+ REID_HEADS_REGISTRY.__doc__ = """
11
+ Registry for reid heads in a baseline model.
12
+
13
+ ROIHeads take feature maps and region proposals, and
14
+ perform per-region computation.
15
+ The registered object will be called with `obj(cfg, input_shape)`.
16
+ The call is expected to return an :class:`ROIHeads`.
17
+ """
18
+
19
+
20
+ def build_heads(cfg):
21
+ """
22
+ Build REIDHeads defined by `cfg.MODEL.REID_HEADS.NAME`.
23
+ """
24
+ head = cfg.MODEL.HEADS.NAME
25
+ return REID_HEADS_REGISTRY.get(head)(cfg)
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ """
3
+ @author: xingyu liao
4
+ @contact: sherlockliao01@gmail.com
5
+ """
6
+
7
+ import torch.nn.functional as F
8
+
9
+ from fastreid.modeling.heads import REID_HEADS_REGISTRY, EmbeddingHead
10
+
11
+
12
+ @REID_HEADS_REGISTRY.register()
13
+ class ClasHead(EmbeddingHead):
14
+ def forward(self, features, targets=None):
15
+ """
16
+ See :class:`ClsHeads.forward`.
17
+ """
18
+ pool_feat = self.pool_layer(features)
19
+ neck_feat = self.bottleneck(pool_feat)
20
+ neck_feat = neck_feat.view(neck_feat.size(0), -1)
21
+
22
+ if self.cls_layer.__class__.__name__ == 'Linear':
23
+ logits = F.linear(neck_feat, self.weight)
24
+ else:
25
+ logits = F.linear(F.normalize(neck_feat), F.normalize(self.weight))
26
+
27
+ # Evaluation
28
+ if not self.training: return logits.mul_(self.cls_layer.s)
29
+
30
+ cls_outputs = self.cls_layer(logits.clone(), targets)
31
+
32
+ return {
33
+ "cls_outputs": cls_outputs,
34
+ "pred_class_logits": logits.mul_(self.cls_layer.s),
35
+ "features": neck_feat,
36
+ }