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.
- dnt/__init__.py +4 -1
- dnt/analysis/__init__.py +3 -1
- dnt/analysis/count.py +107 -0
- dnt/analysis/interaction2.py +518 -0
- dnt/analysis/position.py +12 -0
- dnt/analysis/stop.py +92 -33
- dnt/analysis/stop2.py +289 -0
- dnt/analysis/stop3.py +758 -0
- dnt/detect/__init__.py +1 -1
- dnt/detect/signal/detector.py +326 -0
- dnt/detect/timestamp.py +105 -0
- dnt/detect/yolov8/detector.py +182 -35
- dnt/detect/yolov8/segmentor.py +171 -0
- dnt/engine/__init__.py +8 -0
- dnt/engine/bbox_interp.py +83 -0
- dnt/engine/bbox_iou.py +20 -0
- dnt/engine/cluster.py +31 -0
- dnt/engine/iob.py +66 -0
- dnt/filter/__init__.py +4 -0
- dnt/filter/filter.py +450 -21
- dnt/label/__init__.py +1 -1
- dnt/label/labeler.py +215 -14
- dnt/label/labeler2.py +631 -0
- dnt/shared/__init__.py +2 -1
- dnt/shared/data/coco.names +0 -0
- dnt/shared/data/openimages.names +0 -0
- dnt/shared/data/voc.names +0 -0
- dnt/shared/download.py +12 -0
- dnt/shared/synhcro.py +150 -0
- dnt/shared/util.py +17 -4
- dnt/third_party/fast-reid/__init__.py +1 -0
- dnt/third_party/fast-reid/configs/Base-AGW.yml +19 -0
- dnt/third_party/fast-reid/configs/Base-MGN.yml +12 -0
- dnt/third_party/fast-reid/configs/Base-SBS.yml +63 -0
- dnt/third_party/fast-reid/configs/Base-bagtricks.yml +76 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/bagtricks_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/DukeMTMC/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT17/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT17/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/bagtricks_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT17/bagtricks_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT17/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT17/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT17/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT20/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT20/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/bagtricks_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT20/bagtricks_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MOT20/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MOT20/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MOT20/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MSMT17/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MSMT17/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R101-ibn.yml +13 -0
- dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MSMT17/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MSMT17/bagtricks_S50.yml +12 -0
- dnt/third_party/fast-reid/configs/MSMT17/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/MSMT17/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/MSMT17/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/MSMT17/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/AGW_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/Market1501/AGW_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/AGW_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/Market1501/AGW_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/bagtricks_vit.yml +88 -0
- dnt/third_party/fast-reid/configs/Market1501/mgn_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/sbs_R101-ibn.yml +12 -0
- dnt/third_party/fast-reid/configs/Market1501/sbs_R50-ibn.yml +11 -0
- dnt/third_party/fast-reid/configs/Market1501/sbs_R50.yml +7 -0
- dnt/third_party/fast-reid/configs/Market1501/sbs_S50.yml +11 -0
- dnt/third_party/fast-reid/configs/VERIWild/bagtricks_R50-ibn.yml +35 -0
- dnt/third_party/fast-reid/configs/VeRi/sbs_R50-ibn.yml +35 -0
- dnt/third_party/fast-reid/configs/VehicleID/bagtricks_R50-ibn.yml +36 -0
- dnt/third_party/fast-reid/configs/__init__.py +0 -0
- dnt/third_party/fast-reid/fast_reid_interfece.py +175 -0
- dnt/third_party/fast-reid/fastreid/__init__.py +6 -0
- dnt/third_party/fast-reid/fastreid/config/__init__.py +15 -0
- dnt/third_party/fast-reid/fastreid/config/config.py +319 -0
- dnt/third_party/fast-reid/fastreid/config/defaults.py +329 -0
- dnt/third_party/fast-reid/fastreid/data/__init__.py +17 -0
- dnt/third_party/fast-reid/fastreid/data/build.py +194 -0
- dnt/third_party/fast-reid/fastreid/data/common.py +58 -0
- dnt/third_party/fast-reid/fastreid/data/data_utils.py +202 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/AirportALERT.py +50 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/__init__.py +43 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/bases.py +183 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/caviara.py +44 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/cuhk03.py +274 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/cuhk_sysu.py +58 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/dukemtmcreid.py +70 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/grid.py +44 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/iLIDS.py +45 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/lpw.py +49 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/market1501.py +89 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/msmt17.py +114 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/pes3d.py +44 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/pku.py +44 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/prai.py +43 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/prid.py +41 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/saivt.py +47 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/sensereid.py +47 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/shinpuhkan.py +48 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/sysu_mm.py +47 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/thermalworld.py +43 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/vehicleid.py +126 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/veri.py +69 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/veriwild.py +140 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/viper.py +45 -0
- dnt/third_party/fast-reid/fastreid/data/datasets/wildtracker.py +59 -0
- dnt/third_party/fast-reid/fastreid/data/samplers/__init__.py +18 -0
- dnt/third_party/fast-reid/fastreid/data/samplers/data_sampler.py +85 -0
- dnt/third_party/fast-reid/fastreid/data/samplers/imbalance_sampler.py +67 -0
- dnt/third_party/fast-reid/fastreid/data/samplers/triplet_sampler.py +260 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/__init__.py +11 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/autoaugment.py +806 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/build.py +100 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/functional.py +180 -0
- dnt/third_party/fast-reid/fastreid/data/transforms/transforms.py +161 -0
- dnt/third_party/fast-reid/fastreid/engine/__init__.py +15 -0
- dnt/third_party/fast-reid/fastreid/engine/defaults.py +490 -0
- dnt/third_party/fast-reid/fastreid/engine/hooks.py +534 -0
- dnt/third_party/fast-reid/fastreid/engine/launch.py +103 -0
- dnt/third_party/fast-reid/fastreid/engine/train_loop.py +357 -0
- dnt/third_party/fast-reid/fastreid/evaluation/__init__.py +6 -0
- dnt/third_party/fast-reid/fastreid/evaluation/clas_evaluator.py +81 -0
- dnt/third_party/fast-reid/fastreid/evaluation/evaluator.py +176 -0
- dnt/third_party/fast-reid/fastreid/evaluation/query_expansion.py +46 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rank.py +200 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/__init__.py +20 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/setup.py +32 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rank_cylib/test_cython.py +106 -0
- dnt/third_party/fast-reid/fastreid/evaluation/reid_evaluation.py +143 -0
- dnt/third_party/fast-reid/fastreid/evaluation/rerank.py +73 -0
- dnt/third_party/fast-reid/fastreid/evaluation/roc.py +90 -0
- dnt/third_party/fast-reid/fastreid/evaluation/testing.py +88 -0
- dnt/third_party/fast-reid/fastreid/layers/__init__.py +19 -0
- dnt/third_party/fast-reid/fastreid/layers/activation.py +59 -0
- dnt/third_party/fast-reid/fastreid/layers/any_softmax.py +80 -0
- dnt/third_party/fast-reid/fastreid/layers/batch_norm.py +205 -0
- dnt/third_party/fast-reid/fastreid/layers/context_block.py +113 -0
- dnt/third_party/fast-reid/fastreid/layers/drop.py +161 -0
- dnt/third_party/fast-reid/fastreid/layers/frn.py +199 -0
- dnt/third_party/fast-reid/fastreid/layers/gather_layer.py +30 -0
- dnt/third_party/fast-reid/fastreid/layers/helpers.py +31 -0
- dnt/third_party/fast-reid/fastreid/layers/non_local.py +54 -0
- dnt/third_party/fast-reid/fastreid/layers/pooling.py +124 -0
- dnt/third_party/fast-reid/fastreid/layers/se_layer.py +25 -0
- dnt/third_party/fast-reid/fastreid/layers/splat.py +109 -0
- dnt/third_party/fast-reid/fastreid/layers/weight_init.py +122 -0
- dnt/third_party/fast-reid/fastreid/modeling/__init__.py +23 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/__init__.py +18 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/build.py +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenet.py +195 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/mobilenetv3.py +283 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/osnet.py +525 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/__init__.py +4 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/config.py +396 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B0_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B1_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B2_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B3_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B4_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet/EN-B5_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/effnet.py +281 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnet.py +596 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-1.6GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-12GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-16GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-200MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-3.2GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-32GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-4.0GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-400MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-6.4GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-600MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-8.0GF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnetx/RegNetX-800MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-1.6GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-12GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-16GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-200MF_dds_8gpu.yaml +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-3.2GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-32GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-4.0GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-400MF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-6.4GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-600MF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-8.0GF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/regnet/regnety/RegNetY-800MF_dds_8gpu.yaml +27 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/repvgg.py +309 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/resnest.py +365 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/resnet.py +364 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/resnext.py +335 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/shufflenet.py +203 -0
- dnt/third_party/fast-reid/fastreid/modeling/backbones/vision_transformer.py +399 -0
- dnt/third_party/fast-reid/fastreid/modeling/heads/__init__.py +11 -0
- dnt/third_party/fast-reid/fastreid/modeling/heads/build.py +25 -0
- dnt/third_party/fast-reid/fastreid/modeling/heads/clas_head.py +36 -0
- dnt/third_party/fast-reid/fastreid/modeling/heads/embedding_head.py +151 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/__init__.py +12 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/circle_loss.py +71 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/cross_entroy_loss.py +54 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/focal_loss.py +92 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/triplet_loss.py +113 -0
- dnt/third_party/fast-reid/fastreid/modeling/losses/utils.py +48 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/__init__.py +14 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/baseline.py +188 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/build.py +26 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/distiller.py +140 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/mgn.py +394 -0
- dnt/third_party/fast-reid/fastreid/modeling/meta_arch/moco.py +126 -0
- dnt/third_party/fast-reid/fastreid/solver/__init__.py +8 -0
- dnt/third_party/fast-reid/fastreid/solver/build.py +348 -0
- dnt/third_party/fast-reid/fastreid/solver/lr_scheduler.py +66 -0
- dnt/third_party/fast-reid/fastreid/solver/optim/__init__.py +10 -0
- dnt/third_party/fast-reid/fastreid/solver/optim/lamb.py +123 -0
- dnt/third_party/fast-reid/fastreid/solver/optim/radam.py +149 -0
- dnt/third_party/fast-reid/fastreid/solver/optim/swa.py +246 -0
- dnt/third_party/fast-reid/fastreid/utils/__init__.py +6 -0
- dnt/third_party/fast-reid/fastreid/utils/checkpoint.py +503 -0
- dnt/third_party/fast-reid/fastreid/utils/collect_env.py +158 -0
- dnt/third_party/fast-reid/fastreid/utils/comm.py +255 -0
- dnt/third_party/fast-reid/fastreid/utils/compute_dist.py +200 -0
- dnt/third_party/fast-reid/fastreid/utils/env.py +119 -0
- dnt/third_party/fast-reid/fastreid/utils/events.py +461 -0
- dnt/third_party/fast-reid/fastreid/utils/faiss_utils.py +127 -0
- dnt/third_party/fast-reid/fastreid/utils/file_io.py +520 -0
- dnt/third_party/fast-reid/fastreid/utils/history_buffer.py +71 -0
- dnt/third_party/fast-reid/fastreid/utils/logger.py +211 -0
- dnt/third_party/fast-reid/fastreid/utils/params.py +103 -0
- dnt/third_party/fast-reid/fastreid/utils/precision_bn.py +94 -0
- dnt/third_party/fast-reid/fastreid/utils/registry.py +66 -0
- dnt/third_party/fast-reid/fastreid/utils/summary.py +120 -0
- dnt/third_party/fast-reid/fastreid/utils/timer.py +68 -0
- dnt/third_party/fast-reid/fastreid/utils/visualizer.py +278 -0
- dnt/track/__init__.py +3 -1
- dnt/track/botsort/__init__.py +4 -0
- dnt/track/botsort/bot_tracker/__init__.py +3 -0
- dnt/track/botsort/bot_tracker/basetrack.py +60 -0
- dnt/track/botsort/bot_tracker/bot_sort.py +473 -0
- dnt/track/botsort/bot_tracker/gmc.py +316 -0
- dnt/track/botsort/bot_tracker/kalman_filter.py +269 -0
- dnt/track/botsort/bot_tracker/matching.py +194 -0
- dnt/track/botsort/bot_tracker/mc_bot_sort.py +505 -0
- dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/evaluation.py +14 -4
- dnt/track/{dsort/utils → botsort/bot_tracker/tracking_utils}/io.py +19 -36
- dnt/track/botsort/bot_tracker/tracking_utils/timer.py +37 -0
- dnt/track/botsort/inference.py +96 -0
- dnt/track/config.py +120 -0
- dnt/track/dsort/configs/bagtricks_R50.yml +7 -0
- dnt/track/dsort/configs/deep_sort.yaml +0 -0
- dnt/track/dsort/configs/fastreid.yaml +1 -1
- dnt/track/dsort/deep_sort/deep/checkpoint/ckpt.t7 +0 -0
- dnt/track/dsort/deep_sort/deep/feature_extractor.py +87 -8
- dnt/track/dsort/deep_sort/deep_sort.py +31 -21
- dnt/track/dsort/deep_sort/sort/detection.py +2 -1
- dnt/track/dsort/deep_sort/sort/iou_matching.py +0 -2
- dnt/track/dsort/deep_sort/sort/linear_assignment.py +0 -3
- dnt/track/dsort/deep_sort/sort/nn_matching.py +5 -5
- dnt/track/dsort/deep_sort/sort/preprocessing.py +1 -2
- dnt/track/dsort/deep_sort/sort/track.py +2 -1
- dnt/track/dsort/deep_sort/sort/tracker.py +1 -1
- dnt/track/dsort/dsort.py +44 -27
- dnt/track/re_class.py +117 -0
- dnt/track/sort/sort.py +9 -7
- dnt/track/tracker.py +225 -20
- dnt-0.3.1.8.dist-info/METADATA +117 -0
- dnt-0.3.1.8.dist-info/RECORD +315 -0
- {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info}/WHEEL +1 -1
- dnt/track/dsort/deep_sort/deep/evaluate.py +0 -15
- dnt/track/dsort/deep_sort/deep/original_model.py +0 -106
- dnt/track/dsort/deep_sort/deep/test.py +0 -77
- dnt/track/dsort/deep_sort/deep/train.py +0 -189
- dnt/track/dsort/utils/asserts.py +0 -13
- dnt/track/dsort/utils/draw.py +0 -36
- dnt/track/dsort/utils/json_logger.py +0 -383
- dnt/track/dsort/utils/log.py +0 -17
- dnt/track/dsort/utils/parser.py +0 -35
- dnt/track/dsort/utils/tools.py +0 -39
- dnt-0.2.1.dist-info/METADATA +0 -35
- dnt-0.2.1.dist-info/RECORD +0 -60
- /dnt/{track/dsort/utils → third_party/fast-reid/checkpoint}/__init__.py +0 -0
- {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info/licenses}/LICENSE +0 -0
- {dnt-0.2.1.dist-info → dnt-0.3.1.8.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# ref: https://github.com/CaoWGG/RepVGG/blob/develop/repvgg.py
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import torch
|
|
9
|
+
import torch.nn as nn
|
|
10
|
+
|
|
11
|
+
from fastreid.layers import *
|
|
12
|
+
from fastreid.utils.checkpoint import get_missing_parameters_message, get_unexpected_parameters_message
|
|
13
|
+
from .build import BACKBONE_REGISTRY
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def deploy(self, mode=False):
|
|
19
|
+
self.deploying = mode
|
|
20
|
+
for module in self.children():
|
|
21
|
+
if hasattr(module, 'deploying'):
|
|
22
|
+
module.deploy(mode)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
nn.Sequential.deploying = False
|
|
26
|
+
nn.Sequential.deploy = deploy
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def conv_bn(norm_type, in_channels, out_channels, kernel_size, stride, padding, groups=1):
|
|
30
|
+
result = nn.Sequential()
|
|
31
|
+
result.add_module('conv', nn.Conv2d(in_channels=in_channels, out_channels=out_channels,
|
|
32
|
+
kernel_size=kernel_size, stride=stride, padding=padding, groups=groups,
|
|
33
|
+
bias=False))
|
|
34
|
+
result.add_module('bn', get_norm(norm_type, out_channels))
|
|
35
|
+
return result
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class RepVGGBlock(nn.Module):
|
|
39
|
+
|
|
40
|
+
def __init__(self, in_channels, out_channels, norm_type, kernel_size,
|
|
41
|
+
stride=1, padding=0, groups=1):
|
|
42
|
+
super(RepVGGBlock, self).__init__()
|
|
43
|
+
self.deploying = False
|
|
44
|
+
|
|
45
|
+
self.groups = groups
|
|
46
|
+
self.in_channels = in_channels
|
|
47
|
+
|
|
48
|
+
assert kernel_size == 3
|
|
49
|
+
assert padding == 1
|
|
50
|
+
|
|
51
|
+
padding_11 = padding - kernel_size // 2
|
|
52
|
+
|
|
53
|
+
self.nonlinearity = nn.ReLU()
|
|
54
|
+
|
|
55
|
+
self.in_channels = in_channels
|
|
56
|
+
self.in_channels = in_channels
|
|
57
|
+
self.kernel_size = kernel_size
|
|
58
|
+
self.stride = stride
|
|
59
|
+
self.padding = padding
|
|
60
|
+
self.groups = groups
|
|
61
|
+
|
|
62
|
+
self.register_parameter('fused_weight', None)
|
|
63
|
+
self.register_parameter('fused_bias', None)
|
|
64
|
+
|
|
65
|
+
self.rbr_identity = get_norm(norm_type, in_channels) if out_channels == in_channels and stride == 1 else None
|
|
66
|
+
self.rbr_dense = conv_bn(norm_type, in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size,
|
|
67
|
+
stride=stride, padding=padding, groups=groups)
|
|
68
|
+
self.rbr_1x1 = conv_bn(norm_type, in_channels=in_channels, out_channels=out_channels, kernel_size=1,
|
|
69
|
+
stride=stride, padding=padding_11, groups=groups)
|
|
70
|
+
|
|
71
|
+
def forward(self, inputs):
|
|
72
|
+
if self.deploying:
|
|
73
|
+
assert self.fused_weight is not None and self.fused_bias is not None, \
|
|
74
|
+
"Make deploy mode=True to generate fused weight and fused bias first"
|
|
75
|
+
fused_out = self.nonlinearity(torch.nn.functional.conv2d(
|
|
76
|
+
inputs, self.fused_weight, self.fused_bias, self.stride, self.padding, 1, self.groups))
|
|
77
|
+
return fused_out
|
|
78
|
+
|
|
79
|
+
if self.rbr_identity is None:
|
|
80
|
+
id_out = 0
|
|
81
|
+
else:
|
|
82
|
+
id_out = self.rbr_identity(inputs)
|
|
83
|
+
out = self.nonlinearity(self.rbr_dense(inputs) + self.rbr_1x1(inputs) + id_out)
|
|
84
|
+
|
|
85
|
+
return out
|
|
86
|
+
|
|
87
|
+
def get_equivalent_kernel_bias(self):
|
|
88
|
+
kernel3x3, bias3x3 = self._fuse_bn_tensor(self.rbr_dense)
|
|
89
|
+
kernel1x1, bias1x1 = self._fuse_bn_tensor(self.rbr_1x1)
|
|
90
|
+
kernelid, biasid = self._fuse_bn_tensor(self.rbr_identity)
|
|
91
|
+
return kernel3x3 + self._pad_1x1_to_3x3_tensor(kernel1x1) + kernelid, bias3x3 + bias1x1 + biasid
|
|
92
|
+
|
|
93
|
+
def _pad_1x1_to_3x3_tensor(self, kernel1x1):
|
|
94
|
+
if kernel1x1 is None:
|
|
95
|
+
return 0
|
|
96
|
+
else:
|
|
97
|
+
return torch.nn.functional.pad(kernel1x1, [1, 1, 1, 1])
|
|
98
|
+
|
|
99
|
+
def _fuse_bn_tensor(self, branch):
|
|
100
|
+
if branch is None:
|
|
101
|
+
return 0, 0
|
|
102
|
+
if isinstance(branch, nn.Sequential):
|
|
103
|
+
kernel = branch.conv.weight
|
|
104
|
+
running_mean = branch.bn.running_mean
|
|
105
|
+
running_var = branch.bn.running_var
|
|
106
|
+
gamma = branch.bn.weight
|
|
107
|
+
beta = branch.bn.bias
|
|
108
|
+
eps = branch.bn.eps
|
|
109
|
+
else:
|
|
110
|
+
assert branch.__class__.__name__.find('BatchNorm') != -1
|
|
111
|
+
if not hasattr(self, 'id_tensor'):
|
|
112
|
+
input_dim = self.in_channels // self.groups
|
|
113
|
+
kernel_value = np.zeros((self.in_channels, input_dim, 3, 3), dtype=np.float32)
|
|
114
|
+
for i in range(self.in_channels):
|
|
115
|
+
kernel_value[i, i % input_dim, 1, 1] = 1
|
|
116
|
+
self.id_tensor = torch.from_numpy(kernel_value).to(branch.weight.device)
|
|
117
|
+
kernel = self.id_tensor
|
|
118
|
+
running_mean = branch.running_mean
|
|
119
|
+
running_var = branch.running_var
|
|
120
|
+
gamma = branch.weight
|
|
121
|
+
beta = branch.bias
|
|
122
|
+
eps = branch.eps
|
|
123
|
+
std = (running_var + eps).sqrt()
|
|
124
|
+
t = (gamma / std).reshape(-1, 1, 1, 1)
|
|
125
|
+
return kernel * t, beta - running_mean * gamma / std
|
|
126
|
+
|
|
127
|
+
def deploy(self, mode=False):
|
|
128
|
+
self.deploying = mode
|
|
129
|
+
if mode:
|
|
130
|
+
fused_weight, fused_bias = self.get_equivalent_kernel_bias()
|
|
131
|
+
self.register_parameter('fused_weight', nn.Parameter(fused_weight))
|
|
132
|
+
self.register_parameter('fused_bias', nn.Parameter(fused_bias))
|
|
133
|
+
del self.rbr_identity, self.rbr_1x1, self.rbr_dense
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class RepVGG(nn.Module):
|
|
137
|
+
|
|
138
|
+
def __init__(self, last_stride, norm_type, num_blocks, width_multiplier=None, override_groups_map=None):
|
|
139
|
+
super(RepVGG, self).__init__()
|
|
140
|
+
|
|
141
|
+
assert len(width_multiplier) == 4
|
|
142
|
+
|
|
143
|
+
self.deploying = False
|
|
144
|
+
self.override_groups_map = override_groups_map or dict()
|
|
145
|
+
|
|
146
|
+
assert 0 not in self.override_groups_map
|
|
147
|
+
|
|
148
|
+
self.in_planes = min(64, int(64 * width_multiplier[0]))
|
|
149
|
+
|
|
150
|
+
self.stage0 = RepVGGBlock(in_channels=3, out_channels=self.in_planes, norm_type=norm_type,
|
|
151
|
+
kernel_size=3, stride=2, padding=1)
|
|
152
|
+
self.cur_layer_idx = 1
|
|
153
|
+
self.stage1 = self._make_stage(int(64 * width_multiplier[0]), norm_type, num_blocks[0], stride=2)
|
|
154
|
+
self.stage2 = self._make_stage(int(128 * width_multiplier[1]), norm_type, num_blocks[1], stride=2)
|
|
155
|
+
self.stage3 = self._make_stage(int(256 * width_multiplier[2]), norm_type, num_blocks[2], stride=2)
|
|
156
|
+
self.stage4 = self._make_stage(int(512 * width_multiplier[3]), norm_type, num_blocks[3], stride=last_stride)
|
|
157
|
+
|
|
158
|
+
def _make_stage(self, planes, norm_type, num_blocks, stride):
|
|
159
|
+
strides = [stride] + [1] * (num_blocks - 1)
|
|
160
|
+
blocks = []
|
|
161
|
+
for stride in strides:
|
|
162
|
+
cur_groups = self.override_groups_map.get(self.cur_layer_idx, 1)
|
|
163
|
+
blocks.append(RepVGGBlock(in_channels=self.in_planes, out_channels=planes, norm_type=norm_type,
|
|
164
|
+
kernel_size=3, stride=stride, padding=1, groups=cur_groups))
|
|
165
|
+
self.in_planes = planes
|
|
166
|
+
self.cur_layer_idx += 1
|
|
167
|
+
return nn.Sequential(*blocks)
|
|
168
|
+
|
|
169
|
+
def deploy(self, mode=False):
|
|
170
|
+
self.deploying = mode
|
|
171
|
+
for module in self.children():
|
|
172
|
+
if hasattr(module, 'deploying'):
|
|
173
|
+
module.deploy(mode)
|
|
174
|
+
|
|
175
|
+
def forward(self, x):
|
|
176
|
+
out = self.stage0(x)
|
|
177
|
+
out = self.stage1(out)
|
|
178
|
+
out = self.stage2(out)
|
|
179
|
+
out = self.stage3(out)
|
|
180
|
+
out = self.stage4(out)
|
|
181
|
+
return out
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
optional_groupwise_layers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]
|
|
185
|
+
g2_map = {l: 2 for l in optional_groupwise_layers}
|
|
186
|
+
g4_map = {l: 4 for l in optional_groupwise_layers}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def create_RepVGG_A0(last_stride, norm_type):
|
|
190
|
+
return RepVGG(last_stride, norm_type, num_blocks=[2, 4, 14, 1],
|
|
191
|
+
width_multiplier=[0.75, 0.75, 0.75, 2.5], override_groups_map=None)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def create_RepVGG_A1(last_stride, norm_type):
|
|
195
|
+
return RepVGG(last_stride, norm_type, num_blocks=[2, 4, 14, 1],
|
|
196
|
+
width_multiplier=[1, 1, 1, 2.5], override_groups_map=None)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def create_RepVGG_A2(last_stride, norm_type):
|
|
200
|
+
return RepVGG(last_stride, norm_type, num_blocks=[2, 4, 14, 1],
|
|
201
|
+
width_multiplier=[1.5, 1.5, 1.5, 2.75], override_groups_map=None)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def create_RepVGG_B0(last_stride, norm_type):
|
|
205
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
206
|
+
width_multiplier=[1, 1, 1, 2.5], override_groups_map=None)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def create_RepVGG_B1(last_stride, norm_type):
|
|
210
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
211
|
+
width_multiplier=[2, 2, 2, 4], override_groups_map=None)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def create_RepVGG_B1g2(last_stride, norm_type):
|
|
215
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
216
|
+
width_multiplier=[2, 2, 2, 4], override_groups_map=g2_map)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def create_RepVGG_B1g4(last_stride, norm_type):
|
|
220
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
221
|
+
width_multiplier=[2, 2, 2, 4], override_groups_map=g4_map)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def create_RepVGG_B2(last_stride, norm_type):
|
|
225
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
226
|
+
width_multiplier=[2.5, 2.5, 2.5, 5], override_groups_map=None)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def create_RepVGG_B2g2(last_stride, norm_type):
|
|
230
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
231
|
+
width_multiplier=[2.5, 2.5, 2.5, 5], override_groups_map=g2_map)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def create_RepVGG_B2g4(last_stride, norm_type):
|
|
235
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
236
|
+
width_multiplier=[2.5, 2.5, 2.5, 5], override_groups_map=g4_map)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def create_RepVGG_B3(last_stride, norm_type):
|
|
240
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
241
|
+
width_multiplier=[3, 3, 3, 5], override_groups_map=None)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def create_RepVGG_B3g2(last_stride, norm_type):
|
|
245
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
246
|
+
width_multiplier=[3, 3, 3, 5], override_groups_map=g2_map)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def create_RepVGG_B3g4(last_stride, norm_type):
|
|
250
|
+
return RepVGG(last_stride, norm_type, num_blocks=[4, 6, 16, 1],
|
|
251
|
+
width_multiplier=[3, 3, 3, 5], override_groups_map=g4_map)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@BACKBONE_REGISTRY.register()
|
|
255
|
+
def build_repvgg_backbone(cfg):
|
|
256
|
+
"""
|
|
257
|
+
Create a RepVGG instance from config.
|
|
258
|
+
Returns:
|
|
259
|
+
RepVGG: a :class: `RepVGG` instance.
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
# fmt: off
|
|
263
|
+
pretrain = cfg.MODEL.BACKBONE.PRETRAIN
|
|
264
|
+
pretrain_path = cfg.MODEL.BACKBONE.PRETRAIN_PATH
|
|
265
|
+
last_stride = cfg.MODEL.BACKBONE.LAST_STRIDE
|
|
266
|
+
bn_norm = cfg.MODEL.BACKBONE.NORM
|
|
267
|
+
depth = cfg.MODEL.BACKBONE.DEPTH
|
|
268
|
+
# fmt: on
|
|
269
|
+
|
|
270
|
+
func_dict = {
|
|
271
|
+
'A0': create_RepVGG_A0,
|
|
272
|
+
'A1': create_RepVGG_A1,
|
|
273
|
+
'A2': create_RepVGG_A2,
|
|
274
|
+
'B0': create_RepVGG_B0,
|
|
275
|
+
'B1': create_RepVGG_B1,
|
|
276
|
+
'B1g2': create_RepVGG_B1g2,
|
|
277
|
+
'B1g4': create_RepVGG_B1g4,
|
|
278
|
+
'B2': create_RepVGG_B2,
|
|
279
|
+
'B2g2': create_RepVGG_B2g2,
|
|
280
|
+
'B2g4': create_RepVGG_B2g4,
|
|
281
|
+
'B3': create_RepVGG_B3,
|
|
282
|
+
'B3g2': create_RepVGG_B3g2,
|
|
283
|
+
'B3g4': create_RepVGG_B3g4,
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
model = func_dict[depth](last_stride, bn_norm)
|
|
287
|
+
|
|
288
|
+
if pretrain:
|
|
289
|
+
try:
|
|
290
|
+
state_dict = torch.load(pretrain_path, map_location=torch.device("cpu"))
|
|
291
|
+
logger.info(f"Loading pretrained model from {pretrain_path}")
|
|
292
|
+
except FileNotFoundError as e:
|
|
293
|
+
logger.info(f'{pretrain_path} is not found! Please check this path.')
|
|
294
|
+
raise e
|
|
295
|
+
except KeyError as e:
|
|
296
|
+
logger.info("State dict keys error! Please check the state dict.")
|
|
297
|
+
raise e
|
|
298
|
+
|
|
299
|
+
incompatible = model.load_state_dict(state_dict, strict=False)
|
|
300
|
+
if incompatible.missing_keys:
|
|
301
|
+
logger.info(
|
|
302
|
+
get_missing_parameters_message(incompatible.missing_keys)
|
|
303
|
+
)
|
|
304
|
+
if incompatible.unexpected_keys:
|
|
305
|
+
logger.info(
|
|
306
|
+
get_unexpected_parameters_message(incompatible.unexpected_keys)
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
return model
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# based on:
|
|
3
|
+
# https://github.com/zhanghang1989/ResNeSt/blob/master/resnest/torch/models/resnest.py
|
|
4
|
+
"""ResNeSt models"""
|
|
5
|
+
|
|
6
|
+
import logging
|
|
7
|
+
import math
|
|
8
|
+
|
|
9
|
+
import torch
|
|
10
|
+
from torch import nn
|
|
11
|
+
|
|
12
|
+
from fastreid.layers import SplAtConv2d, get_norm, DropBlock2D
|
|
13
|
+
from fastreid.utils.checkpoint import get_unexpected_parameters_message, get_missing_parameters_message
|
|
14
|
+
from .build import BACKBONE_REGISTRY
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
_url_format = 'https://github.com/zhanghang1989/ResNeSt/releases/download/weights_step1/{}-{}.pth'
|
|
18
|
+
|
|
19
|
+
_model_sha256 = {name: checksum for checksum, name in [
|
|
20
|
+
('528c19ca', 'resnest50'),
|
|
21
|
+
('22405ba7', 'resnest101'),
|
|
22
|
+
('75117900', 'resnest200'),
|
|
23
|
+
('0cc87c48', 'resnest269'),
|
|
24
|
+
]}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def short_hash(name):
|
|
28
|
+
if name not in _model_sha256:
|
|
29
|
+
raise ValueError('Pretrained model for {name} is not available.'.format(name=name))
|
|
30
|
+
return _model_sha256[name][:8]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
model_urls = {name: _url_format.format(name, short_hash(name)) for
|
|
34
|
+
name in _model_sha256.keys()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Bottleneck(nn.Module):
|
|
39
|
+
"""ResNet Bottleneck
|
|
40
|
+
"""
|
|
41
|
+
# pylint: disable=unused-argument
|
|
42
|
+
expansion = 4
|
|
43
|
+
|
|
44
|
+
def __init__(self, inplanes, planes, stride=1, downsample=None,
|
|
45
|
+
radix=1, cardinality=1, bottleneck_width=64,
|
|
46
|
+
avd=False, avd_first=False, dilation=1, is_first=False,
|
|
47
|
+
rectified_conv=False, rectify_avg=False,
|
|
48
|
+
norm_layer=None, dropblock_prob=0.0, last_gamma=False):
|
|
49
|
+
super(Bottleneck, self).__init__()
|
|
50
|
+
group_width = int(planes * (bottleneck_width / 64.)) * cardinality
|
|
51
|
+
self.conv1 = nn.Conv2d(inplanes, group_width, kernel_size=1, bias=False)
|
|
52
|
+
self.bn1 = get_norm(norm_layer, group_width)
|
|
53
|
+
self.dropblock_prob = dropblock_prob
|
|
54
|
+
self.radix = radix
|
|
55
|
+
self.avd = avd and (stride > 1 or is_first)
|
|
56
|
+
self.avd_first = avd_first
|
|
57
|
+
|
|
58
|
+
if self.avd:
|
|
59
|
+
self.avd_layer = nn.AvgPool2d(3, stride, padding=1)
|
|
60
|
+
stride = 1
|
|
61
|
+
|
|
62
|
+
if dropblock_prob > 0.0:
|
|
63
|
+
self.dropblock1 = DropBlock2D(dropblock_prob, 3)
|
|
64
|
+
if radix == 1:
|
|
65
|
+
self.dropblock2 = DropBlock2D(dropblock_prob, 3)
|
|
66
|
+
self.dropblock3 = DropBlock2D(dropblock_prob, 3)
|
|
67
|
+
|
|
68
|
+
if radix >= 1:
|
|
69
|
+
self.conv2 = SplAtConv2d(
|
|
70
|
+
group_width, group_width, kernel_size=3,
|
|
71
|
+
stride=stride, padding=dilation,
|
|
72
|
+
dilation=dilation, groups=cardinality, bias=False,
|
|
73
|
+
radix=radix, rectify=rectified_conv,
|
|
74
|
+
rectify_avg=rectify_avg,
|
|
75
|
+
norm_layer=norm_layer,
|
|
76
|
+
dropblock_prob=dropblock_prob)
|
|
77
|
+
elif rectified_conv:
|
|
78
|
+
from rfconv import RFConv2d
|
|
79
|
+
self.conv2 = RFConv2d(
|
|
80
|
+
group_width, group_width, kernel_size=3, stride=stride,
|
|
81
|
+
padding=dilation, dilation=dilation,
|
|
82
|
+
groups=cardinality, bias=False,
|
|
83
|
+
average_mode=rectify_avg)
|
|
84
|
+
self.bn2 = get_norm(norm_layer, group_width)
|
|
85
|
+
else:
|
|
86
|
+
self.conv2 = nn.Conv2d(
|
|
87
|
+
group_width, group_width, kernel_size=3, stride=stride,
|
|
88
|
+
padding=dilation, dilation=dilation,
|
|
89
|
+
groups=cardinality, bias=False)
|
|
90
|
+
self.bn2 = get_norm(norm_layer, group_width)
|
|
91
|
+
|
|
92
|
+
self.conv3 = nn.Conv2d(
|
|
93
|
+
group_width, planes * 4, kernel_size=1, bias=False)
|
|
94
|
+
self.bn3 = get_norm(norm_layer, planes * 4)
|
|
95
|
+
|
|
96
|
+
if last_gamma:
|
|
97
|
+
from torch.nn.init import zeros_
|
|
98
|
+
zeros_(self.bn3.weight)
|
|
99
|
+
self.relu = nn.ReLU(inplace=True)
|
|
100
|
+
self.downsample = downsample
|
|
101
|
+
self.dilation = dilation
|
|
102
|
+
self.stride = stride
|
|
103
|
+
|
|
104
|
+
def forward(self, x):
|
|
105
|
+
residual = x
|
|
106
|
+
|
|
107
|
+
out = self.conv1(x)
|
|
108
|
+
out = self.bn1(out)
|
|
109
|
+
if self.dropblock_prob > 0.0:
|
|
110
|
+
out = self.dropblock1(out)
|
|
111
|
+
out = self.relu(out)
|
|
112
|
+
|
|
113
|
+
if self.avd and self.avd_first:
|
|
114
|
+
out = self.avd_layer(out)
|
|
115
|
+
|
|
116
|
+
out = self.conv2(out)
|
|
117
|
+
if self.radix == 0:
|
|
118
|
+
out = self.bn2(out)
|
|
119
|
+
if self.dropblock_prob > 0.0:
|
|
120
|
+
out = self.dropblock2(out)
|
|
121
|
+
out = self.relu(out)
|
|
122
|
+
|
|
123
|
+
if self.avd and not self.avd_first:
|
|
124
|
+
out = self.avd_layer(out)
|
|
125
|
+
|
|
126
|
+
out = self.conv3(out)
|
|
127
|
+
out = self.bn3(out)
|
|
128
|
+
if self.dropblock_prob > 0.0:
|
|
129
|
+
out = self.dropblock3(out)
|
|
130
|
+
|
|
131
|
+
if self.downsample is not None:
|
|
132
|
+
residual = self.downsample(x)
|
|
133
|
+
|
|
134
|
+
out += residual
|
|
135
|
+
out = self.relu(out)
|
|
136
|
+
|
|
137
|
+
return out
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class ResNeSt(nn.Module):
|
|
141
|
+
"""ResNet Variants
|
|
142
|
+
Parameters
|
|
143
|
+
----------
|
|
144
|
+
block : Block
|
|
145
|
+
Class for the residual block. Options are BasicBlockV1, BottleneckV1.
|
|
146
|
+
layers : list of int
|
|
147
|
+
Numbers of layers in each block
|
|
148
|
+
classes : int, default 1000
|
|
149
|
+
Number of classification classes.
|
|
150
|
+
dilated : bool, default False
|
|
151
|
+
Applying dilation strategy to pretrained ResNet yielding a stride-8 model,
|
|
152
|
+
typically used in Semantic Segmentation.
|
|
153
|
+
norm_layer : object
|
|
154
|
+
Normalization layer used in backbone network (default: :class:`mxnet.gluon.nn.BatchNorm`;
|
|
155
|
+
for Synchronized Cross-GPU BachNormalization).
|
|
156
|
+
Reference:
|
|
157
|
+
- He, Kaiming, et al. "Deep residual learning for image recognition." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.
|
|
158
|
+
- Yu, Fisher, and Vladlen Koltun. "Multi-scale context aggregation by dilated convolutions."
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
# pylint: disable=unused-variable
|
|
162
|
+
def __init__(self, last_stride, block, layers, radix=1, groups=1, bottleneck_width=64,
|
|
163
|
+
dilated=False, dilation=1,
|
|
164
|
+
deep_stem=False, stem_width=64, avg_down=False,
|
|
165
|
+
rectified_conv=False, rectify_avg=False,
|
|
166
|
+
avd=False, avd_first=False,
|
|
167
|
+
final_drop=0.0, dropblock_prob=0,
|
|
168
|
+
last_gamma=False, norm_layer="BN"):
|
|
169
|
+
if last_stride == 1: dilation = 2
|
|
170
|
+
|
|
171
|
+
self.cardinality = groups
|
|
172
|
+
self.bottleneck_width = bottleneck_width
|
|
173
|
+
# ResNet-D params
|
|
174
|
+
self.inplanes = stem_width * 2 if deep_stem else 64
|
|
175
|
+
self.avg_down = avg_down
|
|
176
|
+
self.last_gamma = last_gamma
|
|
177
|
+
# ResNeSt params
|
|
178
|
+
self.radix = radix
|
|
179
|
+
self.avd = avd
|
|
180
|
+
self.avd_first = avd_first
|
|
181
|
+
|
|
182
|
+
super().__init__()
|
|
183
|
+
self.rectified_conv = rectified_conv
|
|
184
|
+
self.rectify_avg = rectify_avg
|
|
185
|
+
if rectified_conv:
|
|
186
|
+
from rfconv import RFConv2d
|
|
187
|
+
conv_layer = RFConv2d
|
|
188
|
+
else:
|
|
189
|
+
conv_layer = nn.Conv2d
|
|
190
|
+
conv_kwargs = {'average_mode': rectify_avg} if rectified_conv else {}
|
|
191
|
+
if deep_stem:
|
|
192
|
+
self.conv1 = nn.Sequential(
|
|
193
|
+
conv_layer(3, stem_width, kernel_size=3, stride=2, padding=1, bias=False, **conv_kwargs),
|
|
194
|
+
get_norm(norm_layer, stem_width),
|
|
195
|
+
nn.ReLU(inplace=True),
|
|
196
|
+
conv_layer(stem_width, stem_width, kernel_size=3, stride=1, padding=1, bias=False, **conv_kwargs),
|
|
197
|
+
get_norm(norm_layer, stem_width),
|
|
198
|
+
nn.ReLU(inplace=True),
|
|
199
|
+
conv_layer(stem_width, stem_width * 2, kernel_size=3, stride=1, padding=1, bias=False, **conv_kwargs),
|
|
200
|
+
)
|
|
201
|
+
else:
|
|
202
|
+
self.conv1 = conv_layer(3, 64, kernel_size=7, stride=2, padding=3,
|
|
203
|
+
bias=False, **conv_kwargs)
|
|
204
|
+
self.bn1 = get_norm(norm_layer, self.inplanes)
|
|
205
|
+
self.relu = nn.ReLU(inplace=True)
|
|
206
|
+
self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
|
|
207
|
+
self.layer1 = self._make_layer(block, 64, layers[0], norm_layer=norm_layer, is_first=False)
|
|
208
|
+
self.layer2 = self._make_layer(block, 128, layers[1], stride=2, norm_layer=norm_layer)
|
|
209
|
+
if dilated or dilation == 4:
|
|
210
|
+
self.layer3 = self._make_layer(block, 256, layers[2], stride=1,
|
|
211
|
+
dilation=2, norm_layer=norm_layer,
|
|
212
|
+
dropblock_prob=dropblock_prob)
|
|
213
|
+
self.layer4 = self._make_layer(block, 512, layers[3], stride=1,
|
|
214
|
+
dilation=4, norm_layer=norm_layer,
|
|
215
|
+
dropblock_prob=dropblock_prob)
|
|
216
|
+
elif dilation == 2:
|
|
217
|
+
self.layer3 = self._make_layer(block, 256, layers[2], stride=2,
|
|
218
|
+
dilation=1, norm_layer=norm_layer,
|
|
219
|
+
dropblock_prob=dropblock_prob)
|
|
220
|
+
self.layer4 = self._make_layer(block, 512, layers[3], stride=1,
|
|
221
|
+
dilation=2, norm_layer=norm_layer,
|
|
222
|
+
dropblock_prob=dropblock_prob)
|
|
223
|
+
else:
|
|
224
|
+
self.layer3 = self._make_layer(block, 256, layers[2], stride=2,
|
|
225
|
+
norm_layer=norm_layer,
|
|
226
|
+
dropblock_prob=dropblock_prob)
|
|
227
|
+
self.layer4 = self._make_layer(block, 512, layers[3], stride=2,
|
|
228
|
+
norm_layer=norm_layer,
|
|
229
|
+
dropblock_prob=dropblock_prob)
|
|
230
|
+
self.drop = nn.Dropout(final_drop) if final_drop > 0.0 else None
|
|
231
|
+
|
|
232
|
+
for m in self.modules():
|
|
233
|
+
if isinstance(m, nn.Conv2d):
|
|
234
|
+
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
|
|
235
|
+
m.weight.data.normal_(0, math.sqrt(2. / n))
|
|
236
|
+
|
|
237
|
+
def _make_layer(self, block, planes, blocks, stride=1, dilation=1, norm_layer=None,
|
|
238
|
+
dropblock_prob=0.0, is_first=True):
|
|
239
|
+
downsample = None
|
|
240
|
+
if stride != 1 or self.inplanes != planes * block.expansion:
|
|
241
|
+
down_layers = []
|
|
242
|
+
if self.avg_down:
|
|
243
|
+
if dilation == 1:
|
|
244
|
+
down_layers.append(nn.AvgPool2d(kernel_size=stride, stride=stride,
|
|
245
|
+
ceil_mode=True, count_include_pad=False))
|
|
246
|
+
else:
|
|
247
|
+
down_layers.append(nn.AvgPool2d(kernel_size=1, stride=1,
|
|
248
|
+
ceil_mode=True, count_include_pad=False))
|
|
249
|
+
down_layers.append(nn.Conv2d(self.inplanes, planes * block.expansion,
|
|
250
|
+
kernel_size=1, stride=1, bias=False))
|
|
251
|
+
else:
|
|
252
|
+
down_layers.append(nn.Conv2d(self.inplanes, planes * block.expansion,
|
|
253
|
+
kernel_size=1, stride=stride, bias=False))
|
|
254
|
+
down_layers.append(get_norm(norm_layer, planes * block.expansion))
|
|
255
|
+
downsample = nn.Sequential(*down_layers)
|
|
256
|
+
|
|
257
|
+
layers = []
|
|
258
|
+
if dilation == 1 or dilation == 2:
|
|
259
|
+
layers.append(block(self.inplanes, planes, stride, downsample=downsample,
|
|
260
|
+
radix=self.radix, cardinality=self.cardinality,
|
|
261
|
+
bottleneck_width=self.bottleneck_width,
|
|
262
|
+
avd=self.avd, avd_first=self.avd_first,
|
|
263
|
+
dilation=1, is_first=is_first, rectified_conv=self.rectified_conv,
|
|
264
|
+
rectify_avg=self.rectify_avg,
|
|
265
|
+
norm_layer=norm_layer, dropblock_prob=dropblock_prob,
|
|
266
|
+
last_gamma=self.last_gamma))
|
|
267
|
+
elif dilation == 4:
|
|
268
|
+
layers.append(block(self.inplanes, planes, stride, downsample=downsample,
|
|
269
|
+
radix=self.radix, cardinality=self.cardinality,
|
|
270
|
+
bottleneck_width=self.bottleneck_width,
|
|
271
|
+
avd=self.avd, avd_first=self.avd_first,
|
|
272
|
+
dilation=2, is_first=is_first, rectified_conv=self.rectified_conv,
|
|
273
|
+
rectify_avg=self.rectify_avg,
|
|
274
|
+
norm_layer=norm_layer, dropblock_prob=dropblock_prob,
|
|
275
|
+
last_gamma=self.last_gamma))
|
|
276
|
+
else:
|
|
277
|
+
raise RuntimeError("=> unknown dilation size: {}".format(dilation))
|
|
278
|
+
|
|
279
|
+
self.inplanes = planes * block.expansion
|
|
280
|
+
for i in range(1, blocks):
|
|
281
|
+
layers.append(block(self.inplanes, planes,
|
|
282
|
+
radix=self.radix, cardinality=self.cardinality,
|
|
283
|
+
bottleneck_width=self.bottleneck_width,
|
|
284
|
+
avd=self.avd, avd_first=self.avd_first,
|
|
285
|
+
dilation=dilation, rectified_conv=self.rectified_conv,
|
|
286
|
+
rectify_avg=self.rectify_avg,
|
|
287
|
+
norm_layer=norm_layer, dropblock_prob=dropblock_prob,
|
|
288
|
+
last_gamma=self.last_gamma))
|
|
289
|
+
|
|
290
|
+
return nn.Sequential(*layers)
|
|
291
|
+
|
|
292
|
+
def forward(self, x):
|
|
293
|
+
x = self.conv1(x)
|
|
294
|
+
x = self.bn1(x)
|
|
295
|
+
x = self.relu(x)
|
|
296
|
+
x = self.maxpool(x)
|
|
297
|
+
|
|
298
|
+
x = self.layer1(x)
|
|
299
|
+
x = self.layer2(x)
|
|
300
|
+
x = self.layer3(x)
|
|
301
|
+
x = self.layer4(x)
|
|
302
|
+
|
|
303
|
+
return x
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
@BACKBONE_REGISTRY.register()
|
|
307
|
+
def build_resnest_backbone(cfg):
|
|
308
|
+
"""
|
|
309
|
+
Create a ResNest instance from config.
|
|
310
|
+
Returns:
|
|
311
|
+
ResNet: a :class:`ResNet` instance.
|
|
312
|
+
"""
|
|
313
|
+
|
|
314
|
+
# fmt: off
|
|
315
|
+
pretrain = cfg.MODEL.BACKBONE.PRETRAIN
|
|
316
|
+
pretrain_path = cfg.MODEL.BACKBONE.PRETRAIN_PATH
|
|
317
|
+
last_stride = cfg.MODEL.BACKBONE.LAST_STRIDE
|
|
318
|
+
bn_norm = cfg.MODEL.BACKBONE.NORM
|
|
319
|
+
depth = cfg.MODEL.BACKBONE.DEPTH
|
|
320
|
+
# fmt: on
|
|
321
|
+
|
|
322
|
+
num_blocks_per_stage = {
|
|
323
|
+
"50x": [3, 4, 6, 3],
|
|
324
|
+
"101x": [3, 4, 23, 3],
|
|
325
|
+
"200x": [3, 24, 36, 3],
|
|
326
|
+
"269x": [3, 30, 48, 8],
|
|
327
|
+
}[depth]
|
|
328
|
+
|
|
329
|
+
stem_width = {
|
|
330
|
+
"50x": 32,
|
|
331
|
+
"101x": 64,
|
|
332
|
+
"200x": 64,
|
|
333
|
+
"269x": 64,
|
|
334
|
+
}[depth]
|
|
335
|
+
|
|
336
|
+
model = ResNeSt(last_stride, Bottleneck, num_blocks_per_stage,
|
|
337
|
+
radix=2, groups=1, bottleneck_width=64,
|
|
338
|
+
deep_stem=True, stem_width=stem_width, avg_down=True,
|
|
339
|
+
avd=True, avd_first=False, norm_layer=bn_norm)
|
|
340
|
+
if pretrain:
|
|
341
|
+
# Load pretrain path if specifically
|
|
342
|
+
if pretrain_path:
|
|
343
|
+
try:
|
|
344
|
+
state_dict = torch.load(pretrain_path, map_location=torch.device('cpu'))
|
|
345
|
+
logger.info(f"Loading pretrained model from {pretrain_path}")
|
|
346
|
+
except FileNotFoundError as e:
|
|
347
|
+
logger.info(f'{pretrain_path} is not found! Please check this path.')
|
|
348
|
+
raise e
|
|
349
|
+
except KeyError as e:
|
|
350
|
+
logger.info("State dict keys error! Please check the state dict.")
|
|
351
|
+
raise e
|
|
352
|
+
else:
|
|
353
|
+
state_dict = torch.hub.load_state_dict_from_url(
|
|
354
|
+
model_urls['resnest' + depth[:-1]], progress=True, check_hash=True, map_location=torch.device('cpu'))
|
|
355
|
+
|
|
356
|
+
incompatible = model.load_state_dict(state_dict, strict=False)
|
|
357
|
+
if incompatible.missing_keys:
|
|
358
|
+
logger.info(
|
|
359
|
+
get_missing_parameters_message(incompatible.missing_keys)
|
|
360
|
+
)
|
|
361
|
+
if incompatible.unexpected_keys:
|
|
362
|
+
logger.info(
|
|
363
|
+
get_unexpected_parameters_message(incompatible.unexpected_keys)
|
|
364
|
+
)
|
|
365
|
+
return model
|