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
dnt/detect/yolov8/detector.py
CHANGED
|
@@ -1,31 +1,109 @@
|
|
|
1
|
-
|
|
1
|
+
'''
|
|
2
|
+
This module is a wrapper for ultralytics YOLOV8 and RTDETR models.
|
|
3
|
+
'''
|
|
4
|
+
from ultralytics import YOLO, RTDETR
|
|
2
5
|
import cv2
|
|
3
6
|
import pandas as pd
|
|
4
7
|
from tqdm import tqdm
|
|
5
8
|
import random, os
|
|
6
9
|
from pathlib import Path
|
|
10
|
+
import torch
|
|
7
11
|
|
|
8
12
|
class Detector:
|
|
9
|
-
def __init__(self,
|
|
13
|
+
def __init__(self,
|
|
14
|
+
model:str='yolo',
|
|
15
|
+
weights:str='x',
|
|
16
|
+
conf:float=0.25,
|
|
17
|
+
nms:float=0.7,
|
|
18
|
+
max_det:int=300,
|
|
19
|
+
device:str='auto',
|
|
20
|
+
half:bool=False):
|
|
10
21
|
'''
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
Initialize the Detector class.
|
|
23
|
+
Parameters:
|
|
24
|
+
model: 'yolo' (default), 'rtdetr'
|
|
25
|
+
weights: 'x' - extra-large (default), 'l' - large, 'm' - mdium, 's' - small, 'n' - nano, '.pt' - custom model weights
|
|
26
|
+
conf: 0.25 (default) - confidence threshold
|
|
27
|
+
nms: 0.7 (default) - non-max suppression threshold
|
|
28
|
+
max_det: 300 (default) - maximum number of detections per image
|
|
29
|
+
device: 'auto' (default), 'cuda', 'cpu', 'mps'
|
|
30
|
+
half: False (default), True
|
|
16
31
|
'''
|
|
17
|
-
# Load
|
|
32
|
+
# Load model
|
|
18
33
|
cwd = Path(__file__).parent.absolute()
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
if model == 'yolo':
|
|
35
|
+
if weights in ['x', 'l', 'm', 's', 'n']:
|
|
36
|
+
model_path = os.path.join(cwd, 'models/yolov8'+weights+'.pt')
|
|
37
|
+
elif ".pt" in weights:
|
|
38
|
+
model_path = os.path.join(cwd, 'models/'+weights)
|
|
39
|
+
elif model == 'yolo11':
|
|
40
|
+
if weights in ['x', 'l', 'm', 's', 'n']:
|
|
41
|
+
model_path = os.path.join(cwd, 'models/yolo11'+weights+'.pt')
|
|
42
|
+
elif ".pt" in weights:
|
|
43
|
+
model_path = os.path.join(cwd, 'models/'+weights)
|
|
44
|
+
|
|
45
|
+
elif model == 'rtdetr':
|
|
46
|
+
if weights in ['x', 'l']:
|
|
47
|
+
model_path = os.path.join(cwd, 'models/rtdetr-'+weights+'.pt')
|
|
48
|
+
elif ".pt" in weights:
|
|
49
|
+
model_path = os.path.join(cwd, 'models/'+weights)
|
|
50
|
+
else:
|
|
51
|
+
model_path = os.path.join(cwd, 'models/rtdetr-x.pt')
|
|
52
|
+
#elif model == 'nas':
|
|
53
|
+
# if weights in ['l', 'm', 's']:
|
|
54
|
+
# model_path = os.path.join(cwd, 'models/yolo_nas_'+weights+'.pt')
|
|
55
|
+
# elif ".pt" in weights:
|
|
56
|
+
# model_path = os.path.join(cwd, 'models/'+weights)
|
|
57
|
+
# else:
|
|
58
|
+
# model_path = os.path.join(cwd, 'models/yolo_nas_l.pt')
|
|
59
|
+
else:
|
|
60
|
+
raise Exception('Invalid detection model type!')
|
|
61
|
+
|
|
62
|
+
if model == 'yolo' or model == 'yolo11':
|
|
63
|
+
self.model = YOLO(model_path)
|
|
64
|
+
elif model == 'rtdetr':
|
|
65
|
+
self.model = RTDETR(model_path)
|
|
66
|
+
#elif model == 'nas':
|
|
67
|
+
# self.model = NAS(model_path)
|
|
68
|
+
else:
|
|
69
|
+
raise Exception('Invalid model weights!')
|
|
70
|
+
|
|
21
71
|
self.conf = conf
|
|
22
72
|
self.nms = nms
|
|
23
73
|
self.max_det = max_det
|
|
24
74
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
75
|
+
if device == 'auto':
|
|
76
|
+
self.device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
|
|
77
|
+
elif device == 'cuda' and torch.cuda.is_available():
|
|
78
|
+
self.device = 'cuda'
|
|
79
|
+
elif device == 'mps' and torch.backends.mps.is_available():
|
|
80
|
+
self.device = 'mps'
|
|
81
|
+
else:
|
|
82
|
+
self.device = 'cpu'
|
|
83
|
+
|
|
84
|
+
self.half = half
|
|
85
|
+
|
|
86
|
+
def detect(self,
|
|
87
|
+
input_video:str,
|
|
88
|
+
iou_file:str=None,
|
|
89
|
+
video_index:int=None,
|
|
90
|
+
video_tot:int=None,
|
|
91
|
+
start_frame:int=None,
|
|
92
|
+
end_frame:int=None,
|
|
93
|
+
verbose:bool=True) -> pd.DataFrame:
|
|
94
|
+
'''
|
|
95
|
+
Detect objects in a video file.
|
|
96
|
+
Parameters:
|
|
97
|
+
input_video: path to the input video file
|
|
98
|
+
iou_file: path to the output file
|
|
99
|
+
video_index: index of the video in the batch
|
|
100
|
+
video_tot: total number of videos in the batch
|
|
101
|
+
start_frame: start frame number
|
|
102
|
+
end_frame: end frame number
|
|
103
|
+
verbose: True (default), False
|
|
104
|
+
Returns:
|
|
105
|
+
df: pandas DataFrame containing the detection results
|
|
106
|
+
'''
|
|
29
107
|
# open input video
|
|
30
108
|
cap = cv2.VideoCapture(input_video)
|
|
31
109
|
if not cap.isOpened():
|
|
@@ -35,16 +113,14 @@ class Detector:
|
|
|
35
113
|
results = []
|
|
36
114
|
|
|
37
115
|
video_fps = int(cap.get(cv2.CAP_PROP_FPS)) #original fps
|
|
38
|
-
if
|
|
39
|
-
start_frame
|
|
40
|
-
if start_frame > int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1:
|
|
116
|
+
if start_frame:
|
|
117
|
+
if (start_frame > int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1) or (start_frame < 0):
|
|
41
118
|
start_frame = 0
|
|
42
119
|
else:
|
|
43
120
|
start_frame = 0
|
|
44
121
|
|
|
45
|
-
if
|
|
46
|
-
end_frame
|
|
47
|
-
if end_frame > int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1:
|
|
122
|
+
if end_frame:
|
|
123
|
+
if (end_frame > int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1) or (end_frame < 0):
|
|
48
124
|
end_frame = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1
|
|
49
125
|
else:
|
|
50
126
|
end_frame = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1
|
|
@@ -52,9 +128,13 @@ class Detector:
|
|
|
52
128
|
if start_frame>=end_frame:
|
|
53
129
|
raise Exception('The given start time exceeds the end time!')
|
|
54
130
|
|
|
55
|
-
frame_total = end_frame - start_frame
|
|
56
|
-
|
|
57
|
-
|
|
131
|
+
frame_total = end_frame - start_frame
|
|
132
|
+
if verbose:
|
|
133
|
+
pbar = tqdm(total=frame_total, unit=" frames")
|
|
134
|
+
if video_index and video_tot:
|
|
135
|
+
pbar.set_description_str("Detecting {} of {}".format(video_index, video_tot))
|
|
136
|
+
else:
|
|
137
|
+
pbar.set_description_str("Detecting ")
|
|
58
138
|
|
|
59
139
|
cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
|
|
60
140
|
while cap.isOpened():
|
|
@@ -63,7 +143,8 @@ class Detector:
|
|
|
63
143
|
if (not ret) or (pos_frame>end_frame):
|
|
64
144
|
break
|
|
65
145
|
|
|
66
|
-
detects = self.model.predict(frame, verbose=False, conf=self.conf, iou=self.nms, max_det=self.max_det
|
|
146
|
+
detects = self.model.predict(frame, verbose=False, conf=self.conf, iou=self.nms, max_det=self.max_det,
|
|
147
|
+
device=self.device, half=self.half)
|
|
67
148
|
if len(detects)>0:
|
|
68
149
|
detect = detects[0]
|
|
69
150
|
|
|
@@ -75,13 +156,16 @@ class Detector:
|
|
|
75
156
|
result.insert(1, 'res', -1)
|
|
76
157
|
results.append(result)
|
|
77
158
|
|
|
78
|
-
|
|
159
|
+
if verbose:
|
|
160
|
+
pbar.update()
|
|
79
161
|
|
|
80
|
-
|
|
162
|
+
if verbose:
|
|
163
|
+
pbar.close()
|
|
81
164
|
cap.release()
|
|
82
|
-
cv2.destroyAllWindows()
|
|
165
|
+
#cv2.destroyAllWindows()
|
|
83
166
|
|
|
84
|
-
df = pd.concat(results)
|
|
167
|
+
df = pd.concat(d for d in results if not d.empty) # remove empty dataframes
|
|
168
|
+
#df = pd.concat(results)
|
|
85
169
|
df['x'] = round(df['x'], 1)
|
|
86
170
|
df['y'] = round(df['y'], 1)
|
|
87
171
|
df['w'] = round(df['x2']-df['x'], 0)
|
|
@@ -96,9 +180,61 @@ class Detector:
|
|
|
96
180
|
|
|
97
181
|
return df
|
|
98
182
|
|
|
99
|
-
def
|
|
183
|
+
def detect_frames(self, input_video:str, frames:list[int], verbose:bool=False)->pd.DataFrame:
|
|
184
|
+
# open input video
|
|
185
|
+
cap = cv2.VideoCapture(input_video)
|
|
186
|
+
if not cap.isOpened():
|
|
187
|
+
print('Failed to open the video!')
|
|
188
|
+
|
|
189
|
+
random.seed(3) # deterministic bbox colors
|
|
190
|
+
results = []
|
|
191
|
+
|
|
192
|
+
if verbose:
|
|
193
|
+
pbar = tqdm(total=len(frames), unit=" frames")
|
|
194
|
+
for pos_frame in frames:
|
|
195
|
+
cap.set(cv2.CAP_PROP_POS_FRAMES, pos_frame)
|
|
196
|
+
ret, frame = cap.read()
|
|
197
|
+
if not ret:
|
|
198
|
+
break
|
|
199
|
+
|
|
200
|
+
detects = self.model.predict(frame, verbose=False, conf=self.conf, iou=self.nms, max_det=self.max_det,
|
|
201
|
+
device=self.device, half=self.half)
|
|
202
|
+
if len(detects)>0:
|
|
203
|
+
detect = detects[0]
|
|
204
|
+
|
|
205
|
+
xyxy = pd.DataFrame(detect.boxes.xyxy.tolist(), columns=['x', 'y', 'x2', 'y2'])
|
|
206
|
+
cls = pd.DataFrame(detect.boxes.cls.tolist(), columns=['class'])
|
|
207
|
+
conf = pd.DataFrame(detect.boxes.conf.tolist(), columns = ['conf'])
|
|
208
|
+
result = pd.concat([xyxy, conf, cls], axis=1)
|
|
209
|
+
result.insert(0, 'frame', pos_frame)
|
|
210
|
+
result.insert(1, 'res', -1)
|
|
211
|
+
results.append(result)
|
|
212
|
+
|
|
213
|
+
if verbose:
|
|
214
|
+
pbar.update()
|
|
215
|
+
|
|
216
|
+
if verbose:
|
|
217
|
+
pbar.close()
|
|
218
|
+
cap.release()
|
|
219
|
+
|
|
220
|
+
if len(results) == 0:
|
|
221
|
+
return pd.DataFrame(columns=['frame', 'res', 'x', 'y', 'w', 'h', 'conf', 'class'])
|
|
222
|
+
|
|
223
|
+
df = pd.concat(d for d in results if not d.empty) # remove empty dataframes
|
|
224
|
+
#df = pd.concat(results)
|
|
225
|
+
df['x'] = round(df['x'], 1)
|
|
226
|
+
df['y'] = round(df['y'], 1)
|
|
227
|
+
df['w'] = round(df['x2']-df['x'], 0)
|
|
228
|
+
df['h'] = round(df['y2']-df['y'], 0)
|
|
229
|
+
df['class'] = round(df['class'], 0)
|
|
230
|
+
df['conf'] = round(df['conf'], 2)
|
|
231
|
+
df = df[['frame', 'res', 'x', 'y', 'w', 'h', 'conf', 'class']].reset_index(drop=True)
|
|
232
|
+
|
|
233
|
+
return df
|
|
234
|
+
|
|
235
|
+
def detect_v8(self, input_video:str, iou_file:str=None, save:bool=False, verbose:bool=False, show:bool=False):
|
|
100
236
|
detects = self.model.predict(input_video,
|
|
101
|
-
verbose=verbose, stream=True, save=save, show=show,
|
|
237
|
+
verbose=verbose, stream=True, save=save, show=show, device=self.device, half=self.half)
|
|
102
238
|
|
|
103
239
|
if iou_file:
|
|
104
240
|
results = []
|
|
@@ -123,7 +259,8 @@ class Detector:
|
|
|
123
259
|
df = pd.concat(results)
|
|
124
260
|
df.to_csv(iou_file, index=False, header=False)
|
|
125
261
|
|
|
126
|
-
def detect_batch(self, input_videos, output_path=None, is_overwrite=False,
|
|
262
|
+
def detect_batch(self, input_videos:list[str], output_path:str=None, is_overwrite:bool=False,
|
|
263
|
+
is_report:bool=True, verbose:bool=False) -> list[str]:
|
|
127
264
|
|
|
128
265
|
results = []
|
|
129
266
|
total_videos = len(input_videos)
|
|
@@ -159,14 +296,24 @@ class Detector:
|
|
|
159
296
|
return results
|
|
160
297
|
|
|
161
298
|
@staticmethod
|
|
162
|
-
def get_fps(
|
|
163
|
-
cap = cv2.VideoCapture(
|
|
299
|
+
def get_fps(video:str)->float:
|
|
300
|
+
cap = cv2.VideoCapture(video)
|
|
164
301
|
if not cap.isOpened():
|
|
165
302
|
print('Failed to open the video!')
|
|
166
303
|
fps = cap.get(cv2.CAP_PROP_FPS)
|
|
167
304
|
return fps
|
|
305
|
+
|
|
306
|
+
@staticmethod
|
|
307
|
+
def get_frames(video:str)->int:
|
|
308
|
+
cap = cv2.VideoCapture(video)
|
|
309
|
+
if not cap.isOpened():
|
|
310
|
+
print('Failed to open the video!')
|
|
311
|
+
frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
312
|
+
return frames
|
|
168
313
|
|
|
169
314
|
if __name__=='__main__':
|
|
170
315
|
|
|
171
|
-
detector = Detector()
|
|
172
|
-
detector.detect('/mnt/
|
|
316
|
+
detector = Detector(model='yolo11')
|
|
317
|
+
result = detector.detect('/mnt/d/videos/sample/traffic.mp4', verbose=True)
|
|
318
|
+
|
|
319
|
+
print(result)
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
from ultralytics import YOLO
|
|
2
|
+
import cv2
|
|
3
|
+
import pandas as pd
|
|
4
|
+
from tqdm import tqdm
|
|
5
|
+
import random, os, json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import torch
|
|
8
|
+
from shapely.geometry import Polygon as Pol
|
|
9
|
+
|
|
10
|
+
class Segmentor:
|
|
11
|
+
def __init__(self, model:str='yolov8m-seg.pt', conf:float=0.25, nms:float=0.7, max_det:int=300, device:str='auto', half:bool=False):
|
|
12
|
+
'''
|
|
13
|
+
yolo: x - yolov8x-seg.pt
|
|
14
|
+
l - yolov8l-seg.pt
|
|
15
|
+
m - yolov8m-seg.pt
|
|
16
|
+
s - yolov8s-seg.pt
|
|
17
|
+
n - yolov8n-seg.pt
|
|
18
|
+
|
|
19
|
+
'''
|
|
20
|
+
# Load YOLOV8 model
|
|
21
|
+
cwd = Path(__file__).parent.absolute()
|
|
22
|
+
model_path = os.path.join(cwd, 'models/'+model)
|
|
23
|
+
self.model = YOLO(model_path)
|
|
24
|
+
self.conf = conf
|
|
25
|
+
self.nms = nms
|
|
26
|
+
self.max_det = max_det
|
|
27
|
+
|
|
28
|
+
if device == 'auto':
|
|
29
|
+
self.device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
|
|
30
|
+
elif device == 'cuda' and torch.cuda.is_available():
|
|
31
|
+
self.device = 'cuda'
|
|
32
|
+
elif device == 'mps' and torch.backends.mps.is_available():
|
|
33
|
+
self.device = 'mps'
|
|
34
|
+
else:
|
|
35
|
+
self.device = 'cpu'
|
|
36
|
+
|
|
37
|
+
self.half = half
|
|
38
|
+
self.half = half
|
|
39
|
+
|
|
40
|
+
def segment(self, input_video:str, mask_file:str=None,
|
|
41
|
+
video_index:int=None, video_tot:int=None,
|
|
42
|
+
start_frame:int=None, end_frame:int=None,
|
|
43
|
+
verbose:bool=False):
|
|
44
|
+
|
|
45
|
+
# open input video
|
|
46
|
+
cap = cv2.VideoCapture(input_video)
|
|
47
|
+
if not cap.isOpened():
|
|
48
|
+
print('Failed to open the video!')
|
|
49
|
+
|
|
50
|
+
results = []
|
|
51
|
+
|
|
52
|
+
video_fps = int(cap.get(cv2.CAP_PROP_FPS)) #original fps
|
|
53
|
+
if start_frame:
|
|
54
|
+
if start_frame > int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1:
|
|
55
|
+
start_frame = 0
|
|
56
|
+
else:
|
|
57
|
+
start_frame = 0
|
|
58
|
+
|
|
59
|
+
if end_frame:
|
|
60
|
+
if end_frame > int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1:
|
|
61
|
+
end_frame = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1
|
|
62
|
+
elif end_frame < start_frame:
|
|
63
|
+
end_frame = start_frame
|
|
64
|
+
else:
|
|
65
|
+
end_frame = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1
|
|
66
|
+
|
|
67
|
+
if start_frame>end_frame:
|
|
68
|
+
raise Exception('The given start time exceeds the end time!')
|
|
69
|
+
|
|
70
|
+
frame_total = end_frame - start_frame + 1
|
|
71
|
+
pbar = tqdm(total=frame_total, unit=" frames")
|
|
72
|
+
if video_index and video_tot:
|
|
73
|
+
pbar.set_description_str("Segmenting {} of {}".format(video_index, video_tot))
|
|
74
|
+
else:
|
|
75
|
+
pbar.set_description_str("Segmenting ")
|
|
76
|
+
|
|
77
|
+
cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
|
|
78
|
+
while cap.isOpened():
|
|
79
|
+
pos_frame = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
|
|
80
|
+
ret, frame = cap.read()
|
|
81
|
+
if (not ret) or (pos_frame>end_frame):
|
|
82
|
+
break
|
|
83
|
+
|
|
84
|
+
detects = self.model.predict(frame, verbose=False, conf=self.conf, iou=self.nms, max_det=self.max_det, half=self.half)
|
|
85
|
+
if len(detects)>0:
|
|
86
|
+
xyxy = detects[0].boxes.xyxy.tolist()
|
|
87
|
+
xywh = list(map(lambda x: [int(x[0]), int(x[1]), int(x[2]-x[0]), int(x[3]-x[1])], xyxy))
|
|
88
|
+
cls = detects[0].boxes.cls.tolist()
|
|
89
|
+
conf = detects[0].boxes.conf.tolist()
|
|
90
|
+
xy = list(map(lambda x: x.tolist(), detects[0].masks.xy))
|
|
91
|
+
|
|
92
|
+
d = {
|
|
93
|
+
"frame": pos_frame,
|
|
94
|
+
"res": -1,
|
|
95
|
+
"class": cls,
|
|
96
|
+
"conf": conf,
|
|
97
|
+
"mask": xy}
|
|
98
|
+
|
|
99
|
+
results.append(d)
|
|
100
|
+
|
|
101
|
+
pbar.update()
|
|
102
|
+
|
|
103
|
+
pbar.close()
|
|
104
|
+
cap.release()
|
|
105
|
+
cv2.destroyAllWindows()
|
|
106
|
+
|
|
107
|
+
if mask_file:
|
|
108
|
+
|
|
109
|
+
with open(mask_file, "w") as out_file:
|
|
110
|
+
for r in results:
|
|
111
|
+
json_str = json.dumps(r)
|
|
112
|
+
out_file.write(json_str)
|
|
113
|
+
if verbose:
|
|
114
|
+
print("Wrote to {}".format(mask_file))
|
|
115
|
+
|
|
116
|
+
return results
|
|
117
|
+
|
|
118
|
+
def segment_single(self, input_video:str, frame:int=None):
|
|
119
|
+
return self.segment(input_video, mask_file=None,
|
|
120
|
+
video_index=None, video_tot=None,
|
|
121
|
+
start_frame=frame, end_frame=frame,
|
|
122
|
+
verbose=False)
|
|
123
|
+
|
|
124
|
+
def segment_zone(self, input_video:str, frame:int=None, zone:list=None) -> list:
|
|
125
|
+
'''
|
|
126
|
+
Segment the video in a specific zone
|
|
127
|
+
input_video: Path to video
|
|
128
|
+
frame: Frame number to segment
|
|
129
|
+
zone: Polygon zone to segment
|
|
130
|
+
Return:
|
|
131
|
+
List of segmented objects in the zone
|
|
132
|
+
'''
|
|
133
|
+
|
|
134
|
+
# open input video
|
|
135
|
+
cap = cv2.VideoCapture(input_video)
|
|
136
|
+
if not cap.isOpened():
|
|
137
|
+
print('Failed to open the video!')
|
|
138
|
+
|
|
139
|
+
if frame <0 or frame > int(cap.get(cv2.CAP_PROP_FRAME_COUNT))-1:
|
|
140
|
+
raise Exception('The given frame is out of range!')
|
|
141
|
+
|
|
142
|
+
cap.set(cv2.CAP_PROP_POS_FRAMES, frame)
|
|
143
|
+
ret, frame = cap.read()
|
|
144
|
+
if ret:
|
|
145
|
+
x1, y1, x2, y2 = zone
|
|
146
|
+
cropped_frame = frame[y1:y2, x1:x2]
|
|
147
|
+
detects = self.model.predict(cropped_frame, verbose=False, conf=self.conf, iou=self.nms, max_det=self.max_det, half=self.half)
|
|
148
|
+
if len(detects)>0:
|
|
149
|
+
if detects[0].masks is not None:
|
|
150
|
+
xy = list(map(lambda x: x.tolist(), detects[0].masks.xy))
|
|
151
|
+
print(xy)
|
|
152
|
+
input('.')
|
|
153
|
+
cap.release()
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
if __name__=="__main__":
|
|
157
|
+
|
|
158
|
+
segmentor = Segmentor()
|
|
159
|
+
#segmentor.segment('/mnt/d/videos/samples/traffic_short.mp4', '/mnt/d/videos/samples/traffic_short_mask.json', start_frame=1, end_frame=1)
|
|
160
|
+
input_video = '/mnt/d/videos/hyde/after_2024-08-15_nw.mp4'
|
|
161
|
+
tracks = pd.read_csv('/mnt/d/videos/hyde/tracks/after_2024-08-15_nw_track_veh_rt.txt')
|
|
162
|
+
tracks.columns = ['frame', 'track', 'x', 'y', 'w', 'h', 'r1', 'r2', 'r3', 'r4']
|
|
163
|
+
dets = tracks[tracks['track'] == 678]
|
|
164
|
+
dets.sort_values(by='frame', inplace=True)
|
|
165
|
+
|
|
166
|
+
for index, det in dets.iterrows():
|
|
167
|
+
zone = (int(det['x']), int(det['y']), int(det['x'] + det['w']), int(det['y'] + det['h']))
|
|
168
|
+
frame = int(det['frame'])
|
|
169
|
+
|
|
170
|
+
segmentor.segment_zone(input_video, frame, zone) # Segment the specific zone
|
|
171
|
+
print(f"Segmented frame {frame}")
|
dnt/engine/__init__.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# bbox_interpolation.pyx
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from scipy.interpolate import CubicSpline, interp1d
|
|
5
|
+
|
|
6
|
+
# Define the function signature
|
|
7
|
+
def interpolate_bbox(boxes:np.ndarray, frames:np.ndarray, target_frame:int, method='cubic')->np.ndarray:
|
|
8
|
+
"""
|
|
9
|
+
Interpolates bounding boxes using cubic splines.
|
|
10
|
+
|
|
11
|
+
Parameters:
|
|
12
|
+
- boxes: a (n, 4) array of bounding box coordinates (x, y, width, height).
|
|
13
|
+
- frames: a (n,) array of frame indices corresponding to the bounding boxes.
|
|
14
|
+
- target_frame: the frame index at which to interpolate the bounding box.
|
|
15
|
+
- method: the spline function, default is 'cubic', 'nearest', 'linear'
|
|
16
|
+
Returns:
|
|
17
|
+
- A 1d array (x, y, width, height) representing the interpolated bounding box.
|
|
18
|
+
"""
|
|
19
|
+
n = boxes.shape[0]
|
|
20
|
+
|
|
21
|
+
if n != frames.shape[0]:
|
|
22
|
+
raise ValueError("Length of boxes and frames must be equal.")
|
|
23
|
+
|
|
24
|
+
if n == 0:
|
|
25
|
+
raise ValueError("Input arrays must not be empty.")
|
|
26
|
+
|
|
27
|
+
if target_frame < frames[0] or target_frame > frames[-1]:
|
|
28
|
+
raise ValueError("Target frame is out of bounds.")
|
|
29
|
+
|
|
30
|
+
# Unpack the boxes into separate arrays for x, y, width, and height
|
|
31
|
+
x = boxes[:, 0]
|
|
32
|
+
y = boxes[:, 1]
|
|
33
|
+
w = boxes[:, 2]
|
|
34
|
+
h = boxes[:, 3]
|
|
35
|
+
|
|
36
|
+
# Create the cubic splines for each parameter
|
|
37
|
+
if method == 'cubic':
|
|
38
|
+
spline_x = CubicSpline(frames, x)
|
|
39
|
+
spline_y = CubicSpline(frames, y)
|
|
40
|
+
spline_w = CubicSpline(frames, w)
|
|
41
|
+
spline_h = CubicSpline(frames, h)
|
|
42
|
+
elif method == 'nearest':
|
|
43
|
+
spline_x = interp1d(frames, x, kind='nearest')
|
|
44
|
+
spline_y = interp1d(frames, y, kind='nearest')
|
|
45
|
+
spline_w = interp1d(frames, w, kind='nearest')
|
|
46
|
+
spline_h = interp1d(frames, h, kind='nearest')
|
|
47
|
+
else:
|
|
48
|
+
spline_x = interp1d(frames, x, kind='linear')
|
|
49
|
+
spline_y = interp1d(frames, y, kind='linear')
|
|
50
|
+
spline_w = interp1d(frames, w, kind='linear')
|
|
51
|
+
spline_h = interp1d(frames, h, kind='linear')
|
|
52
|
+
|
|
53
|
+
# Evaluate the splines at the target frame
|
|
54
|
+
x_t = int(spline_x(target_frame))
|
|
55
|
+
y_t = int(spline_y(target_frame))
|
|
56
|
+
w_t = int(spline_w(target_frame))
|
|
57
|
+
h_t = int(spline_h(target_frame))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
return np.array([x_t, y_t, w_t, h_t])
|
|
61
|
+
|
|
62
|
+
def interpolate_bboxes(boxes:np.ndarray, frames:np.ndarray, target_frames:np.ndarray, method='cubic')->np.ndarray:
|
|
63
|
+
"""
|
|
64
|
+
Interpolates bounding boxes using cubic splines.
|
|
65
|
+
|
|
66
|
+
Parameters:
|
|
67
|
+
- boxes: a (n, 4) array of bounding box coordinates (x, y, width, height).
|
|
68
|
+
- frames: a (n,) array of frame indices corresponding to the bounding boxes.
|
|
69
|
+
- target_frames: the frame indexes at which to interpolate the bounding boxes.
|
|
70
|
+
- method: the spline function, default is 'cubic', 'nearest', 'linear'
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
- List of tuple (x, y, width, height) representing the interpolated bounding boxes.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
n_frames = target_frames.shape[0]
|
|
77
|
+
results = []
|
|
78
|
+
|
|
79
|
+
for i in range(n_frames):
|
|
80
|
+
target_frame = target_frames[i]
|
|
81
|
+
results.append(interpolate_bbox(boxes, frames, target_frame, method))
|
|
82
|
+
|
|
83
|
+
return np.vstack(results)
|
dnt/engine/bbox_iou.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from cython_bbox import bbox_overlaps
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
def ious(atlbrs, btlbrs):
|
|
5
|
+
"""
|
|
6
|
+
Compute cost based on IoU
|
|
7
|
+
:type atlbrs: list[tlbr] | np.ndarray
|
|
8
|
+
:type atlbrs: list[tlbr] | np.ndarray
|
|
9
|
+
|
|
10
|
+
:rtype ious np.ndarray
|
|
11
|
+
"""
|
|
12
|
+
ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=np.float64)
|
|
13
|
+
if ious.size == 0:
|
|
14
|
+
return ious
|
|
15
|
+
|
|
16
|
+
ious = bbox_overlaps(
|
|
17
|
+
np.ascontiguousarray(atlbrs, dtype=np.float64),
|
|
18
|
+
np.ascontiguousarray(btlbrs, dtype=np.float64))
|
|
19
|
+
|
|
20
|
+
return ious
|
dnt/engine/cluster.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def cluster_by_gap(arr:np.ndarray, gap:int)->list:
|
|
4
|
+
'''
|
|
5
|
+
Parameters:
|
|
6
|
+
- arr: a 1d array for clustering
|
|
7
|
+
- gap: the threshold to break (> gap)
|
|
8
|
+
|
|
9
|
+
Returns:
|
|
10
|
+
- list of clustered numbers (lists)
|
|
11
|
+
'''
|
|
12
|
+
# Sort the array to process it in order
|
|
13
|
+
arr.sort()
|
|
14
|
+
clusters = []
|
|
15
|
+
current_cluster = [arr[0]]
|
|
16
|
+
|
|
17
|
+
# Iterate through the sorted list
|
|
18
|
+
for i in range(1, len(arr)):
|
|
19
|
+
if arr[i] - arr[i-1] <= gap:
|
|
20
|
+
# If the gap condition is met, add to the current cluster
|
|
21
|
+
current_cluster.append(arr[i])
|
|
22
|
+
else:
|
|
23
|
+
# If the gap condition is not met, start a new cluster
|
|
24
|
+
clusters.append(current_cluster)
|
|
25
|
+
current_cluster = [arr[i]]
|
|
26
|
+
|
|
27
|
+
# Add the last cluster
|
|
28
|
+
clusters.append(current_cluster)
|
|
29
|
+
|
|
30
|
+
return clusters
|
|
31
|
+
|
dnt/engine/iob.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
def iob(box_a:np.ndarray, box_b:np.ndarray)->tuple:
|
|
4
|
+
"""
|
|
5
|
+
Calculate the Intersection over Box (IoB) between two bounding boxes.
|
|
6
|
+
|
|
7
|
+
Parameters:
|
|
8
|
+
box_a -- numpy arrays of shape (4,) containing [l, t, w, h]
|
|
9
|
+
box_b -- numpy arrays of shape (4,) containing [l, t, w, h], target bounding box
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
iob, iob -- float, the IoB values for box_a and box_b
|
|
13
|
+
"""
|
|
14
|
+
# Determine the (x, y)-coordinates of the intersection rectangle
|
|
15
|
+
x_l = max(box_a[0], box_b[0])
|
|
16
|
+
y_t = max(box_a[1], box_b[1])
|
|
17
|
+
x_r = min(box_a[0]+box_a[2], box_b[0]+box_b[2])
|
|
18
|
+
y_b = min(box_a[1]+box_a[3], box_b[1]+box_b[3])
|
|
19
|
+
|
|
20
|
+
# Compute the area of intersection rectangle
|
|
21
|
+
inter_width = max(0, x_r - x_l)
|
|
22
|
+
inter_height = max(0, y_b - y_t)
|
|
23
|
+
inter_area = inter_width * inter_height
|
|
24
|
+
|
|
25
|
+
# Compute the area of both the prediction and ground-truth rectangles
|
|
26
|
+
box_a_area = box_a[2] * box_a[3]
|
|
27
|
+
box_b_area = box_b[2] * box_b[3]
|
|
28
|
+
|
|
29
|
+
# Compute the intersection over union by taking the intersection area and dividing it by the sum of prediction + ground-truth areas - the intersection area
|
|
30
|
+
iob_a = inter_area / box_a_area if box_a_area != 0 else 0.0
|
|
31
|
+
iob_b = inter_area / box_b_area if box_b_area != 0 else 0.0
|
|
32
|
+
|
|
33
|
+
return iob_a, iob_b
|
|
34
|
+
|
|
35
|
+
def iobs(alrbs:np.ndarray, blrbs:np.ndarray)->np.ndarray:
|
|
36
|
+
"""
|
|
37
|
+
Calculate the IoU matrix for multiple bounding boxes.
|
|
38
|
+
|
|
39
|
+
Parameters:
|
|
40
|
+
boxes -- numpy array of shape (N, 4), where N is the number of boxes, and each row is [x1, y1, x2, y2]
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
iou_matrix -- numpy array of shape (N, N), where iou_matrix[i, j] is the IoU between boxes[i] and boxes[j]
|
|
44
|
+
"""
|
|
45
|
+
num_a = alrbs.shape[0]
|
|
46
|
+
num_b = blrbs.shape[0]
|
|
47
|
+
iobs_a = np.zeros((num_a, num_b))
|
|
48
|
+
iobs_b = np.zeros((num_a, num_b))
|
|
49
|
+
|
|
50
|
+
for i in range(num_a):
|
|
51
|
+
for j in range(num_b):
|
|
52
|
+
iobs_a[i, j], iobs_b[i, j] = iob(alrbs[i,:], blrbs[j,:])
|
|
53
|
+
|
|
54
|
+
return iobs_a, iobs_b
|
|
55
|
+
|
|
56
|
+
if __name__ == '__main__':
|
|
57
|
+
# Example usage
|
|
58
|
+
boxes = np.array([
|
|
59
|
+
[0, 0, 1, 1],
|
|
60
|
+
[0.5, 0.5, 1.5, 1.5],
|
|
61
|
+
[1, 1, 2, 2]
|
|
62
|
+
])
|
|
63
|
+
|
|
64
|
+
matrix_a, matrix_b = iobs(boxes, boxes)
|
|
65
|
+
print(matrix_a)
|
|
66
|
+
print(matrix_b)
|
dnt/filter/__init__.py
CHANGED