dnt 0.2.4__py3-none-any.whl → 0.3.1.3__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 (305) hide show
  1. dnt/__init__.py +3 -2
  2. dnt/analysis/__init__.py +3 -2
  3. dnt/analysis/interaction.py +503 -0
  4. dnt/analysis/stop.py +22 -17
  5. dnt/analysis/stop2.py +289 -0
  6. dnt/analysis/stop3.py +754 -0
  7. dnt/detect/signal/detector.py +317 -0
  8. dnt/detect/yolov8/detector.py +116 -16
  9. dnt/engine/__init__.py +8 -0
  10. dnt/engine/bbox_interp.py +83 -0
  11. dnt/engine/bbox_iou.py +20 -0
  12. dnt/engine/cluster.py +31 -0
  13. dnt/engine/iob.py +66 -0
  14. dnt/filter/filter.py +321 -1
  15. dnt/label/labeler.py +4 -4
  16. dnt/label/labeler2.py +502 -0
  17. dnt/shared/__init__.py +2 -1
  18. dnt/shared/data/coco.names +0 -0
  19. dnt/shared/data/openimages.names +0 -0
  20. dnt/shared/data/voc.names +0 -0
  21. dnt/shared/download.py +12 -0
  22. dnt/shared/synhcro.py +150 -0
  23. dnt/shared/util.py +17 -4
  24. dnt/third_party/fast-reid/__init__.py +1 -0
  25. dnt/third_party/fast-reid/configs/Base-AGW.yml +19 -0
  26. dnt/third_party/fast-reid/configs/Base-MGN.yml +12 -0
  27. dnt/third_party/fast-reid/configs/Base-SBS.yml +63 -0
  28. dnt/third_party/fast-reid/configs/Base-bagtricks.yml +76 -0
  29. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R101-ibn.yml +12 -0
  30. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50-ibn.yml +11 -0
  31. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50.yml +7 -0
  32. dnt/third_party/fast-reid/configs/DukeMTMC/AGW_S50.yml +11 -0
  33. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R101-ibn.yml +12 -0
  34. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50-ibn.yml +11 -0
  35. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50.yml +7 -0
  36. dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_S50.yml +11 -0
  37. dnt/third_party/fast-reid/configs/DukeMTMC/mgn_R50-ibn.yml +11 -0
  38. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R101-ibn.yml +12 -0
  39. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50-ibn.yml +11 -0
  40. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50.yml +7 -0
  41. dnt/third_party/fast-reid/configs/DukeMTMC/sbs_S50.yml +11 -0
  42. dnt/third_party/fast-reid/configs/MOT17/AGW_R101-ibn.yml +12 -0
  43. dnt/third_party/fast-reid/configs/MOT17/AGW_R50-ibn.yml +11 -0
  44. dnt/third_party/fast-reid/configs/MOT17/AGW_R50.yml +7 -0
  45. dnt/third_party/fast-reid/configs/MOT17/AGW_S50.yml +11 -0
  46. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R101-ibn.yml +12 -0
  47. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50-ibn.yml +11 -0
  48. dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50.yml +7 -0
  49. dnt/third_party/fast-reid/configs/MOT17/bagtricks_S50.yml +11 -0
  50. dnt/third_party/fast-reid/configs/MOT17/mgn_R50-ibn.yml +11 -0
  51. dnt/third_party/fast-reid/configs/MOT17/sbs_R101-ibn.yml +12 -0
  52. dnt/third_party/fast-reid/configs/MOT17/sbs_R50-ibn.yml +11 -0
  53. dnt/third_party/fast-reid/configs/MOT17/sbs_R50.yml +7 -0
  54. dnt/third_party/fast-reid/configs/MOT17/sbs_S50.yml +11 -0
  55. dnt/third_party/fast-reid/configs/MOT20/AGW_R101-ibn.yml +12 -0
  56. dnt/third_party/fast-reid/configs/MOT20/AGW_R50-ibn.yml +11 -0
  57. dnt/third_party/fast-reid/configs/MOT20/AGW_R50.yml +7 -0
  58. dnt/third_party/fast-reid/configs/MOT20/AGW_S50.yml +11 -0
  59. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R101-ibn.yml +12 -0
  60. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50-ibn.yml +11 -0
  61. dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50.yml +7 -0
  62. dnt/third_party/fast-reid/configs/MOT20/bagtricks_S50.yml +11 -0
  63. dnt/third_party/fast-reid/configs/MOT20/mgn_R50-ibn.yml +11 -0
  64. dnt/third_party/fast-reid/configs/MOT20/sbs_R101-ibn.yml +12 -0
  65. dnt/third_party/fast-reid/configs/MOT20/sbs_R50-ibn.yml +11 -0
  66. dnt/third_party/fast-reid/configs/MOT20/sbs_R50.yml +7 -0
  67. dnt/third_party/fast-reid/configs/MOT20/sbs_S50.yml +11 -0
  68. dnt/third_party/fast-reid/configs/MSMT17/AGW_R101-ibn.yml +12 -0
  69. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50-ibn.yml +11 -0
  70. dnt/third_party/fast-reid/configs/MSMT17/AGW_R50.yml +7 -0
  71. dnt/third_party/fast-reid/configs/MSMT17/AGW_S50.yml +11 -0
  72. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R101-ibn.yml +13 -0
  73. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50-ibn.yml +12 -0
  74. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50.yml +7 -0
  75. dnt/third_party/fast-reid/configs/MSMT17/bagtricks_S50.yml +12 -0
  76. dnt/third_party/fast-reid/configs/MSMT17/mgn_R50-ibn.yml +11 -0
  77. dnt/third_party/fast-reid/configs/MSMT17/sbs_R101-ibn.yml +12 -0
  78. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50-ibn.yml +11 -0
  79. dnt/third_party/fast-reid/configs/MSMT17/sbs_R50.yml +7 -0
  80. dnt/third_party/fast-reid/configs/MSMT17/sbs_S50.yml +11 -0
  81. dnt/third_party/fast-reid/configs/Market1501/AGW_R101-ibn.yml +12 -0
  82. dnt/third_party/fast-reid/configs/Market1501/AGW_R50-ibn.yml +11 -0
  83. dnt/third_party/fast-reid/configs/Market1501/AGW_R50.yml +7 -0
  84. dnt/third_party/fast-reid/configs/Market1501/AGW_S50.yml +11 -0
  85. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R101-ibn.yml +12 -0
  86. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50-ibn.yml +11 -0
  87. dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50.yml +7 -0
  88. dnt/third_party/fast-reid/configs/Market1501/bagtricks_S50.yml +11 -0
  89. dnt/third_party/fast-reid/configs/Market1501/bagtricks_vit.yml +88 -0
  90. dnt/third_party/fast-reid/configs/Market1501/mgn_R50-ibn.yml +11 -0
  91. dnt/third_party/fast-reid/configs/Market1501/sbs_R101-ibn.yml +12 -0
  92. dnt/third_party/fast-reid/configs/Market1501/sbs_R50-ibn.yml +11 -0
  93. dnt/third_party/fast-reid/configs/Market1501/sbs_R50.yml +7 -0
  94. dnt/third_party/fast-reid/configs/Market1501/sbs_S50.yml +11 -0
  95. dnt/third_party/fast-reid/configs/VERIWild/bagtricks_R50-ibn.yml +35 -0
  96. dnt/third_party/fast-reid/configs/VeRi/sbs_R50-ibn.yml +35 -0
  97. dnt/third_party/fast-reid/configs/VehicleID/bagtricks_R50-ibn.yml +36 -0
  98. dnt/third_party/fast-reid/configs/__init__.py +0 -0
  99. dnt/third_party/fast-reid/fast_reid_interfece.py +175 -0
  100. dnt/third_party/fast-reid/fastreid/__init__.py +6 -0
  101. dnt/third_party/fast-reid/fastreid/config/__init__.py +15 -0
  102. dnt/third_party/fast-reid/fastreid/config/config.py +319 -0
  103. dnt/third_party/fast-reid/fastreid/config/defaults.py +329 -0
  104. dnt/third_party/fast-reid/fastreid/data/__init__.py +17 -0
  105. dnt/third_party/fast-reid/fastreid/data/build.py +194 -0
  106. dnt/third_party/fast-reid/fastreid/data/common.py +58 -0
  107. dnt/third_party/fast-reid/fastreid/data/data_utils.py +202 -0
  108. dnt/third_party/fast-reid/fastreid/data/datasets/AirportALERT.py +50 -0
  109. dnt/third_party/fast-reid/fastreid/data/datasets/__init__.py +43 -0
  110. dnt/third_party/fast-reid/fastreid/data/datasets/bases.py +183 -0
  111. dnt/third_party/fast-reid/fastreid/data/datasets/caviara.py +44 -0
  112. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk03.py +274 -0
  113. dnt/third_party/fast-reid/fastreid/data/datasets/cuhk_sysu.py +58 -0
  114. dnt/third_party/fast-reid/fastreid/data/datasets/dukemtmcreid.py +70 -0
  115. dnt/third_party/fast-reid/fastreid/data/datasets/grid.py +44 -0
  116. dnt/third_party/fast-reid/fastreid/data/datasets/iLIDS.py +45 -0
  117. dnt/third_party/fast-reid/fastreid/data/datasets/lpw.py +49 -0
  118. dnt/third_party/fast-reid/fastreid/data/datasets/market1501.py +89 -0
  119. dnt/third_party/fast-reid/fastreid/data/datasets/msmt17.py +114 -0
  120. dnt/third_party/fast-reid/fastreid/data/datasets/pes3d.py +44 -0
  121. dnt/third_party/fast-reid/fastreid/data/datasets/pku.py +44 -0
  122. dnt/third_party/fast-reid/fastreid/data/datasets/prai.py +43 -0
  123. dnt/third_party/fast-reid/fastreid/data/datasets/prid.py +41 -0
  124. dnt/third_party/fast-reid/fastreid/data/datasets/saivt.py +47 -0
  125. dnt/third_party/fast-reid/fastreid/data/datasets/sensereid.py +47 -0
  126. dnt/third_party/fast-reid/fastreid/data/datasets/shinpuhkan.py +48 -0
  127. dnt/third_party/fast-reid/fastreid/data/datasets/sysu_mm.py +47 -0
  128. dnt/third_party/fast-reid/fastreid/data/datasets/thermalworld.py +43 -0
  129. dnt/third_party/fast-reid/fastreid/data/datasets/vehicleid.py +126 -0
  130. dnt/third_party/fast-reid/fastreid/data/datasets/veri.py +69 -0
  131. dnt/third_party/fast-reid/fastreid/data/datasets/veriwild.py +140 -0
  132. dnt/third_party/fast-reid/fastreid/data/datasets/viper.py +45 -0
  133. dnt/third_party/fast-reid/fastreid/data/datasets/wildtracker.py +59 -0
  134. dnt/third_party/fast-reid/fastreid/data/samplers/__init__.py +18 -0
  135. dnt/third_party/fast-reid/fastreid/data/samplers/data_sampler.py +85 -0
  136. dnt/third_party/fast-reid/fastreid/data/samplers/imbalance_sampler.py +67 -0
  137. dnt/third_party/fast-reid/fastreid/data/samplers/triplet_sampler.py +260 -0
  138. dnt/third_party/fast-reid/fastreid/data/transforms/__init__.py +11 -0
  139. dnt/third_party/fast-reid/fastreid/data/transforms/autoaugment.py +806 -0
  140. dnt/third_party/fast-reid/fastreid/data/transforms/build.py +100 -0
  141. dnt/third_party/fast-reid/fastreid/data/transforms/functional.py +180 -0
  142. dnt/third_party/fast-reid/fastreid/data/transforms/transforms.py +161 -0
  143. dnt/third_party/fast-reid/fastreid/engine/__init__.py +15 -0
  144. dnt/third_party/fast-reid/fastreid/engine/defaults.py +490 -0
  145. dnt/third_party/fast-reid/fastreid/engine/hooks.py +534 -0
  146. dnt/third_party/fast-reid/fastreid/engine/launch.py +103 -0
  147. dnt/third_party/fast-reid/fastreid/engine/train_loop.py +357 -0
  148. dnt/third_party/fast-reid/fastreid/evaluation/__init__.py +6 -0
  149. dnt/third_party/fast-reid/fastreid/evaluation/clas_evaluator.py +81 -0
  150. dnt/third_party/fast-reid/fastreid/evaluation/evaluator.py +176 -0
  151. dnt/third_party/fast-reid/fastreid/evaluation/query_expansion.py +46 -0
  152. dnt/third_party/fast-reid/fastreid/evaluation/rank.py +200 -0
  153. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/__init__.py +20 -0
  154. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/setup.py +32 -0
  155. dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/test_cython.py +106 -0
  156. dnt/third_party/fast-reid/fastreid/evaluation/reid_evaluation.py +143 -0
  157. dnt/third_party/fast-reid/fastreid/evaluation/rerank.py +73 -0
  158. dnt/third_party/fast-reid/fastreid/evaluation/roc.py +90 -0
  159. dnt/third_party/fast-reid/fastreid/evaluation/testing.py +88 -0
  160. dnt/third_party/fast-reid/fastreid/layers/__init__.py +19 -0
  161. dnt/third_party/fast-reid/fastreid/layers/activation.py +59 -0
  162. dnt/third_party/fast-reid/fastreid/layers/any_softmax.py +80 -0
  163. dnt/third_party/fast-reid/fastreid/layers/batch_norm.py +205 -0
  164. dnt/third_party/fast-reid/fastreid/layers/context_block.py +113 -0
  165. dnt/third_party/fast-reid/fastreid/layers/drop.py +161 -0
  166. dnt/third_party/fast-reid/fastreid/layers/frn.py +199 -0
  167. dnt/third_party/fast-reid/fastreid/layers/gather_layer.py +30 -0
  168. dnt/third_party/fast-reid/fastreid/layers/helpers.py +31 -0
  169. dnt/third_party/fast-reid/fastreid/layers/non_local.py +54 -0
  170. dnt/third_party/fast-reid/fastreid/layers/pooling.py +124 -0
  171. dnt/third_party/fast-reid/fastreid/layers/se_layer.py +25 -0
  172. dnt/third_party/fast-reid/fastreid/layers/splat.py +109 -0
  173. dnt/third_party/fast-reid/fastreid/layers/weight_init.py +122 -0
  174. dnt/third_party/fast-reid/fastreid/modeling/__init__.py +23 -0
  175. dnt/third_party/fast-reid/fastreid/modeling/backbones/__init__.py +18 -0
  176. dnt/third_party/fast-reid/fastreid/modeling/backbones/build.py +27 -0
  177. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenet.py +195 -0
  178. dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenetv3.py +283 -0
  179. dnt/third_party/fast-reid/fastreid/modeling/backbones/osnet.py +525 -0
  180. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/__init__.py +4 -0
  181. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/config.py +396 -0
  182. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B0_dds_8gpu.yaml +27 -0
  183. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B1_dds_8gpu.yaml +27 -0
  184. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B2_dds_8gpu.yaml +27 -0
  185. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B3_dds_8gpu.yaml +27 -0
  186. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B4_dds_8gpu.yaml +27 -0
  187. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B5_dds_8gpu.yaml +27 -0
  188. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet.py +281 -0
  189. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnet.py +596 -0
  190. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-1.6GF_dds_8gpu.yaml +26 -0
  191. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-12GF_dds_8gpu.yaml +26 -0
  192. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-16GF_dds_8gpu.yaml +26 -0
  193. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-200MF_dds_8gpu.yaml +26 -0
  194. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-3.2GF_dds_8gpu.yaml +26 -0
  195. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-32GF_dds_8gpu.yaml +26 -0
  196. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-4.0GF_dds_8gpu.yaml +26 -0
  197. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-400MF_dds_8gpu.yaml +26 -0
  198. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-6.4GF_dds_8gpu.yaml +26 -0
  199. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-600MF_dds_8gpu.yaml +26 -0
  200. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-8.0GF_dds_8gpu.yaml +26 -0
  201. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-800MF_dds_8gpu.yaml +26 -0
  202. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-1.6GF_dds_8gpu.yaml +27 -0
  203. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-12GF_dds_8gpu.yaml +27 -0
  204. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-16GF_dds_8gpu.yaml +27 -0
  205. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-200MF_dds_8gpu.yaml +26 -0
  206. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-3.2GF_dds_8gpu.yaml +27 -0
  207. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-32GF_dds_8gpu.yaml +27 -0
  208. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-4.0GF_dds_8gpu.yaml +27 -0
  209. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-400MF_dds_8gpu.yaml +27 -0
  210. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-6.4GF_dds_8gpu.yaml +27 -0
  211. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-600MF_dds_8gpu.yaml +27 -0
  212. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-8.0GF_dds_8gpu.yaml +27 -0
  213. dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-800MF_dds_8gpu.yaml +27 -0
  214. dnt/third_party/fast-reid/fastreid/modeling/backbones/repvgg.py +309 -0
  215. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnest.py +365 -0
  216. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnet.py +364 -0
  217. dnt/third_party/fast-reid/fastreid/modeling/backbones/resnext.py +335 -0
  218. dnt/third_party/fast-reid/fastreid/modeling/backbones/shufflenet.py +203 -0
  219. dnt/third_party/fast-reid/fastreid/modeling/backbones/vision_transformer.py +399 -0
  220. dnt/third_party/fast-reid/fastreid/modeling/heads/__init__.py +11 -0
  221. dnt/third_party/fast-reid/fastreid/modeling/heads/build.py +25 -0
  222. dnt/third_party/fast-reid/fastreid/modeling/heads/clas_head.py +36 -0
  223. dnt/third_party/fast-reid/fastreid/modeling/heads/embedding_head.py +151 -0
  224. dnt/third_party/fast-reid/fastreid/modeling/losses/__init__.py +12 -0
  225. dnt/third_party/fast-reid/fastreid/modeling/losses/circle_loss.py +71 -0
  226. dnt/third_party/fast-reid/fastreid/modeling/losses/cross_entroy_loss.py +54 -0
  227. dnt/third_party/fast-reid/fastreid/modeling/losses/focal_loss.py +92 -0
  228. dnt/third_party/fast-reid/fastreid/modeling/losses/triplet_loss.py +113 -0
  229. dnt/third_party/fast-reid/fastreid/modeling/losses/utils.py +48 -0
  230. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/__init__.py +14 -0
  231. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/baseline.py +188 -0
  232. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/build.py +26 -0
  233. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/distiller.py +140 -0
  234. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/mgn.py +394 -0
  235. dnt/third_party/fast-reid/fastreid/modeling/meta_arch/moco.py +126 -0
  236. dnt/third_party/fast-reid/fastreid/solver/__init__.py +8 -0
  237. dnt/third_party/fast-reid/fastreid/solver/build.py +348 -0
  238. dnt/third_party/fast-reid/fastreid/solver/lr_scheduler.py +66 -0
  239. dnt/third_party/fast-reid/fastreid/solver/optim/__init__.py +10 -0
  240. dnt/third_party/fast-reid/fastreid/solver/optim/lamb.py +123 -0
  241. dnt/third_party/fast-reid/fastreid/solver/optim/radam.py +149 -0
  242. dnt/third_party/fast-reid/fastreid/solver/optim/swa.py +246 -0
  243. dnt/third_party/fast-reid/fastreid/utils/__init__.py +6 -0
  244. dnt/third_party/fast-reid/fastreid/utils/checkpoint.py +503 -0
  245. dnt/third_party/fast-reid/fastreid/utils/collect_env.py +158 -0
  246. dnt/third_party/fast-reid/fastreid/utils/comm.py +255 -0
  247. dnt/third_party/fast-reid/fastreid/utils/compute_dist.py +200 -0
  248. dnt/third_party/fast-reid/fastreid/utils/env.py +119 -0
  249. dnt/third_party/fast-reid/fastreid/utils/events.py +461 -0
  250. dnt/third_party/fast-reid/fastreid/utils/faiss_utils.py +127 -0
  251. dnt/third_party/fast-reid/fastreid/utils/file_io.py +520 -0
  252. dnt/third_party/fast-reid/fastreid/utils/history_buffer.py +71 -0
  253. dnt/third_party/fast-reid/fastreid/utils/logger.py +211 -0
  254. dnt/third_party/fast-reid/fastreid/utils/params.py +103 -0
  255. dnt/third_party/fast-reid/fastreid/utils/precision_bn.py +94 -0
  256. dnt/third_party/fast-reid/fastreid/utils/registry.py +66 -0
  257. dnt/third_party/fast-reid/fastreid/utils/summary.py +120 -0
  258. dnt/third_party/fast-reid/fastreid/utils/timer.py +68 -0
  259. dnt/third_party/fast-reid/fastreid/utils/visualizer.py +278 -0
  260. dnt/track/__init__.py +2 -0
  261. dnt/track/botsort/__init__.py +4 -0
  262. dnt/track/botsort/bot_tracker/__init__.py +3 -0
  263. dnt/track/botsort/bot_tracker/basetrack.py +60 -0
  264. dnt/track/botsort/bot_tracker/bot_sort.py +473 -0
  265. dnt/track/botsort/bot_tracker/gmc.py +316 -0
  266. dnt/track/botsort/bot_tracker/kalman_filter.py +269 -0
  267. dnt/track/botsort/bot_tracker/matching.py +194 -0
  268. dnt/track/botsort/bot_tracker/mc_bot_sort.py +505 -0
  269. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/evaluation.py +14 -4
  270. dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/io.py +19 -36
  271. dnt/track/botsort/bot_tracker/tracking_utils/timer.py +37 -0
  272. dnt/track/botsort/inference.py +96 -0
  273. dnt/track/config.py +120 -0
  274. dnt/track/dsort/configs/bagtricks_R50.yml +7 -0
  275. dnt/track/dsort/configs/deep_sort.yaml +0 -0
  276. dnt/track/dsort/configs/fastreid.yaml +1 -1
  277. dnt/track/dsort/deep_sort/deep/checkpoint/ckpt.t7 +0 -0
  278. dnt/track/dsort/deep_sort/deep/feature_extractor.py +87 -8
  279. dnt/track/dsort/deep_sort/deep_sort.py +28 -18
  280. dnt/track/dsort/deep_sort/sort/iou_matching.py +0 -2
  281. dnt/track/dsort/deep_sort/sort/linear_assignment.py +0 -3
  282. dnt/track/dsort/deep_sort/sort/nn_matching.py +5 -5
  283. dnt/track/dsort/deep_sort/sort/preprocessing.py +1 -2
  284. dnt/track/dsort/dsort.py +21 -28
  285. dnt/track/re_class.py +94 -0
  286. dnt/track/sort/sort.py +5 -1
  287. dnt/track/tracker.py +207 -30
  288. {dnt-0.2.4.dist-info → dnt-0.3.1.3.dist-info}/METADATA +30 -10
  289. dnt-0.3.1.3.dist-info/RECORD +314 -0
  290. {dnt-0.2.4.dist-info → dnt-0.3.1.3.dist-info}/WHEEL +1 -1
  291. dnt/analysis/yield.py +0 -9
  292. dnt/track/dsort/deep_sort/deep/evaluate.py +0 -15
  293. dnt/track/dsort/deep_sort/deep/original_model.py +0 -106
  294. dnt/track/dsort/deep_sort/deep/test.py +0 -77
  295. dnt/track/dsort/deep_sort/deep/train.py +0 -189
  296. dnt/track/dsort/utils/asserts.py +0 -13
  297. dnt/track/dsort/utils/draw.py +0 -36
  298. dnt/track/dsort/utils/json_logger.py +0 -383
  299. dnt/track/dsort/utils/log.py +0 -17
  300. dnt/track/dsort/utils/parser.py +0 -35
  301. dnt/track/dsort/utils/tools.py +0 -39
  302. dnt-0.2.4.dist-info/RECORD +0 -64
  303. /dnt/{track/dsort/utils → third_party/fast-reid/checkpoint}/__init__.py +0 -0
  304. {dnt-0.2.4.dist-info → dnt-0.3.1.3.dist-info}/LICENSE +0 -0
  305. {dnt-0.2.4.dist-info → dnt-0.3.1.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,806 @@
1
+ # encoding: utf-8
2
+ """
3
+ @author: liaoxingyu
4
+ @contact: sherlockliao01@gmail.com
5
+ """
6
+
7
+ """ AutoAugment, RandAugment, and AugMix for PyTorch
8
+ This code implements the searched ImageNet policies with various tweaks and improvements and
9
+ does not include any of the search code.
10
+ AA and RA Implementation adapted from:
11
+ https://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/autoaugment.py
12
+ AugMix adapted from:
13
+ https://github.com/google-research/augmix
14
+ Papers:
15
+ AutoAugment: Learning Augmentation Policies from Data - https://arxiv.org/abs/1805.09501
16
+ Learning Data Augmentation Strategies for Object Detection - https://arxiv.org/abs/1906.11172
17
+ RandAugment: Practical automated data augmentation... - https://arxiv.org/abs/1909.13719
18
+ AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty - https://arxiv.org/abs/1912.02781
19
+ Hacked together by Ross Wightman
20
+ """
21
+ import math
22
+ import random
23
+ import re
24
+
25
+ import PIL
26
+ import numpy as np
27
+ from PIL import Image, ImageOps, ImageEnhance
28
+
29
+ _PIL_VER = tuple([int(x) for x in PIL.__version__.split('.')[:2]])
30
+
31
+ _FILL = (128, 128, 128)
32
+
33
+ # This signifies the max integer that the controller RNN could predict for the
34
+ # augmentation scheme.
35
+ _MAX_LEVEL = 10.
36
+
37
+ _HPARAMS_DEFAULT = dict(
38
+ translate_const=57,
39
+ img_mean=_FILL,
40
+ )
41
+
42
+ _RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
43
+
44
+
45
+ def _interpolation(kwargs):
46
+ interpolation = kwargs.pop('resample', Image.BILINEAR)
47
+ if isinstance(interpolation, (list, tuple)):
48
+ return random.choice(interpolation)
49
+ else:
50
+ return interpolation
51
+
52
+
53
+ def _check_args_tf(kwargs):
54
+ if 'fillcolor' in kwargs and _PIL_VER < (5, 0):
55
+ kwargs.pop('fillcolor')
56
+ kwargs['resample'] = _interpolation(kwargs)
57
+
58
+
59
+ def shear_x(img, factor, **kwargs):
60
+ _check_args_tf(kwargs)
61
+ return img.transform(img.size, Image.AFFINE, (1, factor, 0, 0, 1, 0), **kwargs)
62
+
63
+
64
+ def shear_y(img, factor, **kwargs):
65
+ _check_args_tf(kwargs)
66
+ return img.transform(img.size, Image.AFFINE, (1, 0, 0, factor, 1, 0), **kwargs)
67
+
68
+
69
+ def translate_x_rel(img, pct, **kwargs):
70
+ pixels = pct * img.size[0]
71
+ _check_args_tf(kwargs)
72
+ return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs)
73
+
74
+
75
+ def translate_y_rel(img, pct, **kwargs):
76
+ pixels = pct * img.size[1]
77
+ _check_args_tf(kwargs)
78
+ return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs)
79
+
80
+
81
+ def translate_x_abs(img, pixels, **kwargs):
82
+ _check_args_tf(kwargs)
83
+ return img.transform(img.size, Image.AFFINE, (1, 0, pixels, 0, 1, 0), **kwargs)
84
+
85
+
86
+ def translate_y_abs(img, pixels, **kwargs):
87
+ _check_args_tf(kwargs)
88
+ return img.transform(img.size, Image.AFFINE, (1, 0, 0, 0, 1, pixels), **kwargs)
89
+
90
+
91
+ def rotate(img, degrees, **kwargs):
92
+ _check_args_tf(kwargs)
93
+ if _PIL_VER >= (5, 2):
94
+ return img.rotate(degrees, **kwargs)
95
+ elif _PIL_VER >= (5, 0):
96
+ w, h = img.size
97
+ post_trans = (0, 0)
98
+ rotn_center = (w / 2.0, h / 2.0)
99
+ angle = -math.radians(degrees)
100
+ matrix = [
101
+ round(math.cos(angle), 15),
102
+ round(math.sin(angle), 15),
103
+ 0.0,
104
+ round(-math.sin(angle), 15),
105
+ round(math.cos(angle), 15),
106
+ 0.0,
107
+ ]
108
+
109
+ def transform(x, y, matrix):
110
+ (a, b, c, d, e, f) = matrix
111
+ return a * x + b * y + c, d * x + e * y + f
112
+
113
+ matrix[2], matrix[5] = transform(
114
+ -rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix
115
+ )
116
+ matrix[2] += rotn_center[0]
117
+ matrix[5] += rotn_center[1]
118
+ return img.transform(img.size, Image.AFFINE, matrix, **kwargs)
119
+ else:
120
+ return img.rotate(degrees, resample=kwargs['resample'])
121
+
122
+
123
+ def auto_contrast(img, **__):
124
+ return ImageOps.autocontrast(img)
125
+
126
+
127
+ def invert(img, **__):
128
+ return ImageOps.invert(img)
129
+
130
+
131
+ def equalize(img, **__):
132
+ return ImageOps.equalize(img)
133
+
134
+
135
+ def solarize(img, thresh, **__):
136
+ return ImageOps.solarize(img, thresh)
137
+
138
+
139
+ def solarize_add(img, add, thresh=128, **__):
140
+ lut = []
141
+ for i in range(256):
142
+ if i < thresh:
143
+ lut.append(min(255, i + add))
144
+ else:
145
+ lut.append(i)
146
+ if img.mode in ("L", "RGB"):
147
+ if img.mode == "RGB" and len(lut) == 256:
148
+ lut = lut + lut + lut
149
+ return img.point(lut)
150
+ else:
151
+ return img
152
+
153
+
154
+ def posterize(img, bits_to_keep, **__):
155
+ if bits_to_keep >= 8:
156
+ return img
157
+ return ImageOps.posterize(img, bits_to_keep)
158
+
159
+
160
+ def contrast(img, factor, **__):
161
+ return ImageEnhance.Contrast(img).enhance(factor)
162
+
163
+
164
+ def color(img, factor, **__):
165
+ return ImageEnhance.Color(img).enhance(factor)
166
+
167
+
168
+ def brightness(img, factor, **__):
169
+ return ImageEnhance.Brightness(img).enhance(factor)
170
+
171
+
172
+ def sharpness(img, factor, **__):
173
+ return ImageEnhance.Sharpness(img).enhance(factor)
174
+
175
+
176
+ def _randomly_negate(v):
177
+ """With 50% prob, negate the value"""
178
+ return -v if random.random() > 0.5 else v
179
+
180
+
181
+ def _rotate_level_to_arg(level, _hparams):
182
+ # range [-30, 30]
183
+ level = (level / _MAX_LEVEL) * 30.
184
+ level = _randomly_negate(level)
185
+ return level,
186
+
187
+
188
+ def _enhance_level_to_arg(level, _hparams):
189
+ # range [0.1, 1.9]
190
+ return (level / _MAX_LEVEL) * 1.8 + 0.1,
191
+
192
+
193
+ def _enhance_increasing_level_to_arg(level, _hparams):
194
+ # the 'no change' level is 1.0, moving away from that towards 0. or 2.0 increases the enhancement blend
195
+ # range [0.1, 1.9]
196
+ level = (level / _MAX_LEVEL) * .9
197
+ level = 1.0 + _randomly_negate(level)
198
+ return level,
199
+
200
+
201
+ def _shear_level_to_arg(level, _hparams):
202
+ # range [-0.3, 0.3]
203
+ level = (level / _MAX_LEVEL) * 0.3
204
+ level = _randomly_negate(level)
205
+ return level,
206
+
207
+
208
+ def _translate_abs_level_to_arg(level, hparams):
209
+ translate_const = hparams['translate_const']
210
+ level = (level / _MAX_LEVEL) * float(translate_const)
211
+ level = _randomly_negate(level)
212
+ return level,
213
+
214
+
215
+ def _translate_rel_level_to_arg(level, hparams):
216
+ # default range [-0.45, 0.45]
217
+ translate_pct = hparams.get('translate_pct', 0.45)
218
+ level = (level / _MAX_LEVEL) * translate_pct
219
+ level = _randomly_negate(level)
220
+ return level,
221
+
222
+
223
+ def _posterize_level_to_arg(level, _hparams):
224
+ # As per Tensorflow TPU EfficientNet impl
225
+ # range [0, 4], 'keep 0 up to 4 MSB of original image'
226
+ # intensity/severity of augmentation decreases with level
227
+ return int((level / _MAX_LEVEL) * 4),
228
+
229
+
230
+ def _posterize_increasing_level_to_arg(level, hparams):
231
+ # As per Tensorflow models research and UDA impl
232
+ # range [4, 0], 'keep 4 down to 0 MSB of original image',
233
+ # intensity/severity of augmentation increases with level
234
+ return 4 - _posterize_level_to_arg(level, hparams)[0],
235
+
236
+
237
+ def _posterize_original_level_to_arg(level, _hparams):
238
+ # As per original AutoAugment paper description
239
+ # range [4, 8], 'keep 4 up to 8 MSB of image'
240
+ # intensity/severity of augmentation decreases with level
241
+ return int((level / _MAX_LEVEL) * 4) + 4,
242
+
243
+
244
+ def _solarize_level_to_arg(level, _hparams):
245
+ # range [0, 256]
246
+ # intensity/severity of augmentation decreases with level
247
+ return int((level / _MAX_LEVEL) * 256),
248
+
249
+
250
+ def _solarize_increasing_level_to_arg(level, _hparams):
251
+ # range [0, 256]
252
+ # intensity/severity of augmentation increases with level
253
+ return 256 - _solarize_level_to_arg(level, _hparams)[0],
254
+
255
+
256
+ def _solarize_add_level_to_arg(level, _hparams):
257
+ # range [0, 110]
258
+ return int((level / _MAX_LEVEL) * 110),
259
+
260
+
261
+ LEVEL_TO_ARG = {
262
+ 'AutoContrast': None,
263
+ 'Equalize': None,
264
+ 'Invert': None,
265
+ 'Rotate': _rotate_level_to_arg,
266
+ # There are several variations of the posterize level scaling in various Tensorflow/Google repositories/papers
267
+ 'Posterize': _posterize_level_to_arg,
268
+ 'PosterizeIncreasing': _posterize_increasing_level_to_arg,
269
+ 'PosterizeOriginal': _posterize_original_level_to_arg,
270
+ 'Solarize': _solarize_level_to_arg,
271
+ 'SolarizeIncreasing': _solarize_increasing_level_to_arg,
272
+ 'SolarizeAdd': _solarize_add_level_to_arg,
273
+ 'Color': _enhance_level_to_arg,
274
+ 'ColorIncreasing': _enhance_increasing_level_to_arg,
275
+ 'Contrast': _enhance_level_to_arg,
276
+ 'ContrastIncreasing': _enhance_increasing_level_to_arg,
277
+ 'Brightness': _enhance_level_to_arg,
278
+ 'BrightnessIncreasing': _enhance_increasing_level_to_arg,
279
+ 'Sharpness': _enhance_level_to_arg,
280
+ 'SharpnessIncreasing': _enhance_increasing_level_to_arg,
281
+ 'ShearX': _shear_level_to_arg,
282
+ 'ShearY': _shear_level_to_arg,
283
+ 'TranslateX': _translate_abs_level_to_arg,
284
+ 'TranslateY': _translate_abs_level_to_arg,
285
+ 'TranslateXRel': _translate_rel_level_to_arg,
286
+ 'TranslateYRel': _translate_rel_level_to_arg,
287
+ }
288
+
289
+ NAME_TO_OP = {
290
+ 'AutoContrast': auto_contrast,
291
+ 'Equalize': equalize,
292
+ 'Invert': invert,
293
+ 'Rotate': rotate,
294
+ 'Posterize': posterize,
295
+ 'PosterizeIncreasing': posterize,
296
+ 'PosterizeOriginal': posterize,
297
+ 'Solarize': solarize,
298
+ 'SolarizeIncreasing': solarize,
299
+ 'SolarizeAdd': solarize_add,
300
+ 'Color': color,
301
+ 'ColorIncreasing': color,
302
+ 'Contrast': contrast,
303
+ 'ContrastIncreasing': contrast,
304
+ 'Brightness': brightness,
305
+ 'BrightnessIncreasing': brightness,
306
+ 'Sharpness': sharpness,
307
+ 'SharpnessIncreasing': sharpness,
308
+ 'ShearX': shear_x,
309
+ 'ShearY': shear_y,
310
+ 'TranslateX': translate_x_abs,
311
+ 'TranslateY': translate_y_abs,
312
+ 'TranslateXRel': translate_x_rel,
313
+ 'TranslateYRel': translate_y_rel,
314
+ }
315
+
316
+
317
+ class AugmentOp:
318
+
319
+ def __init__(self, name, prob=0.5, magnitude=10, hparams=None):
320
+ hparams = hparams or _HPARAMS_DEFAULT
321
+ self.aug_fn = NAME_TO_OP[name]
322
+ self.level_fn = LEVEL_TO_ARG[name]
323
+ self.prob = prob
324
+ self.magnitude = magnitude
325
+ self.hparams = hparams.copy()
326
+ self.kwargs = dict(
327
+ fillcolor=hparams['img_mean'] if 'img_mean' in hparams else _FILL,
328
+ resample=hparams['interpolation'] if 'interpolation' in hparams else _RANDOM_INTERPOLATION,
329
+ )
330
+
331
+ # If magnitude_std is > 0, we introduce some randomness
332
+ # in the usually fixed policy and sample magnitude from a normal distribution
333
+ # with mean `magnitude` and std-dev of `magnitude_std`.
334
+ # NOTE This is my own hack, being tested, not in papers or reference impls.
335
+ self.magnitude_std = self.hparams.get('magnitude_std', 0)
336
+
337
+ def __call__(self, img):
338
+ if self.prob < 1.0 and random.random() > self.prob:
339
+ return img
340
+ magnitude = self.magnitude
341
+ if self.magnitude_std and self.magnitude_std > 0:
342
+ magnitude = random.gauss(magnitude, self.magnitude_std)
343
+ magnitude = min(_MAX_LEVEL, max(0, magnitude)) # clip to valid range
344
+ level_args = self.level_fn(magnitude, self.hparams) if self.level_fn is not None else tuple()
345
+ return self.aug_fn(img, *level_args, **self.kwargs)
346
+
347
+
348
+ def auto_augment_policy_v0(hparams):
349
+ # ImageNet v0 policy from TPU EfficientNet impl, cannot find a paper reference.
350
+ policy = [
351
+ [('Equalize', 0.8, 1), ('ShearY', 0.8, 4)],
352
+ [('Color', 0.4, 9), ('Equalize', 0.6, 3)],
353
+ [('Color', 0.4, 1), ('Rotate', 0.6, 8)],
354
+ [('Solarize', 0.8, 3), ('Equalize', 0.4, 7)],
355
+ [('Solarize', 0.4, 2), ('Solarize', 0.6, 2)],
356
+ [('Color', 0.2, 0), ('Equalize', 0.8, 8)],
357
+ [('Equalize', 0.4, 8), ('SolarizeAdd', 0.8, 3)],
358
+ [('ShearX', 0.2, 9), ('Rotate', 0.6, 8)],
359
+ [('Color', 0.6, 1), ('Equalize', 1.0, 2)],
360
+ [('Invert', 0.4, 9), ('Rotate', 0.6, 0)],
361
+ [('Equalize', 1.0, 9), ('ShearY', 0.6, 3)],
362
+ [('Color', 0.4, 7), ('Equalize', 0.6, 0)],
363
+ [('Posterize', 0.4, 6), ('AutoContrast', 0.4, 7)],
364
+ [('Solarize', 0.6, 8), ('Color', 0.6, 9)],
365
+ [('Solarize', 0.2, 4), ('Rotate', 0.8, 9)],
366
+ [('Rotate', 1.0, 7), ('TranslateYRel', 0.8, 9)],
367
+ [('ShearX', 0.0, 0), ('Solarize', 0.8, 4)],
368
+ [('ShearY', 0.8, 0), ('Color', 0.6, 4)],
369
+ [('Color', 1.0, 0), ('Rotate', 0.6, 2)],
370
+ [('Equalize', 0.8, 4), ('Equalize', 0.0, 8)],
371
+ [('Equalize', 1.0, 4), ('AutoContrast', 0.6, 2)],
372
+ [('ShearY', 0.4, 7), ('SolarizeAdd', 0.6, 7)],
373
+ [('Posterize', 0.8, 2), ('Solarize', 0.6, 10)], # This results in black image with Tpu posterize
374
+ [('Solarize', 0.6, 8), ('Equalize', 0.6, 1)],
375
+ [('Color', 0.8, 6), ('Rotate', 0.4, 5)],
376
+ ]
377
+ pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy]
378
+ return pc
379
+
380
+
381
+ def auto_augment_policy_v0r(hparams):
382
+ # ImageNet v0 policy from TPU EfficientNet impl, with variation of Posterize used
383
+ # in Google research implementation (number of bits discarded increases with magnitude)
384
+ policy = [
385
+ [('Equalize', 0.8, 1), ('ShearY', 0.8, 4)],
386
+ [('Color', 0.4, 9), ('Equalize', 0.6, 3)],
387
+ [('Color', 0.4, 1), ('Rotate', 0.6, 8)],
388
+ [('Solarize', 0.8, 3), ('Equalize', 0.4, 7)],
389
+ [('Solarize', 0.4, 2), ('Solarize', 0.6, 2)],
390
+ [('Color', 0.2, 0), ('Equalize', 0.8, 8)],
391
+ [('Equalize', 0.4, 8), ('SolarizeAdd', 0.8, 3)],
392
+ [('ShearX', 0.2, 9), ('Rotate', 0.6, 8)],
393
+ [('Color', 0.6, 1), ('Equalize', 1.0, 2)],
394
+ [('Invert', 0.4, 9), ('Rotate', 0.6, 0)],
395
+ [('Equalize', 1.0, 9), ('ShearY', 0.6, 3)],
396
+ [('Color', 0.4, 7), ('Equalize', 0.6, 0)],
397
+ [('PosterizeIncreasing', 0.4, 6), ('AutoContrast', 0.4, 7)],
398
+ [('Solarize', 0.6, 8), ('Color', 0.6, 9)],
399
+ [('Solarize', 0.2, 4), ('Rotate', 0.8, 9)],
400
+ [('Rotate', 1.0, 7), ('TranslateYRel', 0.8, 9)],
401
+ [('ShearX', 0.0, 0), ('Solarize', 0.8, 4)],
402
+ [('ShearY', 0.8, 0), ('Color', 0.6, 4)],
403
+ [('Color', 1.0, 0), ('Rotate', 0.6, 2)],
404
+ [('Equalize', 0.8, 4), ('Equalize', 0.0, 8)],
405
+ [('Equalize', 1.0, 4), ('AutoContrast', 0.6, 2)],
406
+ [('ShearY', 0.4, 7), ('SolarizeAdd', 0.6, 7)],
407
+ [('PosterizeIncreasing', 0.8, 2), ('Solarize', 0.6, 10)],
408
+ [('Solarize', 0.6, 8), ('Equalize', 0.6, 1)],
409
+ [('Color', 0.8, 6), ('Rotate', 0.4, 5)],
410
+ ]
411
+ pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy]
412
+ return pc
413
+
414
+
415
+ def auto_augment_policy_original(hparams):
416
+ # ImageNet policy from https://arxiv.org/abs/1805.09501
417
+ policy = [
418
+ [('PosterizeOriginal', 0.4, 8), ('Rotate', 0.6, 9)],
419
+ [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)],
420
+ [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)],
421
+ [('PosterizeOriginal', 0.6, 7), ('PosterizeOriginal', 0.6, 6)],
422
+ [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)],
423
+ [('Equalize', 0.4, 4), ('Rotate', 0.8, 8)],
424
+ [('Solarize', 0.6, 3), ('Equalize', 0.6, 7)],
425
+ [('PosterizeOriginal', 0.8, 5), ('Equalize', 1.0, 2)],
426
+ [('Rotate', 0.2, 3), ('Solarize', 0.6, 8)],
427
+ [('Equalize', 0.6, 8), ('PosterizeOriginal', 0.4, 6)],
428
+ [('Rotate', 0.8, 8), ('Color', 0.4, 0)],
429
+ [('Rotate', 0.4, 9), ('Equalize', 0.6, 2)],
430
+ [('Equalize', 0.0, 7), ('Equalize', 0.8, 8)],
431
+ [('Invert', 0.6, 4), ('Equalize', 1.0, 8)],
432
+ [('Color', 0.6, 4), ('Contrast', 1.0, 8)],
433
+ [('Rotate', 0.8, 8), ('Color', 1.0, 2)],
434
+ [('Color', 0.8, 8), ('Solarize', 0.8, 7)],
435
+ [('Sharpness', 0.4, 7), ('Invert', 0.6, 8)],
436
+ [('ShearX', 0.6, 5), ('Equalize', 1.0, 9)],
437
+ [('Color', 0.4, 0), ('Equalize', 0.6, 3)],
438
+ [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)],
439
+ [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)],
440
+ [('Invert', 0.6, 4), ('Equalize', 1.0, 8)],
441
+ [('Color', 0.6, 4), ('Contrast', 1.0, 8)],
442
+ [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)],
443
+ ]
444
+ pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy]
445
+ return pc
446
+
447
+
448
+ def auto_augment_policy_originalr(hparams):
449
+ # ImageNet policy from https://arxiv.org/abs/1805.09501 with research posterize variation
450
+ policy = [
451
+ [('PosterizeIncreasing', 0.4, 8), ('Rotate', 0.6, 9)],
452
+ [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)],
453
+ [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)],
454
+ [('PosterizeIncreasing', 0.6, 7), ('PosterizeIncreasing', 0.6, 6)],
455
+ [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)],
456
+ [('Equalize', 0.4, 4), ('Rotate', 0.8, 8)],
457
+ [('Solarize', 0.6, 3), ('Equalize', 0.6, 7)],
458
+ [('PosterizeIncreasing', 0.8, 5), ('Equalize', 1.0, 2)],
459
+ [('Rotate', 0.2, 3), ('Solarize', 0.6, 8)],
460
+ [('Equalize', 0.6, 8), ('PosterizeIncreasing', 0.4, 6)],
461
+ [('Rotate', 0.8, 8), ('Color', 0.4, 0)],
462
+ [('Rotate', 0.4, 9), ('Equalize', 0.6, 2)],
463
+ [('Equalize', 0.0, 7), ('Equalize', 0.8, 8)],
464
+ [('Invert', 0.6, 4), ('Equalize', 1.0, 8)],
465
+ [('Color', 0.6, 4), ('Contrast', 1.0, 8)],
466
+ [('Rotate', 0.8, 8), ('Color', 1.0, 2)],
467
+ [('Color', 0.8, 8), ('Solarize', 0.8, 7)],
468
+ [('Sharpness', 0.4, 7), ('Invert', 0.6, 8)],
469
+ [('ShearX', 0.6, 5), ('Equalize', 1.0, 9)],
470
+ [('Color', 0.4, 0), ('Equalize', 0.6, 3)],
471
+ [('Equalize', 0.4, 7), ('Solarize', 0.2, 4)],
472
+ [('Solarize', 0.6, 5), ('AutoContrast', 0.6, 5)],
473
+ [('Invert', 0.6, 4), ('Equalize', 1.0, 8)],
474
+ [('Color', 0.6, 4), ('Contrast', 1.0, 8)],
475
+ [('Equalize', 0.8, 8), ('Equalize', 0.6, 3)],
476
+ ]
477
+ pc = [[AugmentOp(*a, hparams=hparams) for a in sp] for sp in policy]
478
+ return pc
479
+
480
+
481
+ def auto_augment_policy(name="original"):
482
+ hparams = _HPARAMS_DEFAULT
483
+ if name == 'original':
484
+ return auto_augment_policy_original(hparams)
485
+ elif name == 'originalr':
486
+ return auto_augment_policy_originalr(hparams)
487
+ elif name == 'v0':
488
+ return auto_augment_policy_v0(hparams)
489
+ elif name == 'v0r':
490
+ return auto_augment_policy_v0r(hparams)
491
+ else:
492
+ assert False, 'Unknown AA policy (%s)' % name
493
+
494
+
495
+ class AutoAugment:
496
+
497
+ def __init__(self):
498
+ self.policy = auto_augment_policy()
499
+
500
+ def __call__(self, img):
501
+ sub_policy = random.choice(self.policy)
502
+ for op in sub_policy:
503
+ img = op(img)
504
+ return img
505
+
506
+
507
+ def auto_augment_transform(config_str, hparams):
508
+ """
509
+ Create a AutoAugment transform
510
+ :param config_str: String defining configuration of auto augmentation. Consists of multiple sections separated by
511
+ dashes ('-'). The first section defines the AutoAugment policy (one of 'v0', 'v0r', 'original', 'originalr').
512
+ The remaining sections, not order sepecific determine
513
+ 'mstd' - float std deviation of magnitude noise applied
514
+ Ex 'original-mstd0.5' results in AutoAugment with original policy, magnitude_std 0.5
515
+ :param hparams: Other hparams (kwargs) for the AutoAugmentation scheme
516
+ :return: A PyTorch compatible Transform
517
+ """
518
+ config = config_str.split('-')
519
+ policy_name = config[0]
520
+ config = config[1:]
521
+ for c in config:
522
+ cs = re.split(r'(\d.*)', c)
523
+ if len(cs) < 2:
524
+ continue
525
+ key, val = cs[:2]
526
+ if key == 'mstd':
527
+ # noise param injected via hparams for now
528
+ hparams.setdefault('magnitude_std', float(val))
529
+ else:
530
+ assert False, 'Unknown AutoAugment config section'
531
+ aa_policy = auto_augment_policy(policy_name)
532
+ return AutoAugment(aa_policy)
533
+
534
+
535
+ _RAND_TRANSFORMS = [
536
+ 'AutoContrast',
537
+ 'Equalize',
538
+ 'Invert',
539
+ 'Rotate',
540
+ 'Posterize',
541
+ 'Solarize',
542
+ 'SolarizeAdd',
543
+ 'Color',
544
+ 'Contrast',
545
+ 'Brightness',
546
+ 'Sharpness',
547
+ 'ShearX',
548
+ 'ShearY',
549
+ 'TranslateXRel',
550
+ 'TranslateYRel',
551
+ # 'Cutout' # NOTE I've implement this as random erasing separately
552
+ ]
553
+
554
+ _RAND_INCREASING_TRANSFORMS = [
555
+ 'AutoContrast',
556
+ 'Equalize',
557
+ 'Invert',
558
+ 'Rotate',
559
+ 'PosterizeIncreasing',
560
+ 'SolarizeIncreasing',
561
+ 'SolarizeAdd',
562
+ 'ColorIncreasing',
563
+ 'ContrastIncreasing',
564
+ 'BrightnessIncreasing',
565
+ 'SharpnessIncreasing',
566
+ 'ShearX',
567
+ 'ShearY',
568
+ 'TranslateXRel',
569
+ 'TranslateYRel',
570
+ # 'Cutout' # NOTE I've implement this as random erasing separately
571
+ ]
572
+
573
+ # These experimental weights are based loosely on the relative improvements mentioned in paper.
574
+ # They may not result in increased performance, but could likely be tuned to so.
575
+ _RAND_CHOICE_WEIGHTS_0 = {
576
+ 'Rotate': 0.3,
577
+ 'ShearX': 0.2,
578
+ 'ShearY': 0.2,
579
+ 'TranslateXRel': 0.1,
580
+ 'TranslateYRel': 0.1,
581
+ 'Color': .025,
582
+ 'Sharpness': 0.025,
583
+ 'AutoContrast': 0.025,
584
+ 'Solarize': .005,
585
+ 'SolarizeAdd': .005,
586
+ 'Contrast': .005,
587
+ 'Brightness': .005,
588
+ 'Equalize': .005,
589
+ 'Posterize': 0,
590
+ 'Invert': 0,
591
+ }
592
+
593
+
594
+ def _select_rand_weights(weight_idx=0, transforms=None):
595
+ transforms = transforms or _RAND_TRANSFORMS
596
+ assert weight_idx == 0 # only one set of weights currently
597
+ rand_weights = _RAND_CHOICE_WEIGHTS_0
598
+ probs = [rand_weights[k] for k in transforms]
599
+ probs /= np.sum(probs)
600
+ return probs
601
+
602
+
603
+ def rand_augment_ops(magnitude=10, hparams=None, transforms=None):
604
+ hparams = hparams or _HPARAMS_DEFAULT
605
+ transforms = transforms or _RAND_TRANSFORMS
606
+ return [AugmentOp(
607
+ name, prob=0.5, magnitude=magnitude, hparams=hparams) for name in transforms]
608
+
609
+
610
+ class RandAugment:
611
+ def __init__(self, ops, num_layers=2, choice_weights=None):
612
+ self.ops = ops
613
+ self.num_layers = num_layers
614
+ self.choice_weights = choice_weights
615
+
616
+ def __call__(self, img):
617
+ # no replacement when using weighted choice
618
+ ops = np.random.choice(
619
+ self.ops, self.num_layers, replace=self.choice_weights is None, p=self.choice_weights)
620
+ for op in ops:
621
+ img = op(img)
622
+ return img
623
+
624
+
625
+ def rand_augment_transform(config_str, hparams):
626
+ """
627
+ Create a RandAugment transform
628
+ :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by
629
+ dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining
630
+ sections, not order sepecific determine
631
+ 'm' - integer magnitude of rand augment
632
+ 'n' - integer num layers (number of transform ops selected per image)
633
+ 'w' - integer probabiliy weight index (index of a set of weights to influence choice of op)
634
+ 'mstd' - float std deviation of magnitude noise applied
635
+ 'inc' - integer (bool), use augmentations that increase in severity with magnitude (default: 0)
636
+ Ex 'rand-m9-n3-mstd0.5' results in RandAugment with magnitude 9, num_layers 3, magnitude_std 0.5
637
+ 'rand-mstd1-w0' results in magnitude_std 1.0, weights 0, default magnitude of 10 and num_layers 2
638
+ :param hparams: Other hparams (kwargs) for the RandAugmentation scheme
639
+ :return: A PyTorch compatible Transform
640
+ """
641
+ magnitude = _MAX_LEVEL # default to _MAX_LEVEL for magnitude (currently 10)
642
+ num_layers = 2 # default to 2 ops per image
643
+ weight_idx = None # default to no probability weights for op choice
644
+ transforms = _RAND_TRANSFORMS
645
+ config = config_str.split('-')
646
+ assert config[0] == 'rand'
647
+ config = config[1:]
648
+ for c in config:
649
+ cs = re.split(r'(\d.*)', c)
650
+ if len(cs) < 2:
651
+ continue
652
+ key, val = cs[:2]
653
+ if key == 'mstd':
654
+ # noise param injected via hparams for now
655
+ hparams.setdefault('magnitude_std', float(val))
656
+ elif key == 'inc':
657
+ if bool(val):
658
+ transforms = _RAND_INCREASING_TRANSFORMS
659
+ elif key == 'm':
660
+ magnitude = int(val)
661
+ elif key == 'n':
662
+ num_layers = int(val)
663
+ elif key == 'w':
664
+ weight_idx = int(val)
665
+ else:
666
+ assert False, 'Unknown RandAugment config section'
667
+ ra_ops = rand_augment_ops(magnitude=magnitude, hparams=hparams, transforms=transforms)
668
+ choice_weights = None if weight_idx is None else _select_rand_weights(weight_idx)
669
+ return RandAugment(ra_ops, num_layers, choice_weights=choice_weights)
670
+
671
+
672
+ _AUGMIX_TRANSFORMS = [
673
+ 'AutoContrast',
674
+ 'ColorIncreasing', # not in paper
675
+ 'ContrastIncreasing', # not in paper
676
+ 'BrightnessIncreasing', # not in paper
677
+ 'SharpnessIncreasing', # not in paper
678
+ 'Equalize',
679
+ 'Rotate',
680
+ 'PosterizeIncreasing',
681
+ 'SolarizeIncreasing',
682
+ 'ShearX',
683
+ 'ShearY',
684
+ 'TranslateXRel',
685
+ 'TranslateYRel',
686
+ ]
687
+
688
+
689
+ def augmix_ops(magnitude=10, hparams=None, transforms=None):
690
+ hparams = hparams or _HPARAMS_DEFAULT
691
+ transforms = transforms or _AUGMIX_TRANSFORMS
692
+ return [AugmentOp(
693
+ name, prob=1.0, magnitude=magnitude, hparams=hparams) for name in transforms]
694
+
695
+
696
+ class AugMixAugment:
697
+ """ AugMix Transform
698
+ Adapted and improved from impl here: https://github.com/google-research/augmix/blob/master/imagenet.py
699
+ From paper: 'AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty -
700
+ https://arxiv.org/abs/1912.02781
701
+ """
702
+
703
+ def __init__(self, ops, alpha=1., width=3, depth=-1, blended=False):
704
+ self.ops = ops
705
+ self.alpha = alpha
706
+ self.width = width
707
+ self.depth = depth
708
+ self.blended = blended # blended mode is faster but not well tested
709
+
710
+ def _calc_blended_weights(self, ws, m):
711
+ ws = ws * m
712
+ cump = 1.
713
+ rws = []
714
+ for w in ws[::-1]:
715
+ alpha = w / cump
716
+ cump *= (1 - alpha)
717
+ rws.append(alpha)
718
+ return np.array(rws[::-1], dtype=np.float32)
719
+
720
+ def _apply_blended(self, img, mixing_weights, m):
721
+ # This is my first crack and implementing a slightly faster mixed augmentation. Instead
722
+ # of accumulating the mix for each chain in a Numpy array and then blending with original,
723
+ # it recomputes the blending coefficients and applies one PIL image blend per chain.
724
+ # TODO the results appear in the right ballpark but they differ by more than rounding.
725
+ img_orig = img.copy()
726
+ ws = self._calc_blended_weights(mixing_weights, m)
727
+ for w in ws:
728
+ depth = self.depth if self.depth > 0 else np.random.randint(1, 4)
729
+ ops = np.random.choice(self.ops, depth, replace=True)
730
+ img_aug = img_orig # no ops are in-place, deep copy not necessary
731
+ for op in ops:
732
+ img_aug = op(img_aug)
733
+ img = Image.blend(img, img_aug, w)
734
+ return img
735
+
736
+ def _apply_basic(self, img, mixing_weights, m):
737
+ # This is a literal adaptation of the paper/official implementation without normalizations and
738
+ # PIL <-> Numpy conversions between every op. It is still quite CPU compute heavy compared to the
739
+ # typical augmentation transforms, could use a GPU / Kornia implementation.
740
+ img_shape = img.size[0], img.size[1], len(img.getbands())
741
+ mixed = np.zeros(img_shape, dtype=np.float32)
742
+ for mw in mixing_weights:
743
+ depth = self.depth if self.depth > 0 else np.random.randint(1, 4)
744
+ ops = np.random.choice(self.ops, depth, replace=True)
745
+ img_aug = img # no ops are in-place, deep copy not necessary
746
+ for op in ops:
747
+ img_aug = op(img_aug)
748
+ mixed += mw * np.asarray(img_aug, dtype=np.float32)
749
+ np.clip(mixed, 0, 255., out=mixed)
750
+ mixed = Image.fromarray(mixed.astype(np.uint8))
751
+ return Image.blend(img, mixed, m)
752
+
753
+ def __call__(self, img):
754
+ mixing_weights = np.float32(np.random.dirichlet([self.alpha] * self.width))
755
+ m = np.float32(np.random.beta(self.alpha, self.alpha))
756
+ if self.blended:
757
+ mixed = self._apply_blended(img, mixing_weights, m)
758
+ else:
759
+ mixed = self._apply_basic(img, mixing_weights, m)
760
+ return mixed
761
+
762
+
763
+ def augment_and_mix_transform(config_str, hparams):
764
+ """ Create AugMix PyTorch transform
765
+ :param config_str: String defining configuration of random augmentation. Consists of multiple sections separated by
766
+ dashes ('-'). The first section defines the specific variant of rand augment (currently only 'rand'). The remaining
767
+ sections, not order sepecific determine
768
+ 'm' - integer magnitude (severity) of augmentation mix (default: 3)
769
+ 'w' - integer width of augmentation chain (default: 3)
770
+ 'd' - integer depth of augmentation chain (-1 is random [1, 3], default: -1)
771
+ 'b' - integer (bool), blend each branch of chain into end result without a final blend, less CPU (default: 0)
772
+ 'mstd' - float std deviation of magnitude noise applied (default: 0)
773
+ Ex 'augmix-m5-w4-d2' results in AugMix with severity 5, chain width 4, chain depth 2
774
+ :param hparams: Other hparams (kwargs) for the Augmentation transforms
775
+ :return: A PyTorch compatible Transform
776
+ """
777
+ magnitude = 3
778
+ width = 3
779
+ depth = -1
780
+ alpha = 1.
781
+ blended = False
782
+ config = config_str.split('-')
783
+ assert config[0] == 'augmix'
784
+ config = config[1:]
785
+ for c in config:
786
+ cs = re.split(r'(\d.*)', c)
787
+ if len(cs) < 2:
788
+ continue
789
+ key, val = cs[:2]
790
+ if key == 'mstd':
791
+ # noise param injected via hparams for now
792
+ hparams.setdefault('magnitude_std', float(val))
793
+ elif key == 'm':
794
+ magnitude = int(val)
795
+ elif key == 'w':
796
+ width = int(val)
797
+ elif key == 'd':
798
+ depth = int(val)
799
+ elif key == 'a':
800
+ alpha = float(val)
801
+ elif key == 'b':
802
+ blended = bool(val)
803
+ else:
804
+ assert False, 'Unknown AugMix config section'
805
+ ops = augmix_ops(magnitude=magnitude, hparams=hparams)
806
+ return AugMixAugment(ops, alpha=alpha, width=width, depth=depth, blended=blended)