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.
- dnt/__init__.py +3 -2
- dnt/analysis/__init__.py +3 -2
- dnt/analysis/interaction.py +503 -0
- dnt/analysis/stop.py +22 -17
- dnt/analysis/stop2.py +289 -0
- dnt/analysis/stop3.py +754 -0
- dnt/detect/signal/detector.py +317 -0
- dnt/detect/yolov8/detector.py +116 -16
- 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/filter.py +321 -1
- dnt/label/labeler.py +4 -4
- dnt/label/labeler2.py +502 -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 +2 -0
- 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 +28 -18
- 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/dsort.py +21 -28
- dnt/track/re_class.py +94 -0
- dnt/track/sort/sort.py +5 -1
- dnt/track/tracker.py +207 -30
- {dnt-0.2.4.dist-info → dnt-0.3.1.3.dist-info}/METADATA +30 -10
- dnt-0.3.1.3.dist-info/RECORD +314 -0
- {dnt-0.2.4.dist-info → dnt-0.3.1.3.dist-info}/WHEEL +1 -1
- dnt/analysis/yield.py +0 -9
- 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.4.dist-info/RECORD +0 -64
- /dnt/{track/dsort/utils → third_party/fast-reid/checkpoint}/__init__.py +0 -0
- {dnt-0.2.4.dist-info → dnt-0.3.1.3.dist-info}/LICENSE +0 -0
- {dnt-0.2.4.dist-info → dnt-0.3.1.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
"""
|
|
3
|
+
@author: liaoxingyu
|
|
4
|
+
@contact: sherlockliao01@gmail.com
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
import math
|
|
9
|
+
|
|
10
|
+
import torch
|
|
11
|
+
from torch import nn
|
|
12
|
+
|
|
13
|
+
from fastreid.layers import (
|
|
14
|
+
IBN,
|
|
15
|
+
SELayer,
|
|
16
|
+
Non_local,
|
|
17
|
+
get_norm,
|
|
18
|
+
)
|
|
19
|
+
from fastreid.utils.checkpoint import get_missing_parameters_message, get_unexpected_parameters_message
|
|
20
|
+
from .build import BACKBONE_REGISTRY
|
|
21
|
+
from fastreid.utils import comm
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
logger = logging.getLogger(__name__)
|
|
25
|
+
model_urls = {
|
|
26
|
+
'18x': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
|
|
27
|
+
'34x': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth',
|
|
28
|
+
'50x': 'https://download.pytorch.org/models/resnet50-19c8e357.pth',
|
|
29
|
+
'101x': 'https://download.pytorch.org/models/resnet101-5d3b4d8f.pth',
|
|
30
|
+
'ibn_18x': 'https://github.com/XingangPan/IBN-Net/releases/download/v1.0/resnet18_ibn_a-2f571257.pth',
|
|
31
|
+
'ibn_34x': 'https://github.com/XingangPan/IBN-Net/releases/download/v1.0/resnet34_ibn_a-94bc1577.pth',
|
|
32
|
+
'ibn_50x': 'https://github.com/XingangPan/IBN-Net/releases/download/v1.0/resnet50_ibn_a-d9d0bb7b.pth',
|
|
33
|
+
'ibn_101x': 'https://github.com/XingangPan/IBN-Net/releases/download/v1.0/resnet101_ibn_a-59ea0ac6.pth',
|
|
34
|
+
'se_ibn_101x': 'https://github.com/XingangPan/IBN-Net/releases/download/v1.0/se_resnet101_ibn_a-fabed4e2.pth',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class BasicBlock(nn.Module):
|
|
39
|
+
expansion = 1
|
|
40
|
+
|
|
41
|
+
def __init__(self, inplanes, planes, bn_norm, with_ibn=False, with_se=False,
|
|
42
|
+
stride=1, downsample=None, reduction=16):
|
|
43
|
+
super(BasicBlock, self).__init__()
|
|
44
|
+
self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
|
|
45
|
+
if with_ibn:
|
|
46
|
+
self.bn1 = IBN(planes, bn_norm)
|
|
47
|
+
else:
|
|
48
|
+
self.bn1 = get_norm(bn_norm, planes)
|
|
49
|
+
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
|
|
50
|
+
self.bn2 = get_norm(bn_norm, planes)
|
|
51
|
+
self.relu = nn.ReLU(inplace=True)
|
|
52
|
+
if with_se:
|
|
53
|
+
self.se = SELayer(planes, reduction)
|
|
54
|
+
else:
|
|
55
|
+
self.se = nn.Identity()
|
|
56
|
+
self.downsample = downsample
|
|
57
|
+
self.stride = stride
|
|
58
|
+
|
|
59
|
+
def forward(self, x):
|
|
60
|
+
identity = x
|
|
61
|
+
|
|
62
|
+
out = self.conv1(x)
|
|
63
|
+
out = self.bn1(out)
|
|
64
|
+
out = self.relu(out)
|
|
65
|
+
|
|
66
|
+
out = self.conv2(out)
|
|
67
|
+
out = self.bn2(out)
|
|
68
|
+
out = self.se(out)
|
|
69
|
+
|
|
70
|
+
if self.downsample is not None:
|
|
71
|
+
identity = self.downsample(x)
|
|
72
|
+
|
|
73
|
+
out += identity
|
|
74
|
+
out = self.relu(out)
|
|
75
|
+
|
|
76
|
+
return out
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class Bottleneck(nn.Module):
|
|
80
|
+
expansion = 4
|
|
81
|
+
|
|
82
|
+
def __init__(self, inplanes, planes, bn_norm, with_ibn=False, with_se=False,
|
|
83
|
+
stride=1, downsample=None, reduction=16):
|
|
84
|
+
super(Bottleneck, self).__init__()
|
|
85
|
+
self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
|
|
86
|
+
if with_ibn:
|
|
87
|
+
self.bn1 = IBN(planes, bn_norm)
|
|
88
|
+
else:
|
|
89
|
+
self.bn1 = get_norm(bn_norm, planes)
|
|
90
|
+
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride,
|
|
91
|
+
padding=1, bias=False)
|
|
92
|
+
self.bn2 = get_norm(bn_norm, planes)
|
|
93
|
+
self.conv3 = nn.Conv2d(planes, planes * self.expansion, kernel_size=1, bias=False)
|
|
94
|
+
self.bn3 = get_norm(bn_norm, planes * self.expansion)
|
|
95
|
+
self.relu = nn.ReLU(inplace=True)
|
|
96
|
+
if with_se:
|
|
97
|
+
self.se = SELayer(planes * self.expansion, reduction)
|
|
98
|
+
else:
|
|
99
|
+
self.se = nn.Identity()
|
|
100
|
+
self.downsample = downsample
|
|
101
|
+
self.stride = stride
|
|
102
|
+
|
|
103
|
+
def forward(self, x):
|
|
104
|
+
residual = x
|
|
105
|
+
|
|
106
|
+
out = self.conv1(x)
|
|
107
|
+
out = self.bn1(out)
|
|
108
|
+
out = self.relu(out)
|
|
109
|
+
|
|
110
|
+
out = self.conv2(out)
|
|
111
|
+
out = self.bn2(out)
|
|
112
|
+
out = self.relu(out)
|
|
113
|
+
|
|
114
|
+
out = self.conv3(out)
|
|
115
|
+
out = self.bn3(out)
|
|
116
|
+
out = self.se(out)
|
|
117
|
+
|
|
118
|
+
if self.downsample is not None:
|
|
119
|
+
residual = self.downsample(x)
|
|
120
|
+
|
|
121
|
+
out += residual
|
|
122
|
+
out = self.relu(out)
|
|
123
|
+
|
|
124
|
+
return out
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class ResNet(nn.Module):
|
|
128
|
+
def __init__(self, last_stride, bn_norm, with_ibn, with_se, with_nl, block, layers, non_layers):
|
|
129
|
+
self.inplanes = 64
|
|
130
|
+
super().__init__()
|
|
131
|
+
self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
|
|
132
|
+
bias=False)
|
|
133
|
+
self.bn1 = get_norm(bn_norm, 64)
|
|
134
|
+
self.relu = nn.ReLU(inplace=True)
|
|
135
|
+
# self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
|
|
136
|
+
self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True)
|
|
137
|
+
self.layer1 = self._make_layer(block, 64, layers[0], 1, bn_norm, with_ibn, with_se)
|
|
138
|
+
self.layer2 = self._make_layer(block, 128, layers[1], 2, bn_norm, with_ibn, with_se)
|
|
139
|
+
self.layer3 = self._make_layer(block, 256, layers[2], 2, bn_norm, with_ibn, with_se)
|
|
140
|
+
self.layer4 = self._make_layer(block, 512, layers[3], last_stride, bn_norm, with_se=with_se)
|
|
141
|
+
|
|
142
|
+
self.random_init()
|
|
143
|
+
|
|
144
|
+
# fmt: off
|
|
145
|
+
if with_nl: self._build_nonlocal(layers, non_layers, bn_norm)
|
|
146
|
+
else: self.NL_1_idx = self.NL_2_idx = self.NL_3_idx = self.NL_4_idx = []
|
|
147
|
+
# fmt: on
|
|
148
|
+
|
|
149
|
+
def _make_layer(self, block, planes, blocks, stride=1, bn_norm="BN", with_ibn=False, with_se=False):
|
|
150
|
+
downsample = None
|
|
151
|
+
if stride != 1 or self.inplanes != planes * block.expansion:
|
|
152
|
+
downsample = nn.Sequential(
|
|
153
|
+
nn.Conv2d(self.inplanes, planes * block.expansion,
|
|
154
|
+
kernel_size=1, stride=stride, bias=False),
|
|
155
|
+
get_norm(bn_norm, planes * block.expansion),
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
layers = []
|
|
159
|
+
layers.append(block(self.inplanes, planes, bn_norm, with_ibn, with_se, stride, downsample))
|
|
160
|
+
self.inplanes = planes * block.expansion
|
|
161
|
+
for i in range(1, blocks):
|
|
162
|
+
layers.append(block(self.inplanes, planes, bn_norm, with_ibn, with_se))
|
|
163
|
+
|
|
164
|
+
return nn.Sequential(*layers)
|
|
165
|
+
|
|
166
|
+
def _build_nonlocal(self, layers, non_layers, bn_norm):
|
|
167
|
+
self.NL_1 = nn.ModuleList(
|
|
168
|
+
[Non_local(256, bn_norm) for _ in range(non_layers[0])])
|
|
169
|
+
self.NL_1_idx = sorted([layers[0] - (i + 1) for i in range(non_layers[0])])
|
|
170
|
+
self.NL_2 = nn.ModuleList(
|
|
171
|
+
[Non_local(512, bn_norm) for _ in range(non_layers[1])])
|
|
172
|
+
self.NL_2_idx = sorted([layers[1] - (i + 1) for i in range(non_layers[1])])
|
|
173
|
+
self.NL_3 = nn.ModuleList(
|
|
174
|
+
[Non_local(1024, bn_norm) for _ in range(non_layers[2])])
|
|
175
|
+
self.NL_3_idx = sorted([layers[2] - (i + 1) for i in range(non_layers[2])])
|
|
176
|
+
self.NL_4 = nn.ModuleList(
|
|
177
|
+
[Non_local(2048, bn_norm) for _ in range(non_layers[3])])
|
|
178
|
+
self.NL_4_idx = sorted([layers[3] - (i + 1) for i in range(non_layers[3])])
|
|
179
|
+
|
|
180
|
+
def forward(self, x):
|
|
181
|
+
x = self.conv1(x)
|
|
182
|
+
x = self.bn1(x)
|
|
183
|
+
x = self.relu(x)
|
|
184
|
+
x = self.maxpool(x)
|
|
185
|
+
|
|
186
|
+
# layer 1
|
|
187
|
+
NL1_counter = 0
|
|
188
|
+
if len(self.NL_1_idx) == 0:
|
|
189
|
+
self.NL_1_idx = [-1]
|
|
190
|
+
for i in range(len(self.layer1)):
|
|
191
|
+
x = self.layer1[i](x)
|
|
192
|
+
if i == self.NL_1_idx[NL1_counter]:
|
|
193
|
+
_, C, H, W = x.shape
|
|
194
|
+
x = self.NL_1[NL1_counter](x)
|
|
195
|
+
NL1_counter += 1
|
|
196
|
+
# layer 2
|
|
197
|
+
NL2_counter = 0
|
|
198
|
+
if len(self.NL_2_idx) == 0:
|
|
199
|
+
self.NL_2_idx = [-1]
|
|
200
|
+
for i in range(len(self.layer2)):
|
|
201
|
+
x = self.layer2[i](x)
|
|
202
|
+
if i == self.NL_2_idx[NL2_counter]:
|
|
203
|
+
_, C, H, W = x.shape
|
|
204
|
+
x = self.NL_2[NL2_counter](x)
|
|
205
|
+
NL2_counter += 1
|
|
206
|
+
|
|
207
|
+
# layer 3
|
|
208
|
+
NL3_counter = 0
|
|
209
|
+
if len(self.NL_3_idx) == 0:
|
|
210
|
+
self.NL_3_idx = [-1]
|
|
211
|
+
for i in range(len(self.layer3)):
|
|
212
|
+
x = self.layer3[i](x)
|
|
213
|
+
if i == self.NL_3_idx[NL3_counter]:
|
|
214
|
+
_, C, H, W = x.shape
|
|
215
|
+
x = self.NL_3[NL3_counter](x)
|
|
216
|
+
NL3_counter += 1
|
|
217
|
+
|
|
218
|
+
# layer 4
|
|
219
|
+
NL4_counter = 0
|
|
220
|
+
if len(self.NL_4_idx) == 0:
|
|
221
|
+
self.NL_4_idx = [-1]
|
|
222
|
+
for i in range(len(self.layer4)):
|
|
223
|
+
x = self.layer4[i](x)
|
|
224
|
+
if i == self.NL_4_idx[NL4_counter]:
|
|
225
|
+
_, C, H, W = x.shape
|
|
226
|
+
x = self.NL_4[NL4_counter](x)
|
|
227
|
+
NL4_counter += 1
|
|
228
|
+
|
|
229
|
+
return x
|
|
230
|
+
|
|
231
|
+
def random_init(self):
|
|
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
|
+
nn.init.normal_(m.weight, 0, math.sqrt(2. / n))
|
|
236
|
+
elif isinstance(m, nn.BatchNorm2d):
|
|
237
|
+
nn.init.constant_(m.weight, 1)
|
|
238
|
+
nn.init.constant_(m.bias, 0)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def init_pretrained_weights(key):
|
|
242
|
+
"""Initializes model with pretrained weights.
|
|
243
|
+
|
|
244
|
+
Layers that don't match with pretrained layers in name or size are kept unchanged.
|
|
245
|
+
"""
|
|
246
|
+
import os
|
|
247
|
+
import errno
|
|
248
|
+
import gdown
|
|
249
|
+
|
|
250
|
+
def _get_torch_home():
|
|
251
|
+
ENV_TORCH_HOME = 'TORCH_HOME'
|
|
252
|
+
ENV_XDG_CACHE_HOME = 'XDG_CACHE_HOME'
|
|
253
|
+
DEFAULT_CACHE_DIR = '~/.cache'
|
|
254
|
+
torch_home = os.path.expanduser(
|
|
255
|
+
os.getenv(
|
|
256
|
+
ENV_TORCH_HOME,
|
|
257
|
+
os.path.join(
|
|
258
|
+
os.getenv(ENV_XDG_CACHE_HOME, DEFAULT_CACHE_DIR), 'torch'
|
|
259
|
+
)
|
|
260
|
+
)
|
|
261
|
+
)
|
|
262
|
+
return torch_home
|
|
263
|
+
|
|
264
|
+
torch_home = _get_torch_home()
|
|
265
|
+
model_dir = os.path.join(torch_home, 'checkpoints')
|
|
266
|
+
try:
|
|
267
|
+
os.makedirs(model_dir)
|
|
268
|
+
except OSError as e:
|
|
269
|
+
if e.errno == errno.EEXIST:
|
|
270
|
+
# Directory already exists, ignore.
|
|
271
|
+
pass
|
|
272
|
+
else:
|
|
273
|
+
# Unexpected OSError, re-raise.
|
|
274
|
+
raise
|
|
275
|
+
|
|
276
|
+
filename = model_urls[key].split('/')[-1]
|
|
277
|
+
|
|
278
|
+
cached_file = os.path.join(model_dir, filename)
|
|
279
|
+
|
|
280
|
+
if not os.path.exists(cached_file):
|
|
281
|
+
logger.info(f"Pretrain model don't exist, downloading from {model_urls[key]}")
|
|
282
|
+
if comm.is_main_process():
|
|
283
|
+
gdown.download(model_urls[key], cached_file, quiet=False)
|
|
284
|
+
|
|
285
|
+
comm.synchronize()
|
|
286
|
+
|
|
287
|
+
logger.info(f"Loading pretrained model from {cached_file}")
|
|
288
|
+
state_dict = torch.load(cached_file, map_location=torch.device('cpu'))
|
|
289
|
+
|
|
290
|
+
return state_dict
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
@BACKBONE_REGISTRY.register()
|
|
294
|
+
def build_resnet_backbone(cfg):
|
|
295
|
+
"""
|
|
296
|
+
Create a ResNet instance from config.
|
|
297
|
+
Returns:
|
|
298
|
+
ResNet: a :class:`ResNet` instance.
|
|
299
|
+
"""
|
|
300
|
+
|
|
301
|
+
# fmt: off
|
|
302
|
+
pretrain = cfg.MODEL.BACKBONE.PRETRAIN
|
|
303
|
+
pretrain_path = cfg.MODEL.BACKBONE.PRETRAIN_PATH
|
|
304
|
+
last_stride = cfg.MODEL.BACKBONE.LAST_STRIDE
|
|
305
|
+
bn_norm = cfg.MODEL.BACKBONE.NORM
|
|
306
|
+
with_ibn = cfg.MODEL.BACKBONE.WITH_IBN
|
|
307
|
+
with_se = cfg.MODEL.BACKBONE.WITH_SE
|
|
308
|
+
with_nl = cfg.MODEL.BACKBONE.WITH_NL
|
|
309
|
+
depth = cfg.MODEL.BACKBONE.DEPTH
|
|
310
|
+
# fmt: on
|
|
311
|
+
|
|
312
|
+
num_blocks_per_stage = {
|
|
313
|
+
'18x': [2, 2, 2, 2],
|
|
314
|
+
'34x': [3, 4, 6, 3],
|
|
315
|
+
'50x': [3, 4, 6, 3],
|
|
316
|
+
'101x': [3, 4, 23, 3],
|
|
317
|
+
}[depth]
|
|
318
|
+
|
|
319
|
+
nl_layers_per_stage = {
|
|
320
|
+
'18x': [0, 0, 0, 0],
|
|
321
|
+
'34x': [0, 0, 0, 0],
|
|
322
|
+
'50x': [0, 2, 3, 0],
|
|
323
|
+
'101x': [0, 2, 9, 0]
|
|
324
|
+
}[depth]
|
|
325
|
+
|
|
326
|
+
block = {
|
|
327
|
+
'18x': BasicBlock,
|
|
328
|
+
'34x': BasicBlock,
|
|
329
|
+
'50x': Bottleneck,
|
|
330
|
+
'101x': Bottleneck
|
|
331
|
+
}[depth]
|
|
332
|
+
|
|
333
|
+
model = ResNet(last_stride, bn_norm, with_ibn, with_se, with_nl, block,
|
|
334
|
+
num_blocks_per_stage, nl_layers_per_stage)
|
|
335
|
+
if pretrain:
|
|
336
|
+
# Load pretrain path if specifically
|
|
337
|
+
if pretrain_path:
|
|
338
|
+
try:
|
|
339
|
+
state_dict = torch.load(pretrain_path, map_location=torch.device('cpu'))
|
|
340
|
+
logger.info(f"Loading pretrained model from {pretrain_path}")
|
|
341
|
+
except FileNotFoundError as e:
|
|
342
|
+
logger.info(f'{pretrain_path} is not found! Please check this path.')
|
|
343
|
+
raise e
|
|
344
|
+
except KeyError as e:
|
|
345
|
+
logger.info("State dict keys error! Please check the state dict.")
|
|
346
|
+
raise e
|
|
347
|
+
else:
|
|
348
|
+
key = depth
|
|
349
|
+
if with_ibn: key = 'ibn_' + key
|
|
350
|
+
if with_se: key = 'se_' + key
|
|
351
|
+
|
|
352
|
+
state_dict = init_pretrained_weights(key)
|
|
353
|
+
|
|
354
|
+
incompatible = model.load_state_dict(state_dict, strict=False)
|
|
355
|
+
if incompatible.missing_keys:
|
|
356
|
+
logger.info(
|
|
357
|
+
get_missing_parameters_message(incompatible.missing_keys)
|
|
358
|
+
)
|
|
359
|
+
if incompatible.unexpected_keys:
|
|
360
|
+
logger.info(
|
|
361
|
+
get_unexpected_parameters_message(incompatible.unexpected_keys)
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
return model
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
"""
|
|
3
|
+
@author: xingyu liao
|
|
4
|
+
@contact: sherlockliao01@gmail.com
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# based on:
|
|
8
|
+
# https://github.com/XingangPan/IBN-Net/blob/master/models/imagenet/resnext_ibn_a.py
|
|
9
|
+
|
|
10
|
+
import logging
|
|
11
|
+
import math
|
|
12
|
+
|
|
13
|
+
import torch
|
|
14
|
+
import torch.nn as nn
|
|
15
|
+
|
|
16
|
+
from fastreid.layers import *
|
|
17
|
+
from fastreid.utils import comm
|
|
18
|
+
from fastreid.utils.checkpoint import get_missing_parameters_message, get_unexpected_parameters_message
|
|
19
|
+
from .build import BACKBONE_REGISTRY
|
|
20
|
+
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
model_urls = {
|
|
23
|
+
'ibn_101x': 'https://github.com/XingangPan/IBN-Net/releases/download/v1.0/resnext101_ibn_a-6ace051d.pth',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Bottleneck(nn.Module):
|
|
28
|
+
"""
|
|
29
|
+
RexNeXt bottleneck type C
|
|
30
|
+
"""
|
|
31
|
+
expansion = 4
|
|
32
|
+
|
|
33
|
+
def __init__(self, inplanes, planes, bn_norm, with_ibn, baseWidth, cardinality, stride=1,
|
|
34
|
+
downsample=None):
|
|
35
|
+
""" Constructor
|
|
36
|
+
Args:
|
|
37
|
+
inplanes: input channel dimensionality
|
|
38
|
+
planes: output channel dimensionality
|
|
39
|
+
baseWidth: base width.
|
|
40
|
+
cardinality: num of convolution groups.
|
|
41
|
+
stride: conv stride. Replaces pooling layer.
|
|
42
|
+
"""
|
|
43
|
+
super(Bottleneck, self).__init__()
|
|
44
|
+
|
|
45
|
+
D = int(math.floor(planes * (baseWidth / 64)))
|
|
46
|
+
C = cardinality
|
|
47
|
+
self.conv1 = nn.Conv2d(inplanes, D * C, kernel_size=1, stride=1, padding=0, bias=False)
|
|
48
|
+
if with_ibn:
|
|
49
|
+
self.bn1 = IBN(D * C, bn_norm)
|
|
50
|
+
else:
|
|
51
|
+
self.bn1 = get_norm(bn_norm, D * C)
|
|
52
|
+
self.conv2 = nn.Conv2d(D * C, D * C, kernel_size=3, stride=stride, padding=1, groups=C, bias=False)
|
|
53
|
+
self.bn2 = get_norm(bn_norm, D * C)
|
|
54
|
+
self.conv3 = nn.Conv2d(D * C, planes * 4, kernel_size=1, stride=1, padding=0, bias=False)
|
|
55
|
+
self.bn3 = get_norm(bn_norm, planes * 4)
|
|
56
|
+
self.relu = nn.ReLU(inplace=True)
|
|
57
|
+
|
|
58
|
+
self.downsample = downsample
|
|
59
|
+
|
|
60
|
+
def forward(self, x):
|
|
61
|
+
residual = x
|
|
62
|
+
|
|
63
|
+
out = self.conv1(x)
|
|
64
|
+
out = self.bn1(out)
|
|
65
|
+
out = self.relu(out)
|
|
66
|
+
|
|
67
|
+
out = self.conv2(out)
|
|
68
|
+
out = self.bn2(out)
|
|
69
|
+
out = self.relu(out)
|
|
70
|
+
|
|
71
|
+
out = self.conv3(out)
|
|
72
|
+
out = self.bn3(out)
|
|
73
|
+
|
|
74
|
+
if self.downsample is not None:
|
|
75
|
+
residual = self.downsample(x)
|
|
76
|
+
|
|
77
|
+
out += residual
|
|
78
|
+
out = self.relu(out)
|
|
79
|
+
|
|
80
|
+
return out
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ResNeXt(nn.Module):
|
|
84
|
+
"""
|
|
85
|
+
ResNext optimized for the ImageNet dataset, as specified in
|
|
86
|
+
https://arxiv.org/pdf/1611.05431.pdf
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
def __init__(self, last_stride, bn_norm, with_ibn, with_nl, block, layers, non_layers,
|
|
90
|
+
baseWidth=4, cardinality=32):
|
|
91
|
+
""" Constructor
|
|
92
|
+
Args:
|
|
93
|
+
baseWidth: baseWidth for ResNeXt.
|
|
94
|
+
cardinality: number of convolution groups.
|
|
95
|
+
layers: config of layers, e.g., [3, 4, 6, 3]
|
|
96
|
+
"""
|
|
97
|
+
super(ResNeXt, self).__init__()
|
|
98
|
+
|
|
99
|
+
self.cardinality = cardinality
|
|
100
|
+
self.baseWidth = baseWidth
|
|
101
|
+
self.inplanes = 64
|
|
102
|
+
self.output_size = 64
|
|
103
|
+
|
|
104
|
+
self.conv1 = nn.Conv2d(3, 64, 7, 2, 3, bias=False)
|
|
105
|
+
self.bn1 = get_norm(bn_norm, 64)
|
|
106
|
+
self.relu = nn.ReLU(inplace=True)
|
|
107
|
+
self.maxpool1 = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
|
|
108
|
+
self.layer1 = self._make_layer(block, 64, layers[0], 1, bn_norm, with_ibn=with_ibn)
|
|
109
|
+
self.layer2 = self._make_layer(block, 128, layers[1], 2, bn_norm, with_ibn=with_ibn)
|
|
110
|
+
self.layer3 = self._make_layer(block, 256, layers[2], 2, bn_norm, with_ibn=with_ibn)
|
|
111
|
+
self.layer4 = self._make_layer(block, 512, layers[3], last_stride, bn_norm, with_ibn=with_ibn)
|
|
112
|
+
|
|
113
|
+
self.random_init()
|
|
114
|
+
|
|
115
|
+
# fmt: off
|
|
116
|
+
if with_nl: self._build_nonlocal(layers, non_layers, bn_norm)
|
|
117
|
+
else: self.NL_1_idx = self.NL_2_idx = self.NL_3_idx = self.NL_4_idx = []
|
|
118
|
+
# fmt: on
|
|
119
|
+
|
|
120
|
+
def _make_layer(self, block, planes, blocks, stride=1, bn_norm='BN', with_ibn=False):
|
|
121
|
+
""" Stack n bottleneck modules where n is inferred from the depth of the network.
|
|
122
|
+
Args:
|
|
123
|
+
block: block type used to construct ResNext
|
|
124
|
+
planes: number of output channels (need to multiply by block.expansion)
|
|
125
|
+
blocks: number of blocks to be built
|
|
126
|
+
stride: factor to reduce the spatial dimensionality in the first bottleneck of the block.
|
|
127
|
+
Returns: a Module consisting of n sequential bottlenecks.
|
|
128
|
+
"""
|
|
129
|
+
downsample = None
|
|
130
|
+
if stride != 1 or self.inplanes != planes * block.expansion:
|
|
131
|
+
downsample = nn.Sequential(
|
|
132
|
+
nn.Conv2d(self.inplanes, planes * block.expansion,
|
|
133
|
+
kernel_size=1, stride=stride, bias=False),
|
|
134
|
+
get_norm(bn_norm, planes * block.expansion),
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
layers = []
|
|
138
|
+
layers.append(block(self.inplanes, planes, bn_norm, with_ibn,
|
|
139
|
+
self.baseWidth, self.cardinality, stride, downsample))
|
|
140
|
+
self.inplanes = planes * block.expansion
|
|
141
|
+
for i in range(1, blocks):
|
|
142
|
+
layers.append(
|
|
143
|
+
block(self.inplanes, planes, bn_norm, with_ibn, self.baseWidth, self.cardinality, 1, None))
|
|
144
|
+
|
|
145
|
+
return nn.Sequential(*layers)
|
|
146
|
+
|
|
147
|
+
def _build_nonlocal(self, layers, non_layers, bn_norm):
|
|
148
|
+
self.NL_1 = nn.ModuleList(
|
|
149
|
+
[Non_local(256, bn_norm) for _ in range(non_layers[0])])
|
|
150
|
+
self.NL_1_idx = sorted([layers[0] - (i + 1) for i in range(non_layers[0])])
|
|
151
|
+
self.NL_2 = nn.ModuleList(
|
|
152
|
+
[Non_local(512, bn_norm) for _ in range(non_layers[1])])
|
|
153
|
+
self.NL_2_idx = sorted([layers[1] - (i + 1) for i in range(non_layers[1])])
|
|
154
|
+
self.NL_3 = nn.ModuleList(
|
|
155
|
+
[Non_local(1024, bn_norm) for _ in range(non_layers[2])])
|
|
156
|
+
self.NL_3_idx = sorted([layers[2] - (i + 1) for i in range(non_layers[2])])
|
|
157
|
+
self.NL_4 = nn.ModuleList(
|
|
158
|
+
[Non_local(2048, bn_norm) for _ in range(non_layers[3])])
|
|
159
|
+
self.NL_4_idx = sorted([layers[3] - (i + 1) for i in range(non_layers[3])])
|
|
160
|
+
|
|
161
|
+
def forward(self, x):
|
|
162
|
+
x = self.conv1(x)
|
|
163
|
+
x = self.bn1(x)
|
|
164
|
+
x = self.relu(x)
|
|
165
|
+
x = self.maxpool1(x)
|
|
166
|
+
|
|
167
|
+
NL1_counter = 0
|
|
168
|
+
if len(self.NL_1_idx) == 0:
|
|
169
|
+
self.NL_1_idx = [-1]
|
|
170
|
+
for i in range(len(self.layer1)):
|
|
171
|
+
x = self.layer1[i](x)
|
|
172
|
+
if i == self.NL_1_idx[NL1_counter]:
|
|
173
|
+
_, C, H, W = x.shape
|
|
174
|
+
x = self.NL_1[NL1_counter](x)
|
|
175
|
+
NL1_counter += 1
|
|
176
|
+
# Layer 2
|
|
177
|
+
NL2_counter = 0
|
|
178
|
+
if len(self.NL_2_idx) == 0:
|
|
179
|
+
self.NL_2_idx = [-1]
|
|
180
|
+
for i in range(len(self.layer2)):
|
|
181
|
+
x = self.layer2[i](x)
|
|
182
|
+
if i == self.NL_2_idx[NL2_counter]:
|
|
183
|
+
_, C, H, W = x.shape
|
|
184
|
+
x = self.NL_2[NL2_counter](x)
|
|
185
|
+
NL2_counter += 1
|
|
186
|
+
# Layer 3
|
|
187
|
+
NL3_counter = 0
|
|
188
|
+
if len(self.NL_3_idx) == 0:
|
|
189
|
+
self.NL_3_idx = [-1]
|
|
190
|
+
for i in range(len(self.layer3)):
|
|
191
|
+
x = self.layer3[i](x)
|
|
192
|
+
if i == self.NL_3_idx[NL3_counter]:
|
|
193
|
+
_, C, H, W = x.shape
|
|
194
|
+
x = self.NL_3[NL3_counter](x)
|
|
195
|
+
NL3_counter += 1
|
|
196
|
+
# Layer 4
|
|
197
|
+
NL4_counter = 0
|
|
198
|
+
if len(self.NL_4_idx) == 0:
|
|
199
|
+
self.NL_4_idx = [-1]
|
|
200
|
+
for i in range(len(self.layer4)):
|
|
201
|
+
x = self.layer4[i](x)
|
|
202
|
+
if i == self.NL_4_idx[NL4_counter]:
|
|
203
|
+
_, C, H, W = x.shape
|
|
204
|
+
x = self.NL_4[NL4_counter](x)
|
|
205
|
+
NL4_counter += 1
|
|
206
|
+
return x
|
|
207
|
+
|
|
208
|
+
def random_init(self):
|
|
209
|
+
self.conv1.weight.data.normal_(0, math.sqrt(2. / (7 * 7 * 64)))
|
|
210
|
+
for m in self.modules():
|
|
211
|
+
if isinstance(m, nn.Conv2d):
|
|
212
|
+
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
|
|
213
|
+
m.weight.data.normal_(0, math.sqrt(2. / n))
|
|
214
|
+
elif isinstance(m, nn.BatchNorm2d):
|
|
215
|
+
m.weight.data.fill_(1)
|
|
216
|
+
m.bias.data.zero_()
|
|
217
|
+
elif isinstance(m, nn.InstanceNorm2d):
|
|
218
|
+
m.weight.data.fill_(1)
|
|
219
|
+
m.bias.data.zero_()
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def init_pretrained_weights(key):
|
|
223
|
+
"""Initializes model with pretrained weights.
|
|
224
|
+
|
|
225
|
+
Layers that don't match with pretrained layers in name or size are kept unchanged.
|
|
226
|
+
"""
|
|
227
|
+
import os
|
|
228
|
+
import errno
|
|
229
|
+
import gdown
|
|
230
|
+
|
|
231
|
+
def _get_torch_home():
|
|
232
|
+
ENV_TORCH_HOME = 'TORCH_HOME'
|
|
233
|
+
ENV_XDG_CACHE_HOME = 'XDG_CACHE_HOME'
|
|
234
|
+
DEFAULT_CACHE_DIR = '~/.cache'
|
|
235
|
+
torch_home = os.path.expanduser(
|
|
236
|
+
os.getenv(
|
|
237
|
+
ENV_TORCH_HOME,
|
|
238
|
+
os.path.join(
|
|
239
|
+
os.getenv(ENV_XDG_CACHE_HOME, DEFAULT_CACHE_DIR), 'torch'
|
|
240
|
+
)
|
|
241
|
+
)
|
|
242
|
+
)
|
|
243
|
+
return torch_home
|
|
244
|
+
|
|
245
|
+
torch_home = _get_torch_home()
|
|
246
|
+
model_dir = os.path.join(torch_home, 'checkpoints')
|
|
247
|
+
try:
|
|
248
|
+
os.makedirs(model_dir)
|
|
249
|
+
except OSError as e:
|
|
250
|
+
if e.errno == errno.EEXIST:
|
|
251
|
+
# Directory already exists, ignore.
|
|
252
|
+
pass
|
|
253
|
+
else:
|
|
254
|
+
# Unexpected OSError, re-raise.
|
|
255
|
+
raise
|
|
256
|
+
|
|
257
|
+
filename = model_urls[key].split('/')[-1]
|
|
258
|
+
|
|
259
|
+
cached_file = os.path.join(model_dir, filename)
|
|
260
|
+
|
|
261
|
+
if not os.path.exists(cached_file):
|
|
262
|
+
logger.info(f"Pretrain model don't exist, downloading from {model_urls[key]}")
|
|
263
|
+
if comm.is_main_process():
|
|
264
|
+
gdown.download(model_urls[key], cached_file, quiet=False)
|
|
265
|
+
|
|
266
|
+
comm.synchronize()
|
|
267
|
+
|
|
268
|
+
logger.info(f"Loading pretrained model from {cached_file}")
|
|
269
|
+
state_dict = torch.load(cached_file, map_location=torch.device('cpu'))
|
|
270
|
+
|
|
271
|
+
return state_dict
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
@BACKBONE_REGISTRY.register()
|
|
275
|
+
def build_resnext_backbone(cfg):
|
|
276
|
+
"""
|
|
277
|
+
Create a ResNeXt instance from config.
|
|
278
|
+
Returns:
|
|
279
|
+
ResNeXt: a :class:`ResNeXt` instance.
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
# fmt: off
|
|
283
|
+
pretrain = cfg.MODEL.BACKBONE.PRETRAIN
|
|
284
|
+
pretrain_path = cfg.MODEL.BACKBONE.PRETRAIN_PATH
|
|
285
|
+
last_stride = cfg.MODEL.BACKBONE.LAST_STRIDE
|
|
286
|
+
bn_norm = cfg.MODEL.BACKBONE.NORM
|
|
287
|
+
with_ibn = cfg.MODEL.BACKBONE.WITH_IBN
|
|
288
|
+
with_nl = cfg.MODEL.BACKBONE.WITH_NL
|
|
289
|
+
depth = cfg.MODEL.BACKBONE.DEPTH
|
|
290
|
+
# fmt: on
|
|
291
|
+
|
|
292
|
+
num_blocks_per_stage = {
|
|
293
|
+
'50x': [3, 4, 6, 3],
|
|
294
|
+
'101x': [3, 4, 23, 3],
|
|
295
|
+
'152x': [3, 8, 36, 3], }[depth]
|
|
296
|
+
nl_layers_per_stage = {
|
|
297
|
+
'50x': [0, 2, 3, 0],
|
|
298
|
+
'101x': [0, 2, 3, 0]}[depth]
|
|
299
|
+
model = ResNeXt(last_stride, bn_norm, with_ibn, with_nl, Bottleneck,
|
|
300
|
+
num_blocks_per_stage, nl_layers_per_stage)
|
|
301
|
+
if pretrain:
|
|
302
|
+
if pretrain_path:
|
|
303
|
+
try:
|
|
304
|
+
state_dict = torch.load(pretrain_path, map_location=torch.device('cpu'))['model']
|
|
305
|
+
# Remove module.encoder in name
|
|
306
|
+
new_state_dict = {}
|
|
307
|
+
for k in state_dict:
|
|
308
|
+
new_k = '.'.join(k.split('.')[2:])
|
|
309
|
+
if new_k in model.state_dict() and (model.state_dict()[new_k].shape == state_dict[k].shape):
|
|
310
|
+
new_state_dict[new_k] = state_dict[k]
|
|
311
|
+
state_dict = new_state_dict
|
|
312
|
+
logger.info(f"Loading pretrained model from {pretrain_path}")
|
|
313
|
+
except FileNotFoundError as e:
|
|
314
|
+
logger.info(f'{pretrain_path} is not found! Please check this path.')
|
|
315
|
+
raise e
|
|
316
|
+
except KeyError as e:
|
|
317
|
+
logger.info("State dict keys error! Please check the state dict.")
|
|
318
|
+
raise e
|
|
319
|
+
else:
|
|
320
|
+
key = depth
|
|
321
|
+
if with_ibn: key = 'ibn_' + key
|
|
322
|
+
|
|
323
|
+
state_dict = init_pretrained_weights(key)
|
|
324
|
+
|
|
325
|
+
incompatible = model.load_state_dict(state_dict, strict=False)
|
|
326
|
+
if incompatible.missing_keys:
|
|
327
|
+
logger.info(
|
|
328
|
+
get_missing_parameters_message(incompatible.missing_keys)
|
|
329
|
+
)
|
|
330
|
+
if incompatible.unexpected_keys:
|
|
331
|
+
logger.info(
|
|
332
|
+
get_unexpected_parameters_message(incompatible.unexpected_keys)
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
return model
|