├── .idea ├── .gitignore ├── UnTrack.iml ├── inspectionProfiles │ └── profiles_settings.xml ├── modules.xml └── vcs.xml ├── Depthtrack_workspace ├── config.yaml ├── list.txt └── trackers.ini ├── README.md ├── RGBE_workspace └── test_rgbe_mgpus.py ├── RGBT_workspace ├── attributes_RGBT234.xlsx └── test_rgbt_mgpus.py ├── download_vot.py ├── environment.yaml ├── eval_all.sh ├── eval_rgbd.sh ├── eval_rgbe.sh ├── eval_rgbt.sh ├── eval_rgbtlasher.sh ├── eval_rgbvotd.sh ├── experiments └── untrack │ ├── deep_rgbd.yaml │ ├── deep_rgbe.yaml │ ├── deep_rgbt.yaml │ └── deep_rgbx.yaml ├── install.sh ├── lib ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-310.pyc │ └── __init__.cpython-37.pyc ├── config │ └── untrack │ │ ├── __pycache__ │ │ └── config.cpython-37.pyc │ │ └── config.py ├── models │ ├── __init__.py │ ├── __pycache__ │ │ └── __init__.cpython-37.pyc │ ├── layers │ │ ├── MoE_prompt.py │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── MoE_prompt.cpython-37.pyc │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── attn.cpython-37.pyc │ │ │ ├── attn_blocks.cpython-37.pyc │ │ │ ├── frozen_bn.cpython-37.pyc │ │ │ ├── head.cpython-37.pyc │ │ │ ├── patch_embed.cpython-37.pyc │ │ │ └── rpe.cpython-37.pyc │ │ ├── attn.py │ │ ├── attn_blocks.py │ │ ├── frozen_bn.py │ │ ├── head.py │ │ ├── patch_embed.py │ │ └── rpe.py │ └── untrack │ │ ├── __init__.py │ │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ ├── attention.cpython-37.pyc │ │ ├── base_backbone.cpython-37.pyc │ │ ├── ostrack.cpython-37.pyc │ │ ├── ostrack_prompt.cpython-37.pyc │ │ ├── utils.cpython-37.pyc │ │ ├── vit.cpython-37.pyc │ │ ├── vit_ce.cpython-37.pyc │ │ ├── vit_ce_prompt.cpython-37.pyc │ │ └── vit_prompt.cpython-37.pyc │ │ ├── attention.py │ │ ├── base_backbone.py │ │ ├── ostrack.py │ │ ├── ostrack_prompt.py │ │ ├── test_gradient.py │ │ ├── utils.py │ │ ├── vit.py │ │ ├── vit_ce.py │ │ ├── vit_ce_prompt.py │ │ └── vit_prompt.py ├── test │ ├── evaluation │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── data.cpython-37.pyc │ │ │ ├── datasets.cpython-37.pyc │ │ │ ├── environment.cpython-37.pyc │ │ │ ├── local.cpython-37.pyc │ │ │ ├── running.cpython-37.pyc │ │ │ ├── tracker.cpython-37.pyc │ │ │ └── votdataset.cpython-37.pyc │ │ ├── data.py │ │ ├── datasets.py │ │ ├── environment.py │ │ ├── local.py │ │ ├── running.py │ │ ├── tracker.py │ │ ├── votdataset.py │ │ └── vtuavdataset.py │ ├── parameter │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── untrack.cpython-37.pyc │ │ │ └── vipt.cpython-37.pyc │ │ └── untrack.py │ ├── tracker │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── basetracker.cpython-37.pyc │ │ │ ├── data_utils.cpython-37.pyc │ │ │ ├── ostrack.cpython-37.pyc │ │ │ ├── untrack.cpython-37.pyc │ │ │ ├── vipt.cpython-37.pyc │ │ │ └── vis_utils.cpython-37.pyc │ │ ├── basetracker.py │ │ ├── data_utils.py │ │ ├── ostrack.py │ │ ├── untrack.py │ │ └── vis_utils.py │ ├── utils │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── hann.cpython-37.pyc │ │ │ └── params.cpython-37.pyc │ │ ├── _init_paths.py │ │ ├── hann.py │ │ ├── load_text.py │ │ └── params.py │ └── vot │ │ ├── __pycache__ │ │ ├── untrack_baseline.cpython-37.pyc │ │ ├── untrack_class.cpython-37.pyc │ │ ├── vipt_baseline.cpython-37.pyc │ │ ├── vipt_class.cpython-37.pyc │ │ ├── vot.cpython-37.pyc │ │ └── vot22_utils.cpython-37.pyc │ │ ├── untrack_baseline.py │ │ ├── untrack_class.py │ │ ├── vot.py │ │ └── vot22_utils.py ├── train │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-310.pyc │ │ ├── __init__.cpython-37.pyc │ │ ├── _init_paths.cpython-310.pyc │ │ ├── _init_paths.cpython-37.pyc │ │ ├── base_functions.cpython-37.pyc │ │ └── train_script.cpython-37.pyc │ ├── _init_paths.py │ ├── actors │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── base_actor.cpython-37.pyc │ │ │ ├── untrack.cpython-37.pyc │ │ │ └── vipt.cpython-37.pyc │ │ ├── base_actor.py │ │ └── untrack.py │ ├── admin │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-310.pyc │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── environment.cpython-310.pyc │ │ │ ├── environment.cpython-37.pyc │ │ │ ├── local.cpython-37.pyc │ │ │ ├── multigpu.cpython-310.pyc │ │ │ ├── multigpu.cpython-37.pyc │ │ │ ├── settings.cpython-310.pyc │ │ │ ├── settings.cpython-37.pyc │ │ │ ├── stats.cpython-310.pyc │ │ │ ├── stats.cpython-37.pyc │ │ │ ├── tensorboard.cpython-310.pyc │ │ │ └── tensorboard.cpython-37.pyc │ │ ├── environment.py │ │ ├── local.py │ │ ├── multigpu.py │ │ ├── settings.py │ │ ├── stats.py │ │ └── tensorboard.py │ ├── base_functions.py │ ├── data │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── image_loader.cpython-37.pyc │ │ │ ├── loader.cpython-37.pyc │ │ │ ├── processing.cpython-37.pyc │ │ │ ├── processing_utils.cpython-37.pyc │ │ │ ├── sampler.cpython-37.pyc │ │ │ ├── transforms.cpython-37.pyc │ │ │ └── wandb_logger.cpython-37.pyc │ │ ├── bounding_box_utils.py │ │ ├── image_loader.py │ │ ├── loader.py │ │ ├── processing.py │ │ ├── processing_utils.py │ │ ├── sampler.py │ │ ├── transforms.py │ │ └── wandb_logger.py │ ├── data_specs │ │ ├── README.md │ │ ├── depthtrack_train.txt │ │ ├── depthtrack_val.txt │ │ ├── got10k_train_full_split.txt │ │ ├── got10k_train_split.txt │ │ ├── got10k_val_split.txt │ │ ├── got10k_vot_exclude.txt │ │ ├── got10k_vot_train_split.txt │ │ ├── got10k_vot_val_split.txt │ │ ├── lasher_all.txt │ │ ├── lasher_train.txt │ │ ├── lasher_val.txt │ │ ├── lasot_train_split.txt │ │ ├── trackingnet_classmap.txt │ │ └── visevent_train.txt │ ├── dataset │ │ ├── COCO_tool.py │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── COCO_tool.cpython-37.pyc │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── base_image_dataset.cpython-37.pyc │ │ │ ├── base_video_dataset.cpython-37.pyc │ │ │ ├── coco.cpython-37.pyc │ │ │ ├── coco_seq.cpython-37.pyc │ │ │ ├── coco_seq_lmdb.cpython-37.pyc │ │ │ ├── depth_utils.cpython-37.pyc │ │ │ ├── depthtrack.cpython-37.pyc │ │ │ ├── got10k.cpython-37.pyc │ │ │ ├── got10k_lmdb.cpython-37.pyc │ │ │ ├── imagenetvid.cpython-37.pyc │ │ │ ├── imagenetvid_lmdb.cpython-37.pyc │ │ │ ├── lasher.cpython-37.pyc │ │ │ ├── lasot.cpython-37.pyc │ │ │ ├── lasot_lmdb.cpython-37.pyc │ │ │ ├── tracking_net.cpython-37.pyc │ │ │ ├── tracking_net_lmdb.cpython-37.pyc │ │ │ └── visevent.cpython-37.pyc │ │ ├── base_image_dataset.py │ │ ├── base_video_dataset.py │ │ ├── coco.py │ │ ├── coco_seq.py │ │ ├── coco_seq_lmdb.py │ │ ├── depth_utils.py │ │ ├── depthtrack.py │ │ ├── got10k.py │ │ ├── got10k_lmdb.py │ │ ├── imagenetvid.py │ │ ├── imagenetvid_lmdb.py │ │ ├── lasher.py │ │ ├── lasot.py │ │ ├── lasot_lmdb.py │ │ ├── open_set.py │ │ ├── tracking_net.py │ │ ├── tracking_net_lmdb.py │ │ └── visevent.py │ ├── run_training.py │ ├── train_script.py │ └── trainers │ │ ├── __init__.py │ │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ ├── base_trainer.cpython-37.pyc │ │ └── ltr_trainer.cpython-37.pyc │ │ ├── base_trainer.py │ │ └── ltr_trainer.py ├── utils │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ ├── box_ops.cpython-37.pyc │ │ ├── ce_utils.cpython-37.pyc │ │ ├── focal_loss.cpython-37.pyc │ │ ├── heapmap_utils.cpython-37.pyc │ │ ├── lmdb_utils.cpython-37.pyc │ │ ├── misc.cpython-37.pyc │ │ └── tensor.cpython-37.pyc │ ├── box_ops.py │ ├── ce_utils.py │ ├── focal_loss.py │ ├── heapmap_utils.py │ ├── lmdb_utils.py │ ├── merge.py │ ├── misc.py │ └── tensor.py └── vis │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── plotting.cpython-37.pyc │ ├── utils.cpython-37.pyc │ └── visdom_cus.cpython-37.pyc │ ├── plotting.py │ ├── utils.py │ └── visdom_cus.py ├── requirements.txt ├── tracking ├── __pycache__ │ └── _init_paths.cpython-37.pyc ├── _init_paths.py ├── create_default_local_file.py ├── test.py └── train.py └── train.sh /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/UnTrack.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Depthtrack_workspace/config.yaml: -------------------------------------------------------------------------------- 1 | registry: 2 | - ./trackers.ini 3 | stack: ./votrgbd2021.yaml 4 | -------------------------------------------------------------------------------- /Depthtrack_workspace/list.txt: -------------------------------------------------------------------------------- 1 | pot_indoor 2 | cube05_indoor 3 | book03_indoor 4 | cup12_indoor 5 | toy02_indoor 6 | human02_indoor 7 | ball15_wild 8 | cat01_indoor 9 | bag02_indoor 10 | duck03_wild 11 | ball18_indoor 12 | ball20_indoor 13 | shoes02_indoor 14 | flag_indoor 15 | toy09_indoor 16 | cup01_indoor 17 | bottle04_indoor 18 | card_indoor 19 | ukulele01_indoor 20 | mobilephone03_indoor 21 | cube02_indoor 22 | cup02_indoor 23 | file01_indoor 24 | notebook01_indoor 25 | yogurt_indoor 26 | lock02_indoor 27 | beautifullight02_indoor 28 | toiletpaper01_indoor 29 | pigeon01_wild 30 | cube03_indoor 31 | ball06_indoor 32 | roller_indoor 33 | colacan03_indoor 34 | backpack_indoor 35 | bag01_indoor 36 | ball11_wild 37 | hand01_indoor 38 | stick_indoor 39 | earphone01_indoor 40 | cup04_indoor 41 | ball01_wild 42 | pigeon02_wild 43 | adapter01_indoor 44 | pigeon04_wild 45 | dumbbells01_indoor 46 | ball10_wild 47 | glass01_indoor 48 | squirrel_wild 49 | bandlight_indoor 50 | developmentboard_indoor 51 | -------------------------------------------------------------------------------- /Depthtrack_workspace/trackers.ini: -------------------------------------------------------------------------------- 1 | [untrack_deep] # 2 | label = untrack_deep 3 | protocol = traxpython 4 | 5 | command = untrack_baseline 6 | 7 | # Specify a path to trax python wrapper if it is not visible (separate by ; if using multiple paths) 8 | paths = /home/zwu/Tracking/lib/test/vot 9 | 10 | # Additional environment paths 11 | # env_PATH = ${PATH} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnTrack CVPR 2024 2 | 3 | Official implementation of "Single-Model and Any-Modality for Video Object Tracking" CVPR 2024 ([arxiv](https://arxiv.org/abs/2311.15851)) 4 | 5 | We propose Un-Track, a Unified Tracker of a single set of parameters for any modality, which learns their common latent space with only the RGB-X pairs. This unique shared representation seamlessly binds all modalities together, enabling effective unification and accommodating any missing modality, all within a single transformer-based architecture and without the need for modality-specific fine-tuning. 6 | 7 | # Results 8 | 9 | Our ckpt can be found here ([Google Drive](https://drive.google.com/file/d/13GqlmhCKDl6jWJFvAsijuhOXD3kGJqqv/view?usp=sharing)) 10 | 11 | Put the ckpt into the "models" folder. 12 | 13 | You should then be able to obtain our UnTrack results, which can also be downloaded here ([Google Drive](https://drive.google.com/file/d/1ruCYxvXnmtmfQQxV4t_JAsU9bneyPqIT/view?usp=sharing)) 14 | 15 | A comparison against [ViPT](https://github.com/jiawen-zhu/ViPT) (SOTA specialized method) and [SeqTrack](https://github.com/microsoft/VideoX/tree/master/SeqTrack) (SOTA Tracker) can found in the following video: 16 | 17 | [![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/MNvKQCeMLxg/0.jpg)](https://www.youtube.com/watch?v=MNvKQCeMLxg) 18 | 19 | 20 | 21 | ## Notes 22 | 23 | Our shared embedding is somehow similar to a Mixture of Experts (MoE) model. 24 | 25 | The difference is that we manually force the network to pick the best expert, according to the sensor prior, for feature processing. 26 | 27 | We have also developed a generalist and blind tracker, where the MoE is formally introduced and dynamically assigns the most appropriate expert for feature processing. 28 | 29 | More details can be found in the [[Preprint](https://arxiv.org/pdf/2405.17773)] or [[GitHub](https://github.com/supertyd/XTrack)] 30 | 31 | # Acknowledgments 32 | This repository is heavily based on [ViPT](https://github.com/jiawen-zhu/ViPT) and [OSTrack](https://github.com/botaoye/OSTrack). Thanks to their great work! 33 | -------------------------------------------------------------------------------- /RGBT_workspace/attributes_RGBT234.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/RGBT_workspace/attributes_RGBT234.xlsx -------------------------------------------------------------------------------- /environment.yaml: -------------------------------------------------------------------------------- 1 | name: untrack 2 | channels: 3 | - pytorch 4 | - nvidia 5 | - defaults 6 | dependencies: 7 | - _libgcc_mutex=0.1=main 8 | - _openmp_mutex=5.1=1_gnu 9 | - blas=1.0=mkl 10 | - brotlipy=0.7.0=py37h27cfd23_1003 11 | - bzip2=1.0.8=h7b6447c_0 12 | - ca-certificates=2023.05.30=h06a4308_0 13 | - certifi=2022.12.7=py37h06a4308_0 14 | - cffi=1.15.1=py37h5eee18b_3 15 | - chardet=4.0.0=py37h06a4308_1003 16 | - cryptography=39.0.1=py37h9ce1e76_0 17 | - cuda-cudart=11.7.99=0 18 | - cuda-cupti=11.7.101=0 19 | - cuda-libraries=11.7.1=0 20 | - cuda-nvrtc=11.7.99=0 21 | - cuda-nvtx=11.7.91=0 22 | - cuda-runtime=11.7.1=0 23 | - cudatoolkit=10.2.89=hfd86e86_1 24 | - ffmpeg=4.3=hf484d3e_0 25 | - freetype=2.12.1=h4a9f257_0 26 | - giflib=5.2.1=h5eee18b_3 27 | - gmp=6.2.1=h295c915_3 28 | - gnutls=3.6.15=he1e5248_0 29 | - idna=3.4=py37h06a4308_0 30 | - intel-openmp=2021.4.0=h06a4308_3561 31 | - jpeg=9e=h5eee18b_1 32 | - lame=3.100=h7b6447c_0 33 | - lcms2=2.12=h3be6417_0 34 | - ld_impl_linux-64=2.38=h1181459_1 35 | - lerc=3.0=h295c915_0 36 | - libcublas=11.10.3.66=0 37 | - libcufft=10.7.2.124=h4fbf590_0 38 | - libcufile=1.7.0.149=0 39 | - libcurand=10.3.3.53=0 40 | - libcusolver=11.4.0.1=0 41 | - libcusparse=11.7.4.91=0 42 | - libdeflate=1.17=h5eee18b_0 43 | - libffi=3.4.4=h6a678d5_0 44 | - libgcc-ng=11.2.0=h1234567_1 45 | - libgomp=11.2.0=h1234567_1 46 | - libiconv=1.16=h7f8727e_2 47 | - libidn2=2.3.4=h5eee18b_0 48 | - libnpp=11.7.4.75=0 49 | - libnvjpeg=11.8.0.2=0 50 | - libpng=1.6.39=h5eee18b_0 51 | - libstdcxx-ng=11.2.0=h1234567_1 52 | - libtasn1=4.19.0=h5eee18b_0 53 | - libtiff=4.5.0=h6a678d5_2 54 | - libunistring=0.9.10=h27cfd23_0 55 | - libuv=1.44.2=h5eee18b_0 56 | - libwebp=1.2.4=h11a3e52_1 57 | - libwebp-base=1.2.4=h5eee18b_1 58 | - lz4-c=1.9.4=h6a678d5_0 59 | - mkl=2021.4.0=h06a4308_640 60 | - mkl-service=2.4.0=py37h7f8727e_0 61 | - mkl_fft=1.3.1=py37hd3c417c_0 62 | - mkl_random=1.2.2=py37h51133e4_0 63 | - ncurses=6.4=h6a678d5_0 64 | - nettle=3.7.3=hbbd107a_1 65 | - ninja=1.10.2=h06a4308_5 66 | - ninja-base=1.10.2=hd09550d_5 67 | - numpy=1.21.5=py37h6c91a56_3 68 | - numpy-base=1.21.5=py37ha15fc14_3 69 | - openh264=2.1.1=h4ff587b_0 70 | - openssl=1.1.1u=h7f8727e_0 71 | - pillow=9.4.0=py37h6a678d5_0 72 | - pip=22.3.1=py37h06a4308_0 73 | - pycparser=2.21=pyhd3eb1b0_0 74 | - pyopenssl=23.0.0=py37h06a4308_0 75 | - pysocks=1.7.1=py37_1 76 | - python=3.7.16=h7a1cb2a_0 77 | - pytorch=1.13.1=py3.7_cuda11.7_cudnn8.5.0_0 78 | - pytorch-cuda=11.7=h778d358_5 79 | - pytorch-mutex=1.0=cuda 80 | - readline=8.2=h5eee18b_0 81 | - setuptools=65.6.3=py37h06a4308_0 82 | - six=1.16.0=pyhd3eb1b0_1 83 | - sqlite=3.41.2=h5eee18b_0 84 | - tk=8.6.12=h1ccaba5_0 85 | - torchaudio=0.13.1=py37_cu117 86 | - torchvision=0.14.1=py37_cu117 87 | - tqdm=4.64.1=py37h06a4308_0 88 | - typing_extensions=4.3.0=py37h06a4308_0 89 | - wheel=0.38.4=py37h06a4308_0 90 | - xz=5.4.2=h5eee18b_0 91 | - zlib=1.2.13=h5eee18b_0 92 | - zstd=1.5.5=hc292b87_0 93 | - pip: 94 | - absl-py==1.4.0 95 | - appdirs==1.4.4 96 | - attributee==0.1.8 97 | - attrs==23.1.0 98 | - bidict==0.22.1 99 | - cachetools==5.3.1 100 | - charset-normalizer==3.2.0 101 | - click==8.1.7 102 | - colorama==0.4.6 103 | - cycler==0.11.0 104 | - cython==3.0.0 105 | - dataclasses==0.6 106 | - docker-pycreds==0.4.0 107 | - dominate==2.8.0 108 | - easydict==1.10 109 | - fonttools==4.38.0 110 | - future==0.18.3 111 | - gitdb==4.0.10 112 | - gitpython==3.1.32 113 | - google-auth==2.22.0 114 | - google-auth-oauthlib==0.4.6 115 | - grpcio==1.56.2 116 | - importlib-metadata==6.7.0 117 | - importlib-resources==5.12.0 118 | - info-nce-pytorch==0.1.4 119 | - install==1.3.5 120 | - jpeg4py==0.1.4 121 | - jsonpatch==1.33 122 | - jsonpointer==2.4 123 | - jsonschema==4.17.3 124 | - kiwisolver==1.4.4 125 | - lazy-object-proxy==1.9.0 126 | - llvmlite==0.39.1 127 | - lmdb==1.4.1 128 | - markdown==3.4.3 129 | - markupsafe==2.1.3 130 | - matplotlib==3.5.3 131 | - networkx==2.6.3 132 | - numba==0.56.4 133 | - oauthlib==3.2.2 134 | - opencv-python==4.8.0.74 135 | - ordered-set==4.1.0 136 | - packaging==23.1 137 | - pandas==1.3.5 138 | - pathtools==0.1.2 139 | - phx-class-registry==4.0.6 140 | - pkgutil-resolve-name==1.3.10 141 | - protobuf==3.20.3 142 | - psutil==5.9.5 143 | - pyasn1==0.5.0 144 | - pyasn1-modules==0.3.0 145 | - pycocotools==2.0.6 146 | - pylatex==1.4.1 147 | - pyparsing==3.1.0 148 | - pyrsistent==0.19.3 149 | - python-dateutil==2.8.2 150 | - pytz==2023.3 151 | - pyyaml==6.0.1 152 | - requests==2.31.0 153 | - requests-oauthlib==1.3.1 154 | - rsa==4.9 155 | - scipy==1.7.3 156 | - sentry-sdk==1.30.0 157 | - setproctitle==1.3.2 158 | - smmap==5.0.0 159 | - tb-nightly==2.12.0a20230113 160 | - tensorboard-data-server==0.6.1 161 | - tensorboard-plugin-wit==1.8.1 162 | - tensorly==0.8.1 163 | - timm==0.5.4 164 | - tornado==6.2 165 | - urllib3==1.26.16 166 | - visdom==0.2.4 167 | - vot-toolkit==0.5.3 168 | - vot-trax==3.0.2 169 | - wandb==0.15.9 170 | - websocket-client==1.6.1 171 | - werkzeug==2.2.3 172 | - zipp==3.15.0 173 | prefix: /home/zwu/anaconda3/envs/untrack 174 | -------------------------------------------------------------------------------- /eval_all.sh: -------------------------------------------------------------------------------- 1 | # test lasher 2 | 3 | sh eval_rgbd.sh 4 | CUDA_VISIBLE_DEVICES=0 python ./RGBT_workspace/test_rgbt_mgpus.py --script_name untrack --dataset_name LasHeR --yaml_name deep_rgbt 5 | CUDA_VISIBLE_DEVICES=0 python ./RGBT_workspace/test_rgbt_mgpus.py --script_name untrack --dataset_name LasHeR --yaml_name deep_rgbt 6 | 7 | # test rgbt234 8 | 9 | CUDA_VISIBLE_DEVICES=0 python ./RGBE_workspace/test_rgbe_mgpus.py --script_name untrack --yaml_name deep_rgbe 10 | CUDA_VISIBLE_DEVICES=0 python ./RGBE_workspace/test_rgbe_mgpus.py --script_name untrack --yaml_name deep_rgbe 11 | 12 | 13 | CUDA_VISIBLE_DEVICES=0 python ./RGBT_workspace/test_rgbt_mgpus.py --script_name untrack --dataset_name RGBT234 --yaml_name deep_rgbt 14 | CUDA_VISIBLE_DEVICES=0 python ./RGBT_workspace/test_rgbt_mgpus.py --script_name untrack --dataset_name RGBT234 --yaml_name deep_rgbt 15 | 16 | -------------------------------------------------------------------------------- /eval_rgbd.sh: -------------------------------------------------------------------------------- 1 | # eval depthtrack 2 | cd Depthtrack_workspace 3 | vot evaluate --workspace ./ untrack_deep 4 | vot analysis --nocache --name untrack_deep 5 | cd .. 6 | -------------------------------------------------------------------------------- /eval_rgbe.sh: -------------------------------------------------------------------------------- 1 | # test visevent 2 | CUDA_VISIBLE_DEVICES=0 python ./RGBE_workspace/test_rgbe_mgpus.py --script_name untrack --yaml_name deep_rgbe 3 | -------------------------------------------------------------------------------- /eval_rgbt.sh: -------------------------------------------------------------------------------- 1 | # test lasher 2 | CUDA_VISIBLE_DEVICES=0 python ./RGBT_workspace/test_rgbt_mgpus.py --script_name untrack --dataset_name LasHeR --yaml_name deep_rgbt 3 | 4 | # test rgbt234 5 | CUDA_VISIBLE_DEVICES=0 python ./RGBT_workspace/test_rgbt_mgpus.py --script_name untrack --dataset_name RGBT234 --yaml_name deep_rgbt 6 | -------------------------------------------------------------------------------- /eval_rgbtlasher.sh: -------------------------------------------------------------------------------- 1 | # test lasher 2 | CUDA_VISIBLE_DEVICES=0 python ./RGBT_workspace/test_rgbt_mgpus.py --script_name untrack --dataset_name LasHeR --yaml_name deep_rgbt 3 | -------------------------------------------------------------------------------- /eval_rgbvotd.sh: -------------------------------------------------------------------------------- 1 | # eval depthtrack 2 | #cd Depthtrack_workspace 3 | #vot evaluate --workspace ./ untrack_deep 4 | #vot analysis --nocache --name untrack_deep 5 | #cd .. 6 | 7 | ## eval vot22-rgbd 8 | cd VOT22RGBD_workspace 9 | vot evaluate --workspace ./ untrack_deep 10 | vot analysis --nocache --name untrack_deep 11 | cd .. 12 | 13 | -------------------------------------------------------------------------------- /experiments/untrack/deep_rgbd.yaml: -------------------------------------------------------------------------------- 1 | DATA: 2 | MAX_SAMPLE_INTERVAL: 200 3 | MEAN: 4 | - 0.485 5 | - 0.456 6 | - 0.406 7 | SEARCH: 8 | CENTER_JITTER: 3 9 | FACTOR: 4.0 10 | SCALE_JITTER: 0.25 11 | SIZE: 256 12 | NUMBER: 1 13 | STD: 14 | - 0.229 15 | - 0.224 16 | - 0.225 17 | TEMPLATE: 18 | CENTER_JITTER: 0 19 | FACTOR: 2.0 20 | SCALE_JITTER: 0 21 | SIZE: 128 22 | TRAIN: 23 | DATASETS_NAME: 24 | - DepthTrack_train 25 | DATASETS_RATIO: 26 | - 1 27 | SAMPLE_PER_EPOCH: 60000 28 | VAL: 29 | DATASETS_NAME: 30 | - DepthTrack_val 31 | DATASETS_RATIO: 32 | - 1 33 | SAMPLE_PER_EPOCH: 10000 34 | MODEL: 35 | PRETRAIN_FILE: "./pretrained/OSTrack_ep0300.pth.tar" 36 | EXTRA_MERGER: False 37 | RETURN_INTER: False 38 | BACKBONE: 39 | TYPE: vit_base_patch16_224_ce_prompt 40 | STRIDE: 16 41 | CE_LOC: [3, 6, 9] 42 | CE_KEEP_RATIO: [0.7, 0.7, 0.7] 43 | CE_TEMPLATE_RANGE: 'CTR_POINT' # choose between ALL, CTR_POINT, CTR_REC, GT_BOX 44 | HEAD: 45 | TYPE: CENTER 46 | NUM_CHANNELS: 256 47 | TRAIN: 48 | BACKBONE_MULTIPLIER: 0.1 49 | DROP_PATH_RATE: 0.1 50 | CE_START_EPOCH: 4 # candidate elimination start epoch 1/15 51 | CE_WARM_EPOCH: 16 # candidate elimination warm up epoch 4/15 52 | BATCH_SIZE: 32 53 | EPOCH: 60 54 | GIOU_WEIGHT: 2.0 55 | L1_WEIGHT: 5.0 56 | GRAD_CLIP_NORM: 0.1 57 | LR: 0.0004 58 | LR_DROP_EPOCH: 48 # 4/5 59 | NUM_WORKER: 10 60 | OPTIMIZER: ADAMW 61 | PRINT_INTERVAL: 50 62 | SCHEDULER: 63 | TYPE: step 64 | DECAY_RATE: 0.1 65 | VAL_EPOCH_INTERVAL: 5 66 | WEIGHT_DECAY: 0.0001 67 | AMP: False 68 | PROMPT: 69 | TYPE: deep 70 | FIX_BN: true 71 | SAVE_EPOCH_INTERVAL: 5 72 | SAVE_LAST_N_EPOCH: 1 73 | TEST: 74 | EPOCH: 60 75 | SEARCH_FACTOR: 4.0 76 | SEARCH_SIZE: 256 77 | TEMPLATE_FACTOR: 2.0 78 | TEMPLATE_SIZE: 128 79 | -------------------------------------------------------------------------------- /experiments/untrack/deep_rgbe.yaml: -------------------------------------------------------------------------------- 1 | DATA: 2 | MAX_SAMPLE_INTERVAL: 200 3 | MEAN: 4 | - 0.485 5 | - 0.456 6 | - 0.406 7 | SEARCH: 8 | CENTER_JITTER: 3 9 | FACTOR: 4.0 10 | SCALE_JITTER: 0.25 11 | SIZE: 256 12 | NUMBER: 1 13 | STD: 14 | - 0.229 15 | - 0.224 16 | - 0.225 17 | TEMPLATE: 18 | CENTER_JITTER: 0 19 | FACTOR: 2.0 20 | SCALE_JITTER: 0 21 | SIZE: 128 22 | TRAIN: 23 | DATASETS_NAME: 24 | - VisEvent 25 | DATASETS_RATIO: 26 | - 1 27 | SAMPLE_PER_EPOCH: 60000 28 | VAL: 29 | DATASETS_NAME: 30 | - 31 | DATASETS_RATIO: 32 | - 1 33 | SAMPLE_PER_EPOCH: 10000 34 | MODEL: 35 | PRETRAIN_FILE: "./pretrained/OSTrack_ep0300.pth.tar" 36 | EXTRA_MERGER: False 37 | RETURN_INTER: False 38 | BACKBONE: 39 | TYPE: vit_base_patch16_224_ce_prompt 40 | STRIDE: 16 41 | CE_LOC: [3, 6, 9] 42 | CE_KEEP_RATIO: [0.7, 0.7, 0.7] 43 | CE_TEMPLATE_RANGE: 'CTR_POINT' # choose between ALL, CTR_POINT, CTR_REC, GT_BOX 44 | HEAD: 45 | TYPE: CENTER 46 | NUM_CHANNELS: 256 47 | TRAIN: 48 | BACKBONE_MULTIPLIER: 0.1 49 | DROP_PATH_RATE: 0.1 50 | CE_START_EPOCH: 4 # candidate elimination start epoch 1/15 51 | CE_WARM_EPOCH: 16 # candidate elimination warm up epoch 4/15 52 | BATCH_SIZE: 32 53 | EPOCH: 60 54 | GIOU_WEIGHT: 2.0 55 | L1_WEIGHT: 5.0 56 | GRAD_CLIP_NORM: 0.1 57 | LR: 0.0004 58 | LR_DROP_EPOCH: 48 # 4/5 59 | NUM_WORKER: 10 60 | OPTIMIZER: ADAMW 61 | PRINT_INTERVAL: 50 62 | SCHEDULER: 63 | TYPE: step 64 | DECAY_RATE: 0.1 65 | VAL_EPOCH_INTERVAL: 5 66 | WEIGHT_DECAY: 0.0001 67 | AMP: False 68 | PROMPT: 69 | TYPE: deep 70 | FIX_BN: true 71 | SAVE_EPOCH_INTERVAL: 5 72 | SAVE_LAST_N_EPOCH: 1 73 | TEST: 74 | EPOCH: 60 75 | SEARCH_FACTOR: 4.0 76 | SEARCH_SIZE: 256 77 | TEMPLATE_FACTOR: 2.0 78 | TEMPLATE_SIZE: 128 79 | -------------------------------------------------------------------------------- /experiments/untrack/deep_rgbt.yaml: -------------------------------------------------------------------------------- 1 | DATA: 2 | MAX_SAMPLE_INTERVAL: 200 3 | MEAN: 4 | - 0.485 5 | - 0.456 6 | - 0.406 7 | SEARCH: 8 | CENTER_JITTER: 3 9 | FACTOR: 4.0 10 | SCALE_JITTER: 0.25 11 | SIZE: 256 12 | NUMBER: 1 13 | STD: 14 | - 0.229 15 | - 0.224 16 | - 0.225 17 | TEMPLATE: 18 | CENTER_JITTER: 0 19 | FACTOR: 2.0 20 | SCALE_JITTER: 0 21 | SIZE: 128 22 | TRAIN: 23 | DATASETS_NAME: 24 | - LasHeR_train 25 | DATASETS_RATIO: 26 | - 1 27 | SAMPLE_PER_EPOCH: 60000 28 | VAL: 29 | DATASETS_NAME: 30 | - LasHeR_val 31 | DATASETS_RATIO: 32 | - 1 33 | SAMPLE_PER_EPOCH: 10000 34 | MODEL: 35 | PRETRAIN_FILE: "./pretrained/OSTrack_ep0300.pth.tar" 36 | EXTRA_MERGER: False 37 | RETURN_INTER: False 38 | BACKBONE: 39 | TYPE: vit_base_patch16_224_ce_prompt 40 | STRIDE: 16 41 | CE_LOC: [3, 6, 9] 42 | CE_KEEP_RATIO: [0.7, 0.7, 0.7] 43 | CE_TEMPLATE_RANGE: 'CTR_POINT' # choose between ALL, CTR_POINT, CTR_REC, GT_BOX 44 | HEAD: 45 | TYPE: CENTER 46 | NUM_CHANNELS: 256 47 | TRAIN: 48 | BACKBONE_MULTIPLIER: 0.1 49 | DROP_PATH_RATE: 0.1 50 | CE_START_EPOCH: 4 # candidate elimination start epoch 1/15 51 | CE_WARM_EPOCH: 16 # candidate elimination warm up epoch 4/15 52 | BATCH_SIZE: 64 53 | EPOCH: 60 54 | GIOU_WEIGHT: 2.0 55 | L1_WEIGHT: 5.0 56 | GRAD_CLIP_NORM: 0.1 57 | LR: 0.0004 58 | LR_DROP_EPOCH: 48 # 4/5 59 | NUM_WORKER: 10 60 | OPTIMIZER: ADAMW 61 | PRINT_INTERVAL: 50 62 | SCHEDULER: 63 | TYPE: step 64 | DECAY_RATE: 0.1 65 | VAL_EPOCH_INTERVAL: 5 66 | WEIGHT_DECAY: 0.0001 67 | AMP: False 68 | PROMPT: 69 | TYPE: deep 70 | FIX_BN: true 71 | SAVE_EPOCH_INTERVAL: 5 72 | SAVE_LAST_N_EPOCH: 1 73 | TEST: 74 | EPOCH: 60 75 | SEARCH_FACTOR: 4.0 76 | SEARCH_SIZE: 256 77 | TEMPLATE_FACTOR: 2.0 78 | TEMPLATE_SIZE: 128 79 | -------------------------------------------------------------------------------- /experiments/untrack/deep_rgbx.yaml: -------------------------------------------------------------------------------- 1 | DATA: 2 | MAX_SAMPLE_INTERVAL: 200 3 | MEAN: 4 | - 0.485 5 | - 0.456 6 | - 0.406 7 | SEARCH: 8 | CENTER_JITTER: 3 9 | FACTOR: 4.0 10 | SCALE_JITTER: 0.25 11 | SIZE: 256 12 | NUMBER: 1 13 | STD: 14 | - 0.229 15 | - 0.224 16 | - 0.225 17 | TEMPLATE: 18 | CENTER_JITTER: 0 19 | FACTOR: 2.0 20 | SCALE_JITTER: 0 21 | SIZE: 128 22 | TRAIN: 23 | DATASETS_NAME: 24 | - DepthTrack_LasHeR_VisEvent 25 | DATASETS_RATIO: 26 | - 1 27 | - 1 28 | - 1 29 | SAMPLE_PER_EPOCH: 60000 # 60000 30 | VAL: 31 | DATASETS_NAME: 32 | - DepthTrack_LasHeR_val 33 | DATASETS_RATIO: 34 | - 1 35 | - 1 36 | SAMPLE_PER_EPOCH: 10000 # 10000 37 | MODEL: 38 | PRETRAIN_FILE: "./pretrained/OSTrack_ep0300.pth.tar" 39 | EXTRA_MERGER: False 40 | RETURN_INTER: False 41 | BACKBONE: 42 | TYPE: vit_base_patch16_224_ce_prompt 43 | STRIDE: 16 44 | CE_LOC: [3, 6, 9] 45 | CE_KEEP_RATIO: [0.7, 0.7, 0.7] 46 | CE_TEMPLATE_RANGE: 'CTR_POINT' # choose between ALL, CTR_POINT, CTR_REC, GT_BOX 47 | HEAD: 48 | TYPE: CENTER 49 | NUM_CHANNELS: 256 50 | TRAIN: 51 | BACKBONE_MULTIPLIER: 0.1 52 | DROP_PATH_RATE: 0.1 53 | CE_START_EPOCH: 4 # candidate elimination start epoch 1/15 54 | CE_WARM_EPOCH: 16 # candidate elimination warm up epoch 4/15 55 | BATCH_SIZE: 48 #32 56 | EPOCH: 80 57 | GIOU_WEIGHT: 2.0 58 | L1_WEIGHT: 5.0 59 | GRAD_CLIP_NORM: 0.1 60 | LR: 0.0004 61 | LR_DROP_EPOCH: 48 62 | NUM_WORKER: 10 63 | OPTIMIZER: ADAMW 64 | PRINT_INTERVAL: 50 65 | SCHEDULER: 66 | TYPE: step 67 | DECAY_RATE: 0.1 68 | VAL_EPOCH_INTERVAL: 5 69 | WEIGHT_DECAY: 0.0001 70 | AMP: False 71 | PROMPT: 72 | TYPE: deep 73 | FIX_BN: true 74 | SAVE_EPOCH_INTERVAL: 5 75 | SAVE_LAST_N_EPOCH: 1 76 | TEST: 77 | EPOCH: 60 78 | SEARCH_FACTOR: 4.0 79 | SEARCH_SIZE: 256 80 | TEMPLATE_FACTOR: 2.0 81 | TEMPLATE_SIZE: 128 82 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | echo "****************** Installing pytorch ******************" 2 | conda install -y pytorch==1.7.0 torchvision==0.8.1 cudatoolkit=10.2 -c pytorch 3 | 4 | echo "" 5 | echo "" 6 | echo "****************** Installing yaml ******************" 7 | pip install PyYAML 8 | 9 | echo "" 10 | echo "" 11 | echo "****************** Installing easydict ******************" 12 | pip install easydict 13 | 14 | echo "" 15 | echo "" 16 | echo "****************** Installing cython ******************" 17 | pip install cython 18 | 19 | echo "" 20 | echo "" 21 | echo "****************** Installing opencv-python ******************" 22 | pip install opencv-python 23 | 24 | echo "" 25 | echo "" 26 | echo "****************** Installing pandas ******************" 27 | pip install pandas 28 | 29 | echo "" 30 | echo "" 31 | echo "****************** Installing tqdm ******************" 32 | conda install -y tqdm 33 | 34 | echo "" 35 | echo "" 36 | echo "****************** Installing coco toolkit ******************" 37 | pip install pycocotools 38 | 39 | echo "" 40 | echo "" 41 | echo "****************** Installing jpeg4py python wrapper ******************" 42 | apt-get install libturbojpeg 43 | pip install jpeg4py 44 | 45 | echo "" 46 | echo "" 47 | echo "****************** Installing scipy ******************" 48 | pip install scipy 49 | 50 | echo "" 51 | echo "" 52 | echo "****************** Installing timm ******************" 53 | pip install timm==0.5.4 54 | 55 | echo "" 56 | echo "" 57 | echo "****************** Installing tensorboard ******************" 58 | pip install tb-nightly 59 | 60 | echo "" 61 | echo "" 62 | echo "****************** Installing lmdb ******************" 63 | pip install lmdb 64 | 65 | echo "" 66 | echo "" 67 | echo "****************** Installing visdom ******************" 68 | pip install visdom 69 | 70 | echo "" 71 | echo "" 72 | echo "****************** Installing vot-toolkit python ******************" 73 | pip install git+https://github.com/votchallenge/vot-toolkit-python 74 | 75 | echo "****************** Installation complete! ******************" -------------------------------------------------------------------------------- /lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/__init__.py -------------------------------------------------------------------------------- /lib/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /lib/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/config/untrack/__pycache__/config.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/config/untrack/__pycache__/config.cpython-37.pyc -------------------------------------------------------------------------------- /lib/config/untrack/config.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | import yaml 3 | 4 | """ 5 | Add default config for UnTrack. 6 | """ 7 | cfg = edict() 8 | 9 | # MODEL 10 | cfg.MODEL = edict() 11 | cfg.MODEL.PRETRAIN_FILE = "" 12 | cfg.MODEL.EXTRA_MERGER = False 13 | cfg.MODEL.RETURN_INTER = False 14 | cfg.MODEL.RETURN_STAGES = [] 15 | 16 | # MODEL.BACKBONE 17 | cfg.MODEL.BACKBONE = edict() 18 | cfg.MODEL.BACKBONE.TYPE = "vit_base_patch16_224" 19 | cfg.MODEL.BACKBONE.STRIDE = 16 20 | cfg.MODEL.BACKBONE.MID_PE = False 21 | cfg.MODEL.BACKBONE.SEP_SEG = False 22 | cfg.MODEL.BACKBONE.CAT_MODE = 'direct' 23 | cfg.MODEL.BACKBONE.MERGE_LAYER = 0 24 | cfg.MODEL.BACKBONE.ADD_CLS_TOKEN = False 25 | cfg.MODEL.BACKBONE.CLS_TOKEN_USE_MODE = 'ignore' 26 | 27 | cfg.MODEL.BACKBONE.CE_LOC = [] 28 | cfg.MODEL.BACKBONE.CE_KEEP_RATIO = [] 29 | cfg.MODEL.BACKBONE.CE_TEMPLATE_RANGE = 'ALL' # choose between ALL, CTR_POINT, CTR_REC, GT_BOX 30 | 31 | # MODEL.HEAD 32 | cfg.MODEL.HEAD = edict() 33 | cfg.MODEL.HEAD.TYPE = "CENTER" 34 | cfg.MODEL.HEAD.NUM_CHANNELS = 256 35 | 36 | # TRAIN 37 | cfg.TRAIN = edict() 38 | cfg.TRAIN.PROMPT = edict() 39 | cfg.TRAIN.PROMPT.TYPE = 'deep' 40 | cfg.TRAIN.LR = 0.0001 41 | cfg.TRAIN.WEIGHT_DECAY = 0.0001 42 | cfg.TRAIN.EPOCH = 500 43 | cfg.TRAIN.LR_DROP_EPOCH = 400 44 | cfg.TRAIN.BATCH_SIZE = 16 45 | cfg.TRAIN.NUM_WORKER = 8 46 | cfg.TRAIN.OPTIMIZER = "ADAMW" 47 | cfg.TRAIN.BACKBONE_MULTIPLIER = 0.1 48 | cfg.TRAIN.GIOU_WEIGHT = 2.0 49 | cfg.TRAIN.L1_WEIGHT = 5.0 50 | cfg.TRAIN.FREEZE_LAYERS = [0, ] 51 | cfg.TRAIN.PRINT_INTERVAL = 50 52 | cfg.TRAIN.VAL_EPOCH_INTERVAL = 20 53 | cfg.TRAIN.GRAD_CLIP_NORM = 0.1 54 | cfg.TRAIN.AMP = False 55 | ## TRAIN save cfgs 56 | cfg.TRAIN.FIX_BN = True 57 | cfg.TRAIN.SAVE_EPOCH_INTERVAL = 1 # 1 means save model each epoch 58 | cfg.TRAIN.SAVE_LAST_N_EPOCH = 1 # besides, last n epoch model will be saved 59 | 60 | cfg.TRAIN.CE_START_EPOCH = 20 # candidate elimination start epoch 61 | cfg.TRAIN.CE_WARM_EPOCH = 80 # candidate elimination warm up epoch 62 | cfg.TRAIN.DROP_PATH_RATE = 0.1 # drop path rate for ViT backbone 63 | 64 | # TRAIN.SCHEDULER 65 | cfg.TRAIN.SCHEDULER = edict() 66 | cfg.TRAIN.SCHEDULER.TYPE = "step" 67 | cfg.TRAIN.SCHEDULER.DECAY_RATE = 0.1 68 | 69 | # DATA 70 | cfg.DATA = edict() 71 | cfg.DATA.SAMPLER_MODE = "causal" # sampling methods 72 | cfg.DATA.MEAN = [0.485, 0.456, 0.406] 73 | cfg.DATA.STD = [0.229, 0.224, 0.225] 74 | cfg.DATA.MAX_SAMPLE_INTERVAL = 200 75 | # DATA.TRAIN 76 | cfg.DATA.TRAIN = edict() 77 | cfg.DATA.TRAIN.DATASETS_NAME = ["LASOT", "GOT10K_vottrain"] 78 | cfg.DATA.TRAIN.DATASETS_RATIO = [1, 1] 79 | cfg.DATA.TRAIN.SAMPLE_PER_EPOCH = 60000 80 | # DATA.VAL 81 | cfg.DATA.VAL = edict() 82 | cfg.DATA.VAL.DATASETS_NAME = [] 83 | cfg.DATA.VAL.DATASETS_RATIO = [1] 84 | cfg.DATA.VAL.SAMPLE_PER_EPOCH = 10000 85 | # DATA.SEARCH 86 | cfg.DATA.SEARCH = edict() 87 | cfg.DATA.SEARCH.SIZE = 320 88 | cfg.DATA.SEARCH.FACTOR = 5.0 89 | cfg.DATA.SEARCH.CENTER_JITTER = 4.5 90 | cfg.DATA.SEARCH.SCALE_JITTER = 0.5 91 | cfg.DATA.SEARCH.NUMBER = 1 92 | # DATA.TEMPLATE 93 | cfg.DATA.TEMPLATE = edict() 94 | cfg.DATA.TEMPLATE.NUMBER = 1 95 | cfg.DATA.TEMPLATE.SIZE = 128 96 | cfg.DATA.TEMPLATE.FACTOR = 2.0 97 | cfg.DATA.TEMPLATE.CENTER_JITTER = 0 98 | cfg.DATA.TEMPLATE.SCALE_JITTER = 0 99 | 100 | # TEST 101 | cfg.TEST = edict() 102 | cfg.TEST.TEMPLATE_FACTOR = 2.0 103 | cfg.TEST.TEMPLATE_SIZE = 128 104 | cfg.TEST.SEARCH_FACTOR = 5.0 105 | cfg.TEST.SEARCH_SIZE = 320 106 | cfg.TEST.EPOCH = 500 107 | 108 | 109 | def _edict2dict(dest_dict, src_edict): 110 | if isinstance(dest_dict, dict) and isinstance(src_edict, dict): 111 | for k, v in src_edict.items(): 112 | if not isinstance(v, edict): 113 | dest_dict[k] = v 114 | else: 115 | dest_dict[k] = {} 116 | _edict2dict(dest_dict[k], v) 117 | else: 118 | return 119 | 120 | 121 | def gen_config(config_file): 122 | cfg_dict = {} 123 | _edict2dict(cfg_dict, cfg) 124 | with open(config_file, 'w') as f: 125 | yaml.dump(cfg_dict, f, default_flow_style=False) 126 | 127 | 128 | def _update_config(base_cfg, exp_cfg): 129 | if isinstance(base_cfg, dict) and isinstance(exp_cfg, edict): 130 | for k, v in exp_cfg.items(): 131 | if k in base_cfg: 132 | if not isinstance(v, dict): 133 | base_cfg[k] = v 134 | else: 135 | _update_config(base_cfg[k], v) 136 | else: 137 | raise ValueError("{} not exist in config.py".format(k)) 138 | else: 139 | return 140 | 141 | 142 | def update_config_from_file(filename, base_cfg=None): 143 | exp_config = None 144 | with open(filename) as f: 145 | exp_config = edict(yaml.safe_load(f)) 146 | if base_cfg is not None: 147 | _update_config(base_cfg, exp_config) 148 | else: 149 | _update_config(cfg, exp_config) 150 | -------------------------------------------------------------------------------- /lib/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .untrack.ostrack_prompt import build_untrack 2 | -------------------------------------------------------------------------------- /lib/models/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/layers/MoE_prompt.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | 5 | # class Expert(nn.Module): 6 | # def __init__(self, in_features, out_features): 7 | # super(Expert, self).__init__() 8 | # self.layer = nn.Linear(in_features, out_features) 9 | # 10 | # def forward(self, x): 11 | # return F.relu(self.layer(x)) 12 | # 13 | # 14 | # class Router(nn.Module): 15 | # def __init__(self, in_features, num_experts): 16 | # super(Router, self).__init__() 17 | # self.network = nn.Sequential( 18 | # nn.Linear(in_features, 128), 19 | # nn.ReLU(), 20 | # nn.Linear(128, num_experts) 21 | # ) 22 | # 23 | # def forward(self, x): 24 | # return F.softmax(self.network(x), dim=1) 25 | # 26 | # 27 | # # class MoE(nn.Module): 28 | # # def __init(self, in_features, out_features, num_experts): 29 | # # super(MoE, self).__init__() 30 | # # self.gate = nn.Linear(in_features, num_experts) 31 | # # self.experts = nn.ModuleList([Expert(in_features, out_features) for i in range(num_experts)]) 32 | # # 33 | # # def foward(self, x): 34 | # # gate_output = F.softmax(self.gate(x), dim=1) 35 | # # expert_outputs = [expert(x) for expert in self.experts] 36 | # # final_output = 0 37 | # # for i, expert_output in enumerate(expert_outputs): 38 | # # final_output += gate_output[:, i].unsqueeze(1) * expert_output 39 | # # return final_output 40 | # 41 | # 42 | # class MoE(nn.Module): 43 | # def __init(self, in_features, out_features, num_experts): 44 | # super(MoE, self).__init__() 45 | # self.gate = Router(in_features, num_experts) 46 | # self.experts = nn.ModuleList([Expert(in_features, out_features) for i in range(num_experts)]) 47 | # 48 | # def foward(self, x): 49 | # gate_output = self.gate(x) 50 | # scores, indices = torch.sort(gate_output, dim=1, descending=True) 51 | # final_output = 0 52 | # for i in range(6): 53 | # expert_output = self.experts[indices[:, i]](x) 54 | # final_output += scores[:, i].unsqueeze(1) * expert_output 55 | # return final_output 56 | class Expert(nn.Module): 57 | def __init__(self): 58 | super(Expert, self).__init__() 59 | self.layer = nn.Sequential( 60 | nn.Linear(768,1024), 61 | nn.ReLU(), 62 | nn.Linear(1024,1024), 63 | nn.ReLU(), 64 | nn.Linear(1024,768), 65 | ) 66 | 67 | def forward(self, x): 68 | p_task = F.softmax(self.layer(x), dim=-1) 69 | return self.layer(x), p_task 70 | 71 | 72 | class Router(nn.Module): 73 | def __init__(self, num_experts): 74 | super(Router, self).__init__() 75 | self.pool = nn.AdaptiveAvgPool1d(1) 76 | self.network = nn.Sequential( 77 | nn.Linear(768, 128), 78 | nn.ReLU(), 79 | nn.Linear(128, num_experts) 80 | ) 81 | 82 | def forward(self, x): 83 | x = x.permute(0,2,1) 84 | x = self.pool(x) 85 | #print('x.pool',x.shape) 86 | x = x.squeeze(-1) 87 | #print('squeeze',x.shape) 88 | return F.softmax(self.network(x), dim=1) 89 | 90 | 91 | class MoE(nn.Module): 92 | def __init__(self, num_experts=2): 93 | super(MoE, self).__init__() 94 | self.gate = Router(num_experts) 95 | self.experts = nn.ModuleList([Expert() for _ in range(num_experts)]) 96 | 97 | def forward(self, x): 98 | #print('inputshape',x.shape) (32,64,768) 99 | gate_output = self.gate(x) #(32,64,10) 100 | #print('gateoutput',gate_output.shape) (32,10) 101 | topk_values, topk_indices = torch.topk(gate_output, 2, dim=1) 102 | #print('topk_indices',topk_indices.shape)(32,6) 103 | #print('ttttttt', topk_indices.t().shape)# (6,32) 104 | #print('topk_value',topk_values.shape)(32,6) 105 | #x_reshape = x.reshape(-1, x.shape[-1]) 106 | #print('x_reshape', x_reshape.shape)(2048,768) 107 | #topk_indices - topk_indices.permute(1,0) 108 | expert_output = torch.stack([expert(x)[-1] for expert in self.experts]) 109 | #print('expert_output', expert_output.shape)#(10,32,64,768) 110 | #print('unsqueeze', topk_indices.unsqueeze(2).expand(-1, -1, expert_output.shape[-1]).shape) #(32,6,768) 111 | topk_indices = topk_indices.t().unsqueeze(2) 112 | topk_indices =topk_indices.unsqueeze(3) 113 | #print('unsqueeze2',topk_indices.shape) 114 | expert_output_topk = expert_output.gather(0, topk_indices.expand(-1, -1, expert_output.shape[-2],expert_output.shape[-1])) 115 | #print('expertoutputtopk',expert_output_topk.shape)#6,32,64,768 116 | # expert_outputs = [self.experts[idx](x) for idx in topk_indices] 117 | final_output = 0 118 | for i, expert_output in enumerate(expert_output_topk): 119 | weight = topk_values[:, i].unsqueeze(1).unsqueeze(1).unsqueeze(0) 120 | #print(weight.shape) 121 | final_output += weight*expert_output 122 | #print(final_output.shape) 123 | #print('use MoE') 124 | final_output = final_output.squeeze(0) 125 | return final_output 126 | 127 | def mutual_info_loss(self, p_z, p_t_given_z): 128 | H_z = -torch.sum(p_z * torch.log(p_z), dim=1) 129 | H_t_given_z = -torch.sum(p_t_given_z * torch.log(p_t_given_z), dim=1) 130 | L_mi = H_z - torch.sum(p_z * H_t_given_z, dim=1) 131 | 132 | return L_mi 133 | 134 | 135 | if __name__ == "__main__": 136 | model = MoE().cuda() 137 | inp = torch.randn(32, 64, 768).cuda() 138 | out = model(inp) 139 | -------------------------------------------------------------------------------- /lib/models/layers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/layers/__init__.py -------------------------------------------------------------------------------- /lib/models/layers/__pycache__/MoE_prompt.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/layers/__pycache__/MoE_prompt.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/layers/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/layers/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/layers/__pycache__/attn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/layers/__pycache__/attn.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/layers/__pycache__/attn_blocks.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/layers/__pycache__/attn_blocks.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/layers/__pycache__/frozen_bn.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/layers/__pycache__/frozen_bn.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/layers/__pycache__/head.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/layers/__pycache__/head.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/layers/__pycache__/patch_embed.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/layers/__pycache__/patch_embed.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/layers/__pycache__/rpe.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/layers/__pycache__/rpe.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/layers/attn.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | import torch.nn.functional as F 4 | from timm.models.layers import trunc_normal_ 5 | 6 | from lib.models.layers.rpe import generate_2d_concatenated_self_attention_relative_positional_encoding_index 7 | 8 | 9 | class Attention(nn.Module): 10 | def __init__(self, dim, num_heads=8, qkv_bias=False, attn_drop=0., proj_drop=0., 11 | rpe=False, z_size=7, x_size=14): 12 | super().__init__() 13 | self.num_heads = num_heads 14 | head_dim = dim // num_heads 15 | self.scale = head_dim ** -0.5 16 | 17 | self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias) 18 | self.attn_drop = nn.Dropout(attn_drop) 19 | self.proj = nn.Linear(dim, dim) 20 | self.proj_drop = nn.Dropout(proj_drop) 21 | 22 | self.rpe =rpe 23 | if self.rpe: 24 | relative_position_index = \ 25 | generate_2d_concatenated_self_attention_relative_positional_encoding_index([z_size, z_size], 26 | [x_size, x_size]) 27 | self.register_buffer("relative_position_index", relative_position_index) 28 | # define a parameter table of relative position bias 29 | self.relative_position_bias_table = nn.Parameter(torch.empty((num_heads, 30 | relative_position_index.max() + 1))) 31 | trunc_normal_(self.relative_position_bias_table, std=0.02) 32 | 33 | def forward(self, x, mask=None, return_attention=False): 34 | # x: B, N, C 35 | # mask: [B, N, ] torch.bool 36 | B, N, C = x.shape 37 | qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4) 38 | q, k, v = qkv.unbind(0) # make torchscript happy (cannot use tensor as tuple) 39 | 40 | attn = (q @ k.transpose(-2, -1)) * self.scale 41 | 42 | if self.rpe: 43 | relative_position_bias = self.relative_position_bias_table[:, self.relative_position_index].unsqueeze(0) 44 | attn += relative_position_bias 45 | 46 | if mask is not None: 47 | attn = attn.masked_fill(mask.unsqueeze(1).unsqueeze(2), float('-inf'),) 48 | 49 | attn = attn.softmax(dim=-1) 50 | attn = self.attn_drop(attn) 51 | 52 | x = (attn @ v).transpose(1, 2).reshape(B, N, C) 53 | x = self.proj(x) 54 | x = self.proj_drop(x) 55 | 56 | if return_attention: 57 | return x, attn 58 | else: 59 | return x 60 | 61 | 62 | class Attention_talking_head(nn.Module): 63 | # taken from https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/vision_transformer.py 64 | # with slight modifications to add Talking Heads Attention (https://arxiv.org/pdf/2003.02436v1.pdf) 65 | def __init__(self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0., proj_drop=0., 66 | rpe=True, z_size=7, x_size=14): 67 | super().__init__() 68 | 69 | self.num_heads = num_heads 70 | 71 | head_dim = dim // num_heads 72 | 73 | self.scale = qk_scale or head_dim ** -0.5 74 | 75 | self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias) 76 | self.attn_drop = nn.Dropout(attn_drop) 77 | 78 | self.proj = nn.Linear(dim, dim) 79 | 80 | self.proj_l = nn.Linear(num_heads, num_heads) 81 | self.proj_w = nn.Linear(num_heads, num_heads) 82 | 83 | self.proj_drop = nn.Dropout(proj_drop) 84 | 85 | self.rpe = rpe 86 | if self.rpe: 87 | relative_position_index = \ 88 | generate_2d_concatenated_self_attention_relative_positional_encoding_index([z_size, z_size], 89 | [x_size, x_size]) 90 | self.register_buffer("relative_position_index", relative_position_index) 91 | # define a parameter table of relative position bias 92 | self.relative_position_bias_table = nn.Parameter(torch.empty((num_heads, 93 | relative_position_index.max() + 1))) 94 | trunc_normal_(self.relative_position_bias_table, std=0.02) 95 | 96 | def forward(self, x, mask=None): 97 | B, N, C = x.shape 98 | qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4) 99 | q, k, v = qkv[0] * self.scale, qkv[1], qkv[2] 100 | 101 | attn = (q @ k.transpose(-2, -1)) 102 | 103 | if self.rpe: 104 | relative_position_bias = self.relative_position_bias_table[:, self.relative_position_index].unsqueeze(0) 105 | attn += relative_position_bias 106 | 107 | if mask is not None: 108 | attn = attn.masked_fill(mask.unsqueeze(1).unsqueeze(2), 109 | float('-inf'),) 110 | 111 | attn = self.proj_l(attn.permute(0, 2, 3, 1)).permute(0, 3, 1, 2) 112 | 113 | attn = attn.softmax(dim=-1) 114 | 115 | attn = self.proj_w(attn.permute(0, 2, 3, 1)).permute(0, 3, 1, 2) 116 | attn = self.attn_drop(attn) 117 | 118 | x = (attn @ v).transpose(1, 2).reshape(B, N, C) 119 | x = self.proj(x) 120 | x = self.proj_drop(x) 121 | return x -------------------------------------------------------------------------------- /lib/models/layers/frozen_bn.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | class FrozenBatchNorm2d(torch.nn.Module): 5 | """ 6 | BatchNorm2d where the batch statistics and the affine parameters are fixed. 7 | 8 | Copy-paste from torchvision.misc.ops with added eps before rqsrt, 9 | without which any other models than torchvision.models.resnet[18,34,50,101] 10 | produce nans. 11 | """ 12 | 13 | def __init__(self, n): 14 | super(FrozenBatchNorm2d, self).__init__() 15 | self.register_buffer("weight", torch.ones(n)) 16 | self.register_buffer("bias", torch.zeros(n)) 17 | self.register_buffer("running_mean", torch.zeros(n)) 18 | self.register_buffer("running_var", torch.ones(n)) 19 | 20 | def _load_from_state_dict(self, state_dict, prefix, local_metadata, strict, 21 | missing_keys, unexpected_keys, error_msgs): 22 | num_batches_tracked_key = prefix + 'num_batches_tracked' 23 | if num_batches_tracked_key in state_dict: 24 | del state_dict[num_batches_tracked_key] 25 | 26 | super(FrozenBatchNorm2d, self)._load_from_state_dict( 27 | state_dict, prefix, local_metadata, strict, 28 | missing_keys, unexpected_keys, error_msgs) 29 | 30 | def forward(self, x): 31 | # move reshapes to the beginning 32 | # to make it fuser-friendly 33 | w = self.weight.reshape(1, -1, 1, 1) 34 | b = self.bias.reshape(1, -1, 1, 1) 35 | rv = self.running_var.reshape(1, -1, 1, 1) 36 | rm = self.running_mean.reshape(1, -1, 1, 1) 37 | eps = 1e-5 38 | scale = w * (rv + eps).rsqrt() # rsqrt(x): 1/sqrt(x), r: reciprocal 39 | bias = b - rm * scale 40 | return x * scale + bias 41 | -------------------------------------------------------------------------------- /lib/models/layers/patch_embed.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch.nn.functional as F 3 | from timm.models.layers import to_2tuple 4 | import torch 5 | 6 | class PatchEmbed(nn.Module): 7 | """ 2D Image to Patch Embedding 8 | """ 9 | 10 | def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768, norm_layer=None, flatten=True): 11 | super().__init__() 12 | img_size = to_2tuple(img_size) #(224,224) 13 | patch_size = to_2tuple(patch_size) 14 | self.img_size = img_size 15 | self.patch_size = patch_size 16 | self.grid_size = (img_size[0] // patch_size[0], img_size[1] // patch_size[1]) 17 | self.num_patches = self.grid_size[0] * self.grid_size[1] 18 | self.flatten = flatten 19 | 20 | self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size) 21 | self.norm = norm_layer(embed_dim) if norm_layer else nn.Identity() 22 | 23 | def forward(self, x): 24 | x = self.proj(x) #([32, 768, 16/8, 16/8])/ 25 | if self.flatten: 26 | x = x.flatten(2).transpose(1, 2) # BCHW -> BNC 27 | x = self.norm(x) 28 | return x 29 | -------------------------------------------------------------------------------- /lib/models/layers/rpe.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | from timm.models.layers import trunc_normal_ 4 | 5 | 6 | def generate_2d_relative_positional_encoding_index(z_shape, x_shape): 7 | ''' 8 | z_shape: (z_h, z_w) 9 | x_shape: (x_h, x_w) 10 | ''' 11 | z_2d_index_h, z_2d_index_w = torch.meshgrid(torch.arange(z_shape[0]), torch.arange(z_shape[1])) 12 | x_2d_index_h, x_2d_index_w = torch.meshgrid(torch.arange(x_shape[0]), torch.arange(x_shape[1])) 13 | 14 | z_2d_index_h = z_2d_index_h.flatten(0) 15 | z_2d_index_w = z_2d_index_w.flatten(0) 16 | x_2d_index_h = x_2d_index_h.flatten(0) 17 | x_2d_index_w = x_2d_index_w.flatten(0) 18 | 19 | diff_h = z_2d_index_h[:, None] - x_2d_index_h[None, :] 20 | diff_w = z_2d_index_w[:, None] - x_2d_index_w[None, :] 21 | 22 | diff = torch.stack((diff_h, diff_w), dim=-1) 23 | _, indices = torch.unique(diff.view(-1, 2), return_inverse=True, dim=0) 24 | return indices.view(z_shape[0] * z_shape[1], x_shape[0] * x_shape[1]) 25 | 26 | 27 | def generate_2d_concatenated_self_attention_relative_positional_encoding_index(z_shape, x_shape): 28 | ''' 29 | z_shape: (z_h, z_w) 30 | x_shape: (x_h, x_w) 31 | ''' 32 | z_2d_index_h, z_2d_index_w = torch.meshgrid(torch.arange(z_shape[0]), torch.arange(z_shape[1])) 33 | x_2d_index_h, x_2d_index_w = torch.meshgrid(torch.arange(x_shape[0]), torch.arange(x_shape[1])) 34 | 35 | z_2d_index_h = z_2d_index_h.flatten(0) 36 | z_2d_index_w = z_2d_index_w.flatten(0) 37 | x_2d_index_h = x_2d_index_h.flatten(0) 38 | x_2d_index_w = x_2d_index_w.flatten(0) 39 | 40 | concatenated_2d_index_h = torch.cat((z_2d_index_h, x_2d_index_h)) 41 | concatenated_2d_index_w = torch.cat((z_2d_index_w, x_2d_index_w)) 42 | 43 | diff_h = concatenated_2d_index_h[:, None] - concatenated_2d_index_h[None, :] 44 | diff_w = concatenated_2d_index_w[:, None] - concatenated_2d_index_w[None, :] 45 | 46 | z_len = z_shape[0] * z_shape[1] 47 | x_len = x_shape[0] * x_shape[1] 48 | a = torch.empty((z_len + x_len), dtype=torch.int64) 49 | a[:z_len] = 0 50 | a[z_len:] = 1 51 | b=a[:, None].repeat(1, z_len + x_len) 52 | c=a[None, :].repeat(z_len + x_len, 1) 53 | 54 | diff = torch.stack((diff_h, diff_w, b, c), dim=-1) 55 | _, indices = torch.unique(diff.view((z_len + x_len) * (z_len + x_len), 4), return_inverse=True, dim=0) 56 | return indices.view((z_len + x_len), (z_len + x_len)) 57 | 58 | 59 | def generate_2d_concatenated_cross_attention_relative_positional_encoding_index(z_shape, x_shape): 60 | ''' 61 | z_shape: (z_h, z_w) 62 | x_shape: (x_h, x_w) 63 | ''' 64 | z_2d_index_h, z_2d_index_w = torch.meshgrid(torch.arange(z_shape[0]), torch.arange(z_shape[1])) 65 | x_2d_index_h, x_2d_index_w = torch.meshgrid(torch.arange(x_shape[0]), torch.arange(x_shape[1])) 66 | 67 | z_2d_index_h = z_2d_index_h.flatten(0) 68 | z_2d_index_w = z_2d_index_w.flatten(0) 69 | x_2d_index_h = x_2d_index_h.flatten(0) 70 | x_2d_index_w = x_2d_index_w.flatten(0) 71 | 72 | concatenated_2d_index_h = torch.cat((z_2d_index_h, x_2d_index_h)) 73 | concatenated_2d_index_w = torch.cat((z_2d_index_w, x_2d_index_w)) 74 | 75 | diff_h = x_2d_index_h[:, None] - concatenated_2d_index_h[None, :] 76 | diff_w = x_2d_index_w[:, None] - concatenated_2d_index_w[None, :] 77 | 78 | z_len = z_shape[0] * z_shape[1] 79 | x_len = x_shape[0] * x_shape[1] 80 | 81 | a = torch.empty(z_len + x_len, dtype=torch.int64) 82 | a[: z_len] = 0 83 | a[z_len:] = 1 84 | c = a[None, :].repeat(x_len, 1) 85 | 86 | diff = torch.stack((diff_h, diff_w, c), dim=-1) 87 | _, indices = torch.unique(diff.view(x_len * (z_len + x_len), 3), return_inverse=True, dim=0) 88 | return indices.view(x_len, (z_len + x_len)) 89 | 90 | 91 | class RelativePosition2DEncoder(nn.Module): 92 | def __init__(self, num_heads, embed_size): 93 | super(RelativePosition2DEncoder, self).__init__() 94 | self.relative_position_bias_table = nn.Parameter(torch.empty((num_heads, embed_size))) 95 | trunc_normal_(self.relative_position_bias_table, std=0.02) 96 | 97 | def forward(self, attn_rpe_index): 98 | ''' 99 | Args: 100 | attn_rpe_index (torch.Tensor): (*), any shape containing indices, max(attn_rpe_index) < embed_size 101 | Returns: 102 | torch.Tensor: (1, num_heads, *) 103 | ''' 104 | return self.relative_position_bias_table[:, attn_rpe_index].unsqueeze(0) 105 | -------------------------------------------------------------------------------- /lib/models/untrack/__init__.py: -------------------------------------------------------------------------------- 1 | from .ostrack import build_ostrack 2 | from .ostrack_prompt import build_untrack -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/attention.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/attention.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/base_backbone.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/base_backbone.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/ostrack.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/ostrack.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/ostrack_prompt.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/ostrack_prompt.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/vit.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/vit.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/vit_ce.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/vit_ce.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/vit_ce_prompt.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/vit_ce_prompt.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/__pycache__/vit_prompt.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/models/untrack/__pycache__/vit_prompt.cpython-37.pyc -------------------------------------------------------------------------------- /lib/models/untrack/test_gradient.py: -------------------------------------------------------------------------------- 1 | import math 2 | import logging 3 | import pdb 4 | from functools import partial 5 | from collections import OrderedDict 6 | from copy import deepcopy 7 | 8 | import matplotlib.pyplot as plt 9 | import torch 10 | import torch.nn as nn 11 | import torch.nn.functional as F 12 | 13 | from timm.models.layers import to_2tuple 14 | 15 | import functools 16 | from torch import nn, Tensor 17 | from info_nce import InfoNCE 18 | 19 | def gradient(depth_tmp): 20 | step = 7 21 | 22 | B, C, H, W = depth_tmp.size() 23 | pad = (step - 1) // 2 24 | depth_tmp = F.pad(depth_tmp, [pad, pad, pad, pad], mode='constant', value=0) 25 | patches = depth_tmp.unfold(dimension=2, size=step, step=1) 26 | patches = patches.unfold(dimension=3, size=step, step=1) 27 | max_depth, _ = patches.reshape(B, C, H, W, -1).max(dim=-1) 28 | 29 | # 求解max_depth四个方向梯度, 随后concat depth, 以缓解深度跳变对深度预测模块的影响 30 | step = float(step) 31 | shift_list = [[step / H, 0.0 / W], [-step / H, 0.0 / W], [0.0 / H, step / W], [0.0 / H, -step / W]] 32 | output_list = [] 33 | for shift in shift_list: 34 | transform_matrix = torch.tensor([[1, 0, shift[0]], [0, 1, shift[1]]]).unsqueeze(0).repeat(B, 1, 1).cuda() 35 | grid = F.affine_grid(transform_matrix, max_depth.shape).float() 36 | output = F.grid_sample(max_depth, grid, mode='nearest') # 平移后图像 37 | output = max_depth - output 38 | output_mask = ((output == max_depth) == False) 39 | output = output * output_mask 40 | output_list.append(output) 41 | grad = torch.cat(output_list, dim=1) 42 | max_grad = torch.abs(grad).max(dim=1)[0].unsqueeze(1) 43 | 44 | return grad, max_grad 45 | 46 | if __name__ == "__main__": 47 | path = '/home/zwu/Tracking/data/depthtrack/train/ball02_indoor/color/00001464.jpg' 48 | im = plt.imread(path) 49 | rgb = torch.from_numpy(im).unsqueeze(0).permute(0,3,1,2).cuda() 50 | rgb = F.interpolate(rgb, (256,256)).float() 51 | grad = gradient(rgb) 52 | max_grad = torch.abs(grad).max(dim=1)[0].unsqueeze(1) 53 | a=1 -------------------------------------------------------------------------------- /lib/models/untrack/utils.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | import torch 4 | import torch.nn.functional as F 5 | 6 | 7 | def combine_tokens(template_tokens, search_tokens, mode='direct', return_res=False): 8 | # [B, HW, C] 9 | len_t = template_tokens.shape[1] 10 | len_s = search_tokens.shape[1] 11 | 12 | if mode == 'direct': 13 | merged_feature = torch.cat((template_tokens, search_tokens), dim=1) 14 | elif mode == 'template_central': 15 | central_pivot = len_s // 2 16 | first_half = search_tokens[:, :central_pivot, :] 17 | second_half = search_tokens[:, central_pivot:, :] 18 | merged_feature = torch.cat((first_half, template_tokens, second_half), dim=1) 19 | elif mode == 'partition': 20 | feat_size_s = int(math.sqrt(len_s)) 21 | feat_size_t = int(math.sqrt(len_t)) 22 | window_size = math.ceil(feat_size_t / 2.) 23 | # pad feature maps to multiples of window size 24 | B, _, C = template_tokens.shape 25 | H = W = feat_size_t 26 | template_tokens = template_tokens.view(B, H, W, C) 27 | pad_l = pad_b = pad_r = 0 28 | # pad_r = (window_size - W % window_size) % window_size 29 | pad_t = (window_size - H % window_size) % window_size 30 | template_tokens = F.pad(template_tokens, (0, 0, pad_l, pad_r, pad_t, pad_b)) 31 | _, Hp, Wp, _ = template_tokens.shape 32 | template_tokens = template_tokens.view(B, Hp // window_size, window_size, W, C) 33 | template_tokens = torch.cat([template_tokens[:, 0, ...], template_tokens[:, 1, ...]], dim=2) 34 | _, Hc, Wc, _ = template_tokens.shape 35 | template_tokens = template_tokens.view(B, -1, C) 36 | merged_feature = torch.cat([template_tokens, search_tokens], dim=1) 37 | 38 | # calculate new h and w, which may be useful for SwinT or others 39 | merged_h, merged_w = feat_size_s + Hc, feat_size_s 40 | if return_res: 41 | return merged_feature, merged_h, merged_w 42 | 43 | else: 44 | raise NotImplementedError 45 | 46 | return merged_feature 47 | 48 | 49 | def recover_tokens(merged_tokens, len_template_token, len_search_token, mode='direct'): 50 | if mode == 'direct': 51 | recovered_tokens = merged_tokens 52 | elif mode == 'template_central': 53 | central_pivot = len_search_token // 2 54 | len_remain = len_search_token - central_pivot 55 | len_half_and_t = central_pivot + len_template_token 56 | 57 | first_half = merged_tokens[:, :central_pivot, :] 58 | second_half = merged_tokens[:, -len_remain:, :] 59 | template_tokens = merged_tokens[:, central_pivot:len_half_and_t, :] 60 | 61 | recovered_tokens = torch.cat((template_tokens, first_half, second_half), dim=1) 62 | elif mode == 'partition': 63 | recovered_tokens = merged_tokens 64 | else: 65 | raise NotImplementedError 66 | 67 | return recovered_tokens 68 | 69 | 70 | def window_partition(x, window_size: int): 71 | """ 72 | Args: 73 | x: (B, H, W, C) 74 | window_size (int): window size 75 | 76 | Returns: 77 | windows: (num_windows*B, window_size, window_size, C) 78 | """ 79 | B, H, W, C = x.shape 80 | x = x.view(B, H // window_size, window_size, W // window_size, window_size, C) 81 | windows = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(-1, window_size, window_size, C) 82 | return windows 83 | 84 | 85 | def window_reverse(windows, window_size: int, H: int, W: int): 86 | """ 87 | Args: 88 | windows: (num_windows*B, window_size, window_size, C) 89 | window_size (int): Window size 90 | H (int): Height of image 91 | W (int): Width of image 92 | 93 | Returns: 94 | x: (B, H, W, C) 95 | """ 96 | B = int(windows.shape[0] / (H * W / window_size / window_size)) 97 | x = windows.view(B, H // window_size, W // window_size, window_size, window_size, -1) 98 | x = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(B, H, W, -1) 99 | return x 100 | 101 | 102 | ''' 103 | add token transfer to feature 104 | ''' 105 | def token2feature(tokens): 106 | B,L,D=tokens.shape 107 | H=W=int(L**0.5) 108 | x = tokens.permute(0, 2, 1).view(B, D, W, H).contiguous() 109 | return x 110 | 111 | 112 | ''' 113 | feature2token 114 | ''' 115 | def feature2token(x): 116 | B,C,W,H = x.shape 117 | L = W*H 118 | tokens = x.view(B, C, L).permute(0, 2, 1).contiguous() 119 | return tokens -------------------------------------------------------------------------------- /lib/test/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | from .data import Sequence 2 | from .tracker import Tracker, trackerlist 3 | from .datasets import get_dataset 4 | from .environment import create_default_local_file_test -------------------------------------------------------------------------------- /lib/test/evaluation/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/evaluation/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/evaluation/__pycache__/data.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/evaluation/__pycache__/data.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/evaluation/__pycache__/datasets.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/evaluation/__pycache__/datasets.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/evaluation/__pycache__/environment.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/evaluation/__pycache__/environment.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/evaluation/__pycache__/local.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/evaluation/__pycache__/local.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/evaluation/__pycache__/running.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/evaluation/__pycache__/running.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/evaluation/__pycache__/tracker.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/evaluation/__pycache__/tracker.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/evaluation/__pycache__/votdataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/evaluation/__pycache__/votdataset.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/evaluation/datasets.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | import importlib 3 | from lib.test.evaluation.data import SequenceList 4 | 5 | DatasetInfo = namedtuple('DatasetInfo', ['module', 'class_name', 'kwargs']) 6 | 7 | pt = "lib.test.evaluation.%sdataset" # Useful abbreviations to reduce the clutter 8 | 9 | dataset_dict = dict( 10 | otb=DatasetInfo(module=pt % "otb", class_name="OTBDataset", kwargs=dict()), 11 | nfs=DatasetInfo(module=pt % "nfs", class_name="NFSDataset", kwargs=dict()), 12 | uav=DatasetInfo(module=pt % "uav", class_name="UAVDataset", kwargs=dict()), 13 | tc128=DatasetInfo(module=pt % "tc128", class_name="TC128Dataset", kwargs=dict()), 14 | tc128ce=DatasetInfo(module=pt % "tc128ce", class_name="TC128CEDataset", kwargs=dict()), 15 | trackingnet=DatasetInfo(module=pt % "trackingnet", class_name="TrackingNetDataset", kwargs=dict()), 16 | got10k_test=DatasetInfo(module=pt % "got10k", class_name="GOT10KDataset", kwargs=dict(split='test')), 17 | got10k_val=DatasetInfo(module=pt % "got10k", class_name="GOT10KDataset", kwargs=dict(split='val')), 18 | got10k_ltrval=DatasetInfo(module=pt % "got10k", class_name="GOT10KDataset", kwargs=dict(split='ltrval')), 19 | lasot=DatasetInfo(module=pt % "lasot", class_name="LaSOTDataset", kwargs=dict()), 20 | lasot_lmdb=DatasetInfo(module=pt % "lasot_lmdb", class_name="LaSOTlmdbDataset", kwargs=dict()), 21 | 22 | vot18=DatasetInfo(module=pt % "vot", class_name="VOTDataset", kwargs=dict()), 23 | vot22=DatasetInfo(module=pt % "vot", class_name="VOTDataset", kwargs=dict(year=22)), 24 | itb=DatasetInfo(module=pt % "itb", class_name="ITBDataset", kwargs=dict()), 25 | tnl2k=DatasetInfo(module=pt % "tnl2k", class_name="TNL2kDataset", kwargs=dict()), 26 | lasot_extension_subset=DatasetInfo(module=pt % "lasotextensionsubset", class_name="LaSOTExtensionSubsetDataset", 27 | kwargs=dict()), 28 | vtuav_st=DatasetInfo(module=pt % "vtuav", class_name="VTUAVDataset", kwargs=dict(subset='st')), 29 | vtuav_lt=DatasetInfo(module=pt % "vtuav", class_name="VTUAVDataset", kwargs=dict(subset='lt')), 30 | lasher=DatasetInfo(module=pt % "lasher", class_name="LasHeRDataset", kwargs=dict()), 31 | depthtrack=DatasetInfo(module=pt % "depthtrack", class_name="DepthTrackDataset", kwargs=dict()), 32 | 33 | ) 34 | 35 | 36 | def load_dataset(name: str): 37 | """ Import and load a single dataset.""" 38 | name = name.lower() 39 | dset_info = dataset_dict.get(name) 40 | if dset_info is None: 41 | raise ValueError('Unknown dataset \'%s\'' % name) 42 | 43 | m = importlib.import_module(dset_info.module) 44 | dataset = getattr(m, dset_info.class_name)(**dset_info.kwargs) # Call the constructor 45 | return dataset.get_sequence_list() 46 | 47 | 48 | def get_dataset(*args): 49 | """ Get a single or set of datasets.""" 50 | dset = SequenceList() 51 | for name in args: 52 | dset.extend(load_dataset(name)) 53 | return dset -------------------------------------------------------------------------------- /lib/test/evaluation/environment.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import os 3 | 4 | 5 | class EnvSettings: 6 | def __init__(self): 7 | test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) 8 | 9 | self.results_path = '{}/tracking_results/'.format(test_path) 10 | self.segmentation_path = '{}/segmentation_results/'.format(test_path) 11 | self.network_path = '{}/networks/'.format(test_path) 12 | self.result_plot_path = '{}/result_plots/'.format(test_path) 13 | self.otb_path = '' 14 | self.nfs_path = '' 15 | self.uav_path = '' 16 | self.tpl_path = '' 17 | self.vot_path = '' 18 | self.got10k_path = '' 19 | self.lasot_path = '' 20 | self.trackingnet_path = '' 21 | self.davis_dir = '' 22 | self.youtubevos_dir = '' 23 | 24 | self.got_packed_results_path = '' 25 | self.got_reports_path = '' 26 | self.tn_packed_results_path = '' 27 | 28 | 29 | def create_default_local_file(): 30 | comment = {'results_path': 'Where to store tracking results', 31 | 'network_path': 'Where tracking networks are stored.'} 32 | 33 | path = os.path.join(os.path.dirname(__file__), 'local.py') 34 | with open(path, 'w') as f: 35 | settings = EnvSettings() 36 | 37 | f.write('from test.evaluation.environment import EnvSettings\n\n') 38 | f.write('def local_env_settings():\n') 39 | f.write(' settings = EnvSettings()\n\n') 40 | f.write(' # Set your local paths here.\n\n') 41 | 42 | for attr in dir(settings): 43 | comment_str = None 44 | if attr in comment: 45 | comment_str = comment[attr] 46 | attr_val = getattr(settings, attr) 47 | if not attr.startswith('__') and not callable(attr_val): 48 | if comment_str is None: 49 | f.write(' settings.{} = \'{}\'\n'.format(attr, attr_val)) 50 | else: 51 | f.write(' settings.{} = \'{}\' # {}\n'.format(attr, attr_val, comment_str)) 52 | f.write('\n return settings\n\n') 53 | 54 | 55 | class EnvSettings_ITP: 56 | def __init__(self, workspace_dir, data_dir, save_dir): 57 | self.prj_dir = workspace_dir 58 | self.save_dir = save_dir 59 | self.results_path = os.path.join(save_dir, 'test/tracking_results') 60 | self.segmentation_path = os.path.join(save_dir, 'test/segmentation_results') 61 | self.network_path = os.path.join(save_dir, 'test/networks') 62 | self.result_plot_path = os.path.join(save_dir, 'test/result_plots') 63 | self.otb_path = os.path.join(data_dir, 'otb') 64 | self.nfs_path = os.path.join(data_dir, 'nfs') 65 | self.uav_path = os.path.join(data_dir, 'uav') 66 | self.tc128_path = os.path.join(data_dir, 'TC128') 67 | self.tpl_path = '' 68 | self.vot_path = os.path.join(data_dir, 'VOT2019') 69 | self.got10k_path = os.path.join(data_dir, 'got10k') 70 | self.got10k_lmdb_path = os.path.join(data_dir, 'got10k_lmdb') 71 | self.lasot_path = os.path.join(data_dir, 'lasot') 72 | self.lasot_lmdb_path = os.path.join(data_dir, 'lasot_lmdb') 73 | self.trackingnet_path = os.path.join(data_dir, 'trackingnet') 74 | self.vot18_path = os.path.join(data_dir, 'vot2018') 75 | self.vot22_path = os.path.join(data_dir, 'vot2022') 76 | self.itb_path = os.path.join(data_dir, 'itb') 77 | self.tnl2k_path = os.path.join(data_dir, 'tnl2k') 78 | self.lasot_extension_subset_path_path = os.path.join(data_dir, 'lasot_extension_subset') 79 | self.davis_dir = '' 80 | self.youtubevos_dir = '' 81 | 82 | self.got_packed_results_path = '' 83 | self.got_reports_path = '' 84 | self.tn_packed_results_path = '' 85 | 86 | 87 | def create_default_local_file_test(workspace_dir, data_dir, save_dir): 88 | comment = {'results_path': 'Where to store tracking results', 89 | 'network_path': 'Where tracking networks are stored.'} 90 | 91 | path = os.path.join(os.path.dirname(__file__), 'local.py') 92 | with open(path, 'w') as f: 93 | settings = EnvSettings_ITP(workspace_dir, data_dir, save_dir) 94 | 95 | f.write('from lib.test.evaluation.environment import EnvSettings\n\n') 96 | f.write('def local_env_settings():\n') 97 | f.write(' settings = EnvSettings()\n\n') 98 | f.write(' # Set your local paths here.\n\n') 99 | 100 | for attr in dir(settings): 101 | comment_str = None 102 | if attr in comment: 103 | comment_str = comment[attr] 104 | attr_val = getattr(settings, attr) 105 | if not attr.startswith('__') and not callable(attr_val): 106 | if comment_str is None: 107 | f.write(' settings.{} = \'{}\'\n'.format(attr, attr_val)) 108 | else: 109 | f.write(' settings.{} = \'{}\' # {}\n'.format(attr, attr_val, comment_str)) 110 | f.write('\n return settings\n\n') 111 | 112 | 113 | def env_settings(): 114 | env_module_name = 'lib.test.evaluation.local' 115 | try: 116 | env_module = importlib.import_module(env_module_name) 117 | return env_module.local_env_settings() 118 | except: 119 | env_file = os.path.join(os.path.dirname(__file__), 'local.py') 120 | 121 | # Create a default file 122 | create_default_local_file() 123 | raise RuntimeError('YOU HAVE NOT SETUP YOUR local.py!!!\n Go to "{}" and set all the paths you need. ' 124 | 'Then try to run again.'.format(env_file)) -------------------------------------------------------------------------------- /lib/test/evaluation/local.py: -------------------------------------------------------------------------------- 1 | from lib.test.evaluation.environment import EnvSettings 2 | 3 | def local_env_settings(): 4 | settings = EnvSettings() 5 | 6 | # Set your local paths here. 7 | 8 | settings.davis_dir = '' 9 | settings.got10k_lmdb_path = '/home/zwu/Tracking/data/got10k_lmdb' 10 | settings.got10k_path = '/home/zwu/Tracking/data/got10k' 11 | settings.got_packed_results_path = '' 12 | settings.got_reports_path = '' 13 | settings.itb_path = '/home/zwu/Tracking/data/itb' 14 | settings.lasot_extension_subset_path_path = '/home/zwu/Tracking/data/lasot_extension_subset' 15 | settings.lasot_lmdb_path = '/home/zwu/Tracking/data/lasot_lmdb' 16 | settings.lasot_path = '/home/zwu/Tracking/data/lasot' 17 | settings.network_path = '/home/zwu/Tracking/output/test/networks' # Where tracking networks are stored. 18 | settings.nfs_path = '/home/zwu/Tracking/data/nfs' 19 | settings.otb_path = '/home/zwu/Tracking/data/otb' 20 | settings.prj_dir = '/home/zwu/Tracking' 21 | settings.result_plot_path = '/home/zwu/Tracking/output/test/result_plots' 22 | settings.results_path = '/home/zwu/Tracking/output/test/tracking_results' # Where to store tracking results 23 | settings.save_dir = '/home/zwu/Tracking/output' 24 | settings.segmentation_path = '/home/zwu/Tracking/output/test/segmentation_results' 25 | settings.tc128_path = '/home/zwu/Tracking/data/TC128' 26 | settings.tn_packed_results_path = '' 27 | settings.tnl2k_path = '/home/zwu/Tracking/data/tnl2k' 28 | settings.tpl_path = '' 29 | settings.trackingnet_path = '/home/zwu/Tracking/data/trackingnet' 30 | settings.uav_path = '/home/zwu/Tracking/data/uav' 31 | settings.vot18_path = '/home/zwu/Tracking/data/vot2018' 32 | settings.vot22_path = '/home/zwu/Tracking/data/vot2022' 33 | settings.vot_path = '/home/zwu/Tracking/data/VOT2019' 34 | settings.youtubevos_dir = '' 35 | 36 | return settings 37 | 38 | -------------------------------------------------------------------------------- /lib/test/parameter/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/parameter/__init__.py -------------------------------------------------------------------------------- /lib/test/parameter/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/parameter/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/parameter/__pycache__/untrack.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/parameter/__pycache__/untrack.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/parameter/__pycache__/vipt.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/parameter/__pycache__/vipt.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/parameter/untrack.py: -------------------------------------------------------------------------------- 1 | from lib.test.utils import TrackerParams 2 | import os 3 | from lib.test.evaluation.environment import env_settings 4 | from lib.config.untrack.config import cfg, update_config_from_file 5 | 6 | 7 | def parameters(yaml_name: str, epoch=None): 8 | params = TrackerParams() 9 | prj_dir = env_settings().prj_dir 10 | save_dir = env_settings().save_dir 11 | # update default config from yaml file 12 | yaml_file = os.path.join(prj_dir, 'experiments/untrack/%s.yaml' % yaml_name) 13 | update_config_from_file(yaml_file) 14 | params.cfg = cfg 15 | print("test config: ", cfg) 16 | 17 | # template and search region 18 | params.template_factor = cfg.TEST.TEMPLATE_FACTOR 19 | params.template_size = cfg.TEST.TEMPLATE_SIZE 20 | params.search_factor = cfg.TEST.SEARCH_FACTOR 21 | params.search_size = cfg.TEST.SEARCH_SIZE 22 | 23 | # Network checkpoint path 24 | params.checkpoint = os.path.join(prj_dir, "./models/UnTrack.pth.tar") 25 | 26 | # whether to save boxes from all queries 27 | params.save_all_boxes = False 28 | 29 | return params 30 | -------------------------------------------------------------------------------- /lib/test/tracker/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/tracker/__init__.py -------------------------------------------------------------------------------- /lib/test/tracker/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/tracker/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/tracker/__pycache__/basetracker.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/tracker/__pycache__/basetracker.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/tracker/__pycache__/data_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/tracker/__pycache__/data_utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/tracker/__pycache__/ostrack.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/tracker/__pycache__/ostrack.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/tracker/__pycache__/untrack.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/tracker/__pycache__/untrack.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/tracker/__pycache__/vipt.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/tracker/__pycache__/vipt.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/tracker/__pycache__/vis_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/tracker/__pycache__/vis_utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/tracker/basetracker.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import torch 4 | from _collections import OrderedDict 5 | 6 | from lib.train.data.processing_utils import transform_image_to_crop 7 | from lib.vis.visdom_cus import Visdom 8 | 9 | 10 | class BaseTracker: 11 | """Base class for all trackers.""" 12 | 13 | def __init__(self, params): 14 | self.params = params 15 | self.visdom = None 16 | 17 | def predicts_segmentation_mask(self): 18 | return False 19 | 20 | def initialize(self, image, info: dict) -> dict: 21 | """Overload this function in your tracker. This should initialize the model.""" 22 | raise NotImplementedError 23 | 24 | def track(self, image, info: dict = None) -> dict: 25 | """Overload this function in your tracker. This should track in the frame and update the model.""" 26 | raise NotImplementedError 27 | 28 | def visdom_draw_tracking(self, image, box, segmentation=None): 29 | if isinstance(box, OrderedDict): 30 | box = [v for k, v in box.items()] 31 | else: 32 | box = (box,) 33 | if segmentation is None: 34 | self.visdom.register((image, *box), 'Tracking', 1, 'Tracking') 35 | else: 36 | self.visdom.register((image, *box, segmentation), 'Tracking', 1, 'Tracking') 37 | 38 | def transform_bbox_to_crop(self, box_in, resize_factor, device, box_extract=None, crop_type='template'): 39 | # box_in: list [x1, y1, w, h], not normalized 40 | # box_extract: same as box_in 41 | # out bbox: Torch.tensor [1, 1, 4], x1y1wh, normalized 42 | if crop_type == 'template': 43 | crop_sz = torch.Tensor([self.params.template_size, self.params.template_size]) 44 | elif crop_type == 'search': 45 | crop_sz = torch.Tensor([self.params.search_size, self.params.search_size]) 46 | else: 47 | raise NotImplementedError 48 | 49 | box_in = torch.tensor(box_in) 50 | if box_extract is None: 51 | box_extract = box_in 52 | else: 53 | box_extract = torch.tensor(box_extract) 54 | template_bbox = transform_image_to_crop(box_in, box_extract, resize_factor, crop_sz, normalize=True) 55 | template_bbox = template_bbox.view(1, 1, 4).to(device) 56 | 57 | return template_bbox 58 | 59 | def _init_visdom(self, visdom_info, debug): 60 | visdom_info = {} if visdom_info is None else visdom_info 61 | self.pause_mode = False 62 | self.step = False 63 | self.next_seq = False 64 | if debug > 0 and visdom_info.get('use_visdom', True): 65 | try: 66 | self.visdom = Visdom(debug, {'handler': self._visdom_ui_handler, 'win_id': 'Tracking'}, 67 | visdom_info=visdom_info) 68 | except: 69 | time.sleep(0.5) 70 | print('!!! WARNING: Visdom could not start, so using matplotlib visualization instead !!!\n' 71 | '!!! Start Visdom in a separate terminal window by typing \'visdom\' !!!') 72 | 73 | def _visdom_ui_handler(self, data): 74 | if data['event_type'] == 'KeyPress': 75 | if data['key'] == ' ': 76 | self.pause_mode = not self.pause_mode 77 | 78 | elif data['key'] == 'ArrowRight' and self.pause_mode: 79 | self.step = True 80 | 81 | elif data['key'] == 'n': 82 | self.next_seq = True 83 | -------------------------------------------------------------------------------- /lib/test/tracker/data_utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import numpy as np 3 | 4 | class Preprocessor(object): 5 | def __init__(self): 6 | self.mean = torch.tensor([0.485, 0.456, 0.406]).view((1, 3, 1, 1)).cuda() 7 | self.std = torch.tensor([0.229, 0.224, 0.225]).view((1, 3, 1, 1)).cuda() 8 | 9 | def process(self, img_arr: np.ndarray): 10 | # Deal with the image patch 11 | img_tensor = torch.tensor(img_arr).cuda().float().permute((2,0,1)).unsqueeze(dim=0) 12 | img_tensor_norm = ((img_tensor / 255.0) - self.mean) / self.std # (1,3,H,W) 13 | return img_tensor_norm 14 | 15 | class PreprocessorMM(object): 16 | def __init__(self): 17 | self.mean = torch.tensor([0.485, 0.456, 0.406, 0.485, 0.456, 0.406]).view((1, 6, 1, 1)).cuda() 18 | self.std = torch.tensor([0.229, 0.224, 0.225, 0.229, 0.224, 0.225]).view((1, 6, 1, 1)).cuda() 19 | 20 | 21 | 22 | #self.mean = torch.tensor([0.485, 0.456, 0.406, 0.485, 0.456, 0.406, 0.485, 0.456, 0.406]).view((1, 9, 1, 1)).cuda() 23 | #self.std = torch.tensor([0.229, 0.224, 0.225, 0.229, 0.224, 0.225, 0.229, 0.224, 0.225]).view((1, 9, 1, 1)).cuda() 24 | 25 | 26 | def process(self, img_arr: np.ndarray): 27 | # Deal with the image patch 28 | 29 | img_tensor = torch.tensor(img_arr).cuda().float().permute((2,0,1)).unsqueeze(dim=0) 30 | temp = img_tensor[:, :-1, ...] 31 | sem = img_tensor[:, -1:, ...] 32 | temp_norm = ((temp / 255.0) - self.mean) / self.std # (1,6,H,W) 33 | img_tensor_norm = torch.cat((temp_norm, sem), dim=1) 34 | #img_tensor_norm = ((img_tensor / 255.0) - self.mean) / self.std # (1,6,H,W) 35 | 36 | return img_tensor_norm 37 | 38 | 39 | class PreprocessorX(object): 40 | def __init__(self): 41 | self.mean = torch.tensor([0.485, 0.456, 0.406]).view((1, 3, 1, 1)).cuda() 42 | self.std = torch.tensor([0.229, 0.224, 0.225]).view((1, 3, 1, 1)).cuda() 43 | 44 | def process(self, img_arr: np.ndarray, amask_arr: np.ndarray): 45 | # Deal with the image patch 46 | img_tensor = torch.tensor(img_arr).cuda().float().permute((2,0,1)).unsqueeze(dim=0) 47 | img_tensor_norm = ((img_tensor / 255.0) - self.mean) / self.std # (1,3,H,W) 48 | # Deal with the attention mask 49 | amask_tensor = torch.from_numpy(amask_arr).to(torch.bool).cuda().unsqueeze(dim=0) # (1,H,W) 50 | return img_tensor_norm, amask_tensor 51 | 52 | 53 | class PreprocessorX_onnx(object): 54 | def __init__(self): 55 | self.mean = np.array([0.485, 0.456, 0.406]).reshape((1, 3, 1, 1)) 56 | self.std = np.array([0.229, 0.224, 0.225]).reshape((1, 3, 1, 1)) 57 | 58 | def process(self, img_arr: np.ndarray, amask_arr: np.ndarray): 59 | """img_arr: (H,W,3), amask_arr: (H,W)""" 60 | # Deal with the image patch 61 | img_arr_4d = img_arr[np.newaxis, :, :, :].transpose(0, 3, 1, 2) 62 | img_arr_4d = (img_arr_4d / 255.0 - self.mean) / self.std # (1, 3, H, W) 63 | # Deal with the attention mask 64 | amask_arr_3d = amask_arr[np.newaxis, :, :] # (1,H,W) 65 | return img_arr_4d.astype(np.float32), amask_arr_3d.astype(np.bool) 66 | -------------------------------------------------------------------------------- /lib/test/tracker/vis_utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | ############## used for visulize eliminated tokens ################# 5 | def get_keep_indices(decisions): 6 | keep_indices = [] 7 | for i in range(3): 8 | if i == 0: 9 | keep_indices.append(decisions[i]) 10 | else: 11 | keep_indices.append(keep_indices[-1][decisions[i]]) 12 | return keep_indices 13 | 14 | 15 | def gen_masked_tokens(tokens, indices, alpha=0.2): 16 | # indices = [i for i in range(196) if i not in indices] 17 | indices = indices[0].astype(int) 18 | tokens = tokens.copy() 19 | tokens[indices] = alpha * tokens[indices] + (1 - alpha) * 255 20 | return tokens 21 | 22 | 23 | def recover_image(tokens, H, W, Hp, Wp, patch_size): 24 | # image: (C, 196, 16, 16) 25 | image = tokens.reshape(Hp, Wp, patch_size, patch_size, 3).swapaxes(1, 2).reshape(H, W, 3) 26 | return image 27 | 28 | 29 | def pad_img(img): 30 | height, width, channels = img.shape 31 | im_bg = np.ones((height, width + 8, channels)) * 255 32 | im_bg[0:height, 0:width, :] = img 33 | return im_bg 34 | 35 | 36 | def gen_visualization(image, mask_indices, patch_size=16): 37 | # image [224, 224, 3] 38 | # mask_indices, list of masked token indices 39 | 40 | # mask mask_indices need to cat 41 | # mask_indices = mask_indices[::-1] 42 | num_stages = len(mask_indices) 43 | for i in range(1, num_stages): 44 | mask_indices[i] = np.concatenate([mask_indices[i-1], mask_indices[i]], axis=1) 45 | 46 | # keep_indices = get_keep_indices(decisions) 47 | image = np.asarray(image) 48 | H, W, C = image.shape 49 | Hp, Wp = H // patch_size, W // patch_size 50 | image_tokens = image.reshape(Hp, patch_size, Wp, patch_size, 3).swapaxes(1, 2).reshape(Hp * Wp, patch_size, patch_size, 3) 51 | 52 | stages = [ 53 | recover_image(gen_masked_tokens(image_tokens, mask_indices[i]), H, W, Hp, Wp, patch_size) 54 | for i in range(num_stages) 55 | ] 56 | imgs = [image] + stages 57 | imgs = [pad_img(img) for img in imgs] 58 | viz = np.concatenate(imgs, axis=1) 59 | return viz 60 | -------------------------------------------------------------------------------- /lib/test/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .params import TrackerParams, FeatureParams, Choice -------------------------------------------------------------------------------- /lib/test/utils/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/utils/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/utils/__pycache__/hann.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/utils/__pycache__/hann.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/utils/__pycache__/params.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/utils/__pycache__/params.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/utils/_init_paths.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | from __future__ import division 3 | from __future__ import print_function 4 | 5 | import os.path as osp 6 | import sys 7 | 8 | 9 | def add_path(path): 10 | if path not in sys.path: 11 | sys.path.insert(0, path) 12 | 13 | 14 | this_dir = osp.dirname(__file__) 15 | 16 | prj_path = osp.join(this_dir, '..', '..', '..') 17 | add_path(prj_path) 18 | -------------------------------------------------------------------------------- /lib/test/utils/hann.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import math 3 | import torch.nn.functional as F 4 | 5 | 6 | def hann1d(sz: int, centered = True) -> torch.Tensor: 7 | """1D cosine window.""" 8 | if centered: 9 | return 0.5 * (1 - torch.cos((2 * math.pi / (sz + 1)) * torch.arange(1, sz + 1).float())) 10 | w = 0.5 * (1 + torch.cos((2 * math.pi / (sz + 2)) * torch.arange(0, sz//2 + 1).float())) 11 | return torch.cat([w, w[1:sz-sz//2].flip((0,))]) 12 | 13 | 14 | def hann2d(sz: torch.Tensor, centered = True) -> torch.Tensor: 15 | """2D cosine window.""" 16 | return hann1d(sz[0].item(), centered).reshape(1, 1, -1, 1) * hann1d(sz[1].item(), centered).reshape(1, 1, 1, -1) 17 | 18 | 19 | def hann2d_bias(sz: torch.Tensor, ctr_point: torch.Tensor, centered = True) -> torch.Tensor: 20 | """2D cosine window.""" 21 | distance = torch.stack([ctr_point, sz-ctr_point], dim=0) 22 | max_distance, _ = distance.max(dim=0) 23 | 24 | hann1d_x = hann1d(max_distance[0].item() * 2, centered) 25 | hann1d_x = hann1d_x[max_distance[0] - distance[0, 0]: max_distance[0] + distance[1, 0]] 26 | hann1d_y = hann1d(max_distance[1].item() * 2, centered) 27 | hann1d_y = hann1d_y[max_distance[1] - distance[0, 1]: max_distance[1] + distance[1, 1]] 28 | 29 | return hann1d_y.reshape(1, 1, -1, 1) * hann1d_x.reshape(1, 1, 1, -1) 30 | 31 | 32 | 33 | def hann2d_clipped(sz: torch.Tensor, effective_sz: torch.Tensor, centered = True) -> torch.Tensor: 34 | """1D clipped cosine window.""" 35 | 36 | # Ensure that the difference is even 37 | effective_sz += (effective_sz - sz) % 2 38 | effective_window = hann1d(effective_sz[0].item(), True).reshape(1, 1, -1, 1) * hann1d(effective_sz[1].item(), True).reshape(1, 1, 1, -1) 39 | 40 | pad = (sz - effective_sz) // 2 41 | 42 | window = F.pad(effective_window, (pad[1].item(), pad[1].item(), pad[0].item(), pad[0].item()), 'replicate') 43 | 44 | if centered: 45 | return window 46 | else: 47 | mid = (sz / 2).int() 48 | window_shift_lr = torch.cat((window[:, :, :, mid[1]:], window[:, :, :, :mid[1]]), 3) 49 | return torch.cat((window_shift_lr[:, :, mid[0]:, :], window_shift_lr[:, :, :mid[0], :]), 2) 50 | 51 | 52 | def gauss_fourier(sz: int, sigma: float, half: bool = False) -> torch.Tensor: 53 | if half: 54 | k = torch.arange(0, int(sz/2+1)) 55 | else: 56 | k = torch.arange(-int((sz-1)/2), int(sz/2+1)) 57 | return (math.sqrt(2*math.pi) * sigma / sz) * torch.exp(-2 * (math.pi * sigma * k.float() / sz)**2) 58 | 59 | 60 | def gauss_spatial(sz, sigma, center=0, end_pad=0): 61 | k = torch.arange(-(sz-1)/2, (sz+1)/2+end_pad) 62 | return torch.exp(-1.0/(2*sigma**2) * (k - center)**2) 63 | 64 | 65 | def label_function(sz: torch.Tensor, sigma: torch.Tensor): 66 | return gauss_fourier(sz[0].item(), sigma[0].item()).reshape(1, 1, -1, 1) * gauss_fourier(sz[1].item(), sigma[1].item(), True).reshape(1, 1, 1, -1) 67 | 68 | def label_function_spatial(sz: torch.Tensor, sigma: torch.Tensor, center: torch.Tensor = torch.zeros(2), end_pad: torch.Tensor = torch.zeros(2)): 69 | """The origin is in the middle of the image.""" 70 | return gauss_spatial(sz[0].item(), sigma[0].item(), center[0], end_pad[0].item()).reshape(1, 1, -1, 1) * \ 71 | gauss_spatial(sz[1].item(), sigma[1].item(), center[1], end_pad[1].item()).reshape(1, 1, 1, -1) 72 | 73 | 74 | def cubic_spline_fourier(f, a): 75 | """The continuous Fourier transform of a cubic spline kernel.""" 76 | 77 | bf = (6*(1 - torch.cos(2 * math.pi * f)) + 3*a*(1 - torch.cos(4 * math.pi * f)) 78 | - (6 + 8*a)*math.pi*f*torch.sin(2 * math.pi * f) - 2*a*math.pi*f*torch.sin(4 * math.pi * f)) \ 79 | / (4 * math.pi**4 * f**4) 80 | 81 | bf[f == 0] = 1 82 | 83 | return bf 84 | 85 | def max2d(a: torch.Tensor) -> (torch.Tensor, torch.Tensor): 86 | """Computes maximum and argmax in the last two dimensions.""" 87 | 88 | max_val_row, argmax_row = torch.max(a, dim=-2) 89 | max_val, argmax_col = torch.max(max_val_row, dim=-1) 90 | argmax_row = argmax_row.view(argmax_col.numel(),-1)[torch.arange(argmax_col.numel()), argmax_col.view(-1)] 91 | argmax_row = argmax_row.reshape(argmax_col.shape) 92 | argmax = torch.cat((argmax_row.unsqueeze(-1), argmax_col.unsqueeze(-1)), -1) 93 | return max_val, argmax 94 | -------------------------------------------------------------------------------- /lib/test/utils/load_text.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | 4 | 5 | def load_text_numpy(path, delimiter, dtype): 6 | if isinstance(delimiter, (tuple, list)): 7 | for d in delimiter: 8 | try: 9 | ground_truth_rect = np.loadtxt(path, delimiter=d, dtype=dtype) 10 | return ground_truth_rect 11 | except: 12 | pass 13 | 14 | raise Exception('Could not read file {}'.format(path)) 15 | else: 16 | ground_truth_rect = np.loadtxt(path, delimiter=delimiter, dtype=dtype) 17 | return ground_truth_rect 18 | 19 | 20 | def load_text_pandas(path, delimiter, dtype): 21 | if isinstance(delimiter, (tuple, list)): 22 | for d in delimiter: 23 | try: 24 | ground_truth_rect = pd.read_csv(path, delimiter=d, header=None, dtype=dtype, na_filter=False, 25 | low_memory=False).values 26 | return ground_truth_rect 27 | except Exception as e: 28 | pass 29 | 30 | raise Exception('Could not read file {}'.format(path)) 31 | else: 32 | ground_truth_rect = pd.read_csv(path, delimiter=delimiter, header=None, dtype=dtype, na_filter=False, 33 | low_memory=False).values 34 | return ground_truth_rect 35 | 36 | 37 | def load_text(path, delimiter=' ', dtype=np.float32, backend='numpy'): 38 | if backend == 'numpy': 39 | return load_text_numpy(path, delimiter, dtype) 40 | elif backend == 'pandas': 41 | return load_text_pandas(path, delimiter, dtype) 42 | 43 | 44 | def load_str(path): 45 | with open(path, "r") as f: 46 | text_str = f.readline().strip().lower() 47 | return text_str 48 | -------------------------------------------------------------------------------- /lib/test/utils/params.py: -------------------------------------------------------------------------------- 1 | from lib.utils import TensorList 2 | import random 3 | 4 | 5 | class TrackerParams: 6 | """Class for tracker parameters.""" 7 | def set_default_values(self, default_vals: dict): 8 | for name, val in default_vals.items(): 9 | if not hasattr(self, name): 10 | setattr(self, name, val) 11 | 12 | def get(self, name: str, *default): 13 | """Get a parameter value with the given name. If it does not exists, it return the default value given as a 14 | second argument or returns an error if no default value is given.""" 15 | if len(default) > 1: 16 | raise ValueError('Can only give one default value.') 17 | 18 | if not default: 19 | return getattr(self, name) 20 | 21 | return getattr(self, name, default[0]) 22 | 23 | def has(self, name: str): 24 | """Check if there exist a parameter with the given name.""" 25 | return hasattr(self, name) 26 | 27 | 28 | class FeatureParams: 29 | """Class for feature specific parameters""" 30 | def __init__(self, *args, **kwargs): 31 | if len(args) > 0: 32 | raise ValueError 33 | 34 | for name, val in kwargs.items(): 35 | if isinstance(val, list): 36 | setattr(self, name, TensorList(val)) 37 | else: 38 | setattr(self, name, val) 39 | 40 | 41 | def Choice(*args): 42 | """Can be used to sample random parameter values.""" 43 | return random.choice(args) 44 | -------------------------------------------------------------------------------- /lib/test/vot/__pycache__/untrack_baseline.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/vot/__pycache__/untrack_baseline.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/vot/__pycache__/untrack_class.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/vot/__pycache__/untrack_class.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/vot/__pycache__/vipt_baseline.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/vot/__pycache__/vipt_baseline.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/vot/__pycache__/vipt_class.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/vot/__pycache__/vipt_class.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/vot/__pycache__/vot.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/vot/__pycache__/vot.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/vot/__pycache__/vot22_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/test/vot/__pycache__/vot22_utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/test/vot/untrack_baseline.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | print('************************************') 4 | env_path = os.path.join(os.path.dirname(__file__), '../../..') 5 | print('*********************************', env_path) 6 | if env_path not in sys.path: 7 | sys.path.append(env_path) 8 | 9 | from lib.test.vot.untrack_class import run_vot_exp 10 | os.environ['CUDA_VISIBLE_DEVICES'] = '0' 11 | 12 | 13 | run_vot_exp('untrack', 'deep_rgbd', vis=False, out_conf=True, channel_type='rgbd') 14 | -------------------------------------------------------------------------------- /lib/test/vot/untrack_class.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | from __future__ import division 3 | from __future__ import print_function 4 | from __future__ import unicode_literals 5 | 6 | import pdb 7 | import cv2 8 | import torch 9 | # import vot 10 | import sys 11 | import time 12 | import os 13 | from lib.test.evaluation import Tracker 14 | import lib.test.vot.vot as vot 15 | from lib.test.vot.vot22_utils import * 16 | from lib.train.dataset.depth_utils import get_rgbd_frame 17 | 18 | 19 | class untrack(object): 20 | def __init__(self, tracker_name='', para_name=''): 21 | # create tracker 22 | tracker_info = Tracker(tracker_name, para_name, "vot22", None) 23 | params = tracker_info.get_parameters() 24 | params.visualization = False 25 | params.debug = False 26 | self.tracker = tracker_info.create_tracker(params) 27 | 28 | def write(self, str): 29 | txt_path = "" 30 | file = open(txt_path, 'a') 31 | file.write(str) 32 | 33 | def initialize(self, img_rgb, selection): 34 | # init on the 1st frame 35 | # region = rect_from_mask(mask) 36 | x, y, w, h = selection 37 | bbox = [x,y,w,h] 38 | self.H, self.W, _ = img_rgb.shape 39 | init_info = {'init_bbox': bbox} 40 | _ = self.tracker.initialize(img_rgb, init_info) 41 | 42 | def track(self, img_rgb): 43 | # track 44 | outputs = self.tracker.track(img_rgb) 45 | pred_bbox = outputs['target_bbox'] 46 | max_score = outputs['best_score'] #.max().cpu().numpy() 47 | return pred_bbox, max_score 48 | 49 | 50 | def run_vot_exp(tracker_name, para_name, vis=False, out_conf=False, channel_type='color'): 51 | 52 | torch.set_num_threads(1) 53 | save_root = os.path.join('', para_name) 54 | if vis and (not os.path.exists(save_root)): 55 | os.mkdir(save_root) 56 | 57 | 58 | print(tracker_name) 59 | print("######") 60 | print(para_name) 61 | tracker = untrack(tracker_name=tracker_name, para_name=para_name) 62 | print('No prob after tracker init') 63 | 64 | if channel_type=='rgb': 65 | channel_type=None 66 | handle = vot.VOT("rectangle", channels=channel_type) 67 | 68 | selection = handle.region() 69 | imagefile = handle.frame() 70 | 71 | if not imagefile: 72 | sys.exit(0) 73 | if vis: 74 | '''for vis''' 75 | seq_name = imagefile.split('/')[-3] 76 | save_v_dir = os.path.join(save_root,seq_name) 77 | if not os.path.exists(save_v_dir): 78 | os.mkdir(save_v_dir) 79 | cur_time = int(time.time() % 10000) 80 | save_dir = os.path.join(save_v_dir, str(cur_time)) 81 | if not os.path.exists(save_dir): 82 | os.makedirs(save_dir) 83 | 84 | 85 | # read rgbd data 86 | if isinstance(imagefile, list) and len(imagefile)==2: 87 | image = get_rgbd_frame(imagefile[0], imagefile[1], dtype='rgbcolormap', depth_clip=True) 88 | 89 | modality = image[:, :, 3:] 90 | if '/depth/' in imagefile[1]: 91 | dummy = modality[:, :, 0:1].copy() * 0 + 1 92 | image = cv2.merge((image[:, :, :3], modality, dummy)) 93 | else: 94 | dummy = modality[:, :, 0:1].copy() * 0 + 1 95 | image = cv2.merge((image[:, :, :3], modality, dummy)) 96 | else: 97 | image = cv2.cvtColor(cv2.imread(imagefile), cv2.COLOR_BGR2RGB) # Right 98 | 99 | tracker.initialize(image, selection) 100 | 101 | while True: 102 | imagefile = handle.frame() 103 | if not imagefile: 104 | break 105 | 106 | # read rgbd data 107 | if isinstance(imagefile, list) and len(imagefile) == 2: 108 | image = get_rgbd_frame(imagefile[0], imagefile[1], dtype='rgbcolormap', depth_clip=True) 109 | 110 | 111 | modality = image[:, :, 3:] 112 | if '/depth/' in imagefile[1]: 113 | dummy = modality[:, :, 0:1].copy() * 0 + 1 # +1 for depth 114 | image = cv2.merge((image[:, :, :3], modality, dummy)) 115 | else: 116 | dummy = modality[:, :, 0:1].copy() * 0 + 1 117 | image = cv2.merge((image[:, :, :3], modality, dummy)) 118 | 119 | 120 | else: 121 | image = cv2.cvtColor(cv2.imread(imagefile), cv2.COLOR_BGR2RGB) # Right 122 | 123 | b1, max_score = tracker.track(image) 124 | 125 | if out_conf: 126 | handle.report(vot.Rectangle(*b1), max_score) 127 | else: 128 | handle.report(vot.Rectangle(*b1)) 129 | if vis: 130 | '''Visualization''' 131 | # original image 132 | image_ori = image[:,:,::-1].copy() # RGB --> BGR 133 | image_name = imagefile.split('/')[-1] 134 | save_path = os.path.join(save_dir, image_name) 135 | image_b = image_ori.copy() 136 | cv2.rectangle(image_b, (int(b1[0]), int(b1[1])), 137 | (int(b1[0] + b1[2]), int(b1[1] + b1[3])), (0, 0, 255), 2) 138 | image_b_name = image_name.replace('.jpg','_bbox.jpg') 139 | save_path = os.path.join(save_dir, image_b_name) 140 | cv2.imwrite(save_path, image_b) 141 | 142 | -------------------------------------------------------------------------------- /lib/test/vot/vot.py: -------------------------------------------------------------------------------- 1 | """ 2 | \file vot.py 3 | @brief Python utility functions for VOT integration 4 | @author Luka Cehovin, Alessio Dore 5 | @date 2016 6 | """ 7 | 8 | import sys 9 | import copy 10 | import collections 11 | import numpy as np 12 | 13 | try: 14 | import trax 15 | except ImportError: 16 | raise Exception('TraX support not found. Please add trax module to Python path.') 17 | 18 | Rectangle = collections.namedtuple('Rectangle', ['x', 'y', 'width', 'height']) 19 | Point = collections.namedtuple('Point', ['x', 'y']) 20 | Polygon = collections.namedtuple('Polygon', ['points']) 21 | 22 | class VOT(object): 23 | """ Base class for Python VOT integration """ 24 | def __init__(self, region_format, channels=None): 25 | """ Constructor 26 | Args: 27 | region_format: Region format options 28 | """ 29 | assert(region_format in [trax.Region.RECTANGLE, trax.Region.POLYGON, trax.Region.MASK]) 30 | 31 | if channels is None: 32 | channels = ['color'] 33 | elif channels == 'rgbd': 34 | channels = ['color', 'depth'] 35 | elif channels == 'rgbt': 36 | channels = ['color', 'ir'] 37 | elif channels == 'ir': 38 | channels = ['ir'] 39 | else: 40 | raise Exception('Illegal configuration {}.'.format(channels)) 41 | 42 | # self._trax = trax.Server([region_format], [trax.Image.PATH], channels, customMetadata=dict(vot="python")) 43 | self._trax = trax.Server([region_format], [trax.Image.PATH], channels, customMetadata=dict(vot="python")) 44 | 45 | request = self._trax.wait() 46 | assert(request.type == 'initialize') 47 | if isinstance(request.region, trax.Polygon): 48 | self._region = Polygon([Point(x[0], x[1]) for x in request.region]) 49 | elif isinstance(request.region, trax.Mask): 50 | self._region = request.region.array(True) 51 | else: 52 | self._region = Rectangle(*request.region.bounds()) 53 | self._image = [x.path() for k, x in request.image.items()] 54 | if len(self._image) == 1: 55 | self._image = self._image[0] 56 | 57 | self._trax.status(request.region) 58 | 59 | def region(self): 60 | """ 61 | Send configuration message to the client and receive the initialization 62 | region and the path of the first image 63 | Returns: 64 | initialization region 65 | """ 66 | 67 | return self._region 68 | 69 | def report(self, region, confidence = None): 70 | """ 71 | Report the tracking results to the client 72 | Arguments: 73 | region: region for the frame 74 | """ 75 | assert(isinstance(region, (Rectangle, Polygon, np.ndarray))) 76 | if isinstance(region, Polygon): 77 | tregion = trax.Polygon.create([(x.x, x.y) for x in region.points]) 78 | elif isinstance(region, np.ndarray): 79 | tregion = trax.Mask.create(region) 80 | else: 81 | tregion = trax.Rectangle.create(region.x, region.y, region.width, region.height) 82 | properties = {} 83 | if not confidence is None: 84 | properties['confidence'] = confidence 85 | self._trax.status(tregion, properties) 86 | 87 | def frame(self): 88 | """ 89 | Get a frame (image path) from client 90 | Returns: 91 | absolute path of the image 92 | """ 93 | if hasattr(self, "_image"): 94 | image = self._image 95 | del self._image 96 | return image 97 | 98 | request = self._trax.wait() 99 | 100 | if request.type == 'frame': 101 | image = [x.path() for k, x in request.image.items()] 102 | if len(image) == 1: 103 | return image[0] 104 | return image 105 | else: 106 | return None 107 | 108 | 109 | def quit(self): 110 | if hasattr(self, '_trax'): 111 | self._trax.quit() 112 | 113 | def __del__(self): 114 | self.quit() 115 | -------------------------------------------------------------------------------- /lib/test/vot/vot22_utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | def make_full_size(x, output_sz): 5 | """ 6 | zero-pad input x (right and down) to match output_sz 7 | x: numpy array e.g., binary mask 8 | output_sz: size of the output [width, height] 9 | """ 10 | if x.shape[0] == output_sz[1] and x.shape[1] == output_sz[0]: 11 | return x 12 | pad_x = output_sz[0] - x.shape[1] 13 | if pad_x < 0: 14 | x = x[:, :x.shape[1] + pad_x] 15 | # padding has to be set to zero, otherwise pad function fails 16 | pad_x = 0 17 | pad_y = output_sz[1] - x.shape[0] 18 | if pad_y < 0: 19 | x = x[:x.shape[0] + pad_y, :] 20 | # padding has to be set to zero, otherwise pad function fails 21 | pad_y = 0 22 | return np.pad(x, ((0, pad_y), (0, pad_x)), 'constant', constant_values=0) 23 | 24 | 25 | def rect_from_mask(mask): 26 | """ 27 | create an axis-aligned rectangle from a given binary mask 28 | mask in created as a minimal rectangle containing all non-zero pixels 29 | """ 30 | x_ = np.sum(mask, axis=0) 31 | y_ = np.sum(mask, axis=1) 32 | x0 = np.min(np.nonzero(x_)) 33 | x1 = np.max(np.nonzero(x_)) 34 | y0 = np.min(np.nonzero(y_)) 35 | y1 = np.max(np.nonzero(y_)) 36 | return [x0, y0, x1 - x0 + 1, y1 - y0 + 1] 37 | 38 | 39 | def mask_from_rect(rect, output_sz): 40 | """ 41 | create a binary mask from a given rectangle 42 | rect: axis-aligned rectangle [x0, y0, width, height] 43 | output_sz: size of the output [width, height] 44 | """ 45 | mask = np.zeros((output_sz[1], output_sz[0]), dtype=np.uint8) 46 | x0 = max(int(round(rect[0])), 0) 47 | y0 = max(int(round(rect[1])), 0) 48 | x1 = min(int(round(rect[0] + rect[2])), output_sz[0]) 49 | y1 = min(int(round(rect[1] + rect[3])), output_sz[1]) 50 | mask[y0:y1, x0:x1] = 1 51 | return mask 52 | 53 | 54 | def bbox_clip(x1, y1, x2, y2, boundary, min_sz=10): 55 | """boundary (H,W)""" 56 | x1_new = max(0, min(x1, boundary[1] - min_sz)) 57 | y1_new = max(0, min(y1, boundary[0] - min_sz)) 58 | x2_new = max(min_sz, min(x2, boundary[1])) 59 | y2_new = max(min_sz, min(y2, boundary[0])) 60 | return x1_new, y1_new, x2_new, y2_new -------------------------------------------------------------------------------- /lib/train/__init__.py: -------------------------------------------------------------------------------- 1 | from .admin.multigpu import MultiGPU 2 | -------------------------------------------------------------------------------- /lib/train/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /lib/train/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/__pycache__/_init_paths.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/__pycache__/_init_paths.cpython-310.pyc -------------------------------------------------------------------------------- /lib/train/__pycache__/_init_paths.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/__pycache__/_init_paths.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/__pycache__/base_functions.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/__pycache__/base_functions.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/__pycache__/train_script.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/__pycache__/train_script.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/_init_paths.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | from __future__ import division 3 | from __future__ import print_function 4 | 5 | import os.path as osp 6 | import sys 7 | 8 | 9 | def add_path(path): 10 | if path not in sys.path: 11 | sys.path.insert(0, path) 12 | 13 | 14 | this_dir = osp.dirname(__file__) 15 | 16 | prj_path = osp.join(this_dir, '../..') 17 | add_path(prj_path) 18 | -------------------------------------------------------------------------------- /lib/train/actors/__init__.py: -------------------------------------------------------------------------------- 1 | from .base_actor import BaseActor 2 | from .untrack import UntrackActor 3 | -------------------------------------------------------------------------------- /lib/train/actors/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/actors/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/actors/__pycache__/base_actor.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/actors/__pycache__/base_actor.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/actors/__pycache__/untrack.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/actors/__pycache__/untrack.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/actors/__pycache__/vipt.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/actors/__pycache__/vipt.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/actors/base_actor.py: -------------------------------------------------------------------------------- 1 | from lib.utils import TensorDict 2 | 3 | 4 | class BaseActor: 5 | """ Base class for actor. The actor class handles the passing of the data through the network 6 | and calculation the loss""" 7 | def __init__(self, net, objective): 8 | """ 9 | args: 10 | net - The network to train 11 | objective - The loss function 12 | """ 13 | self.net = net 14 | self.objective = objective 15 | 16 | def __call__(self, data: TensorDict): 17 | """ Called in each training iteration. Should pass in input data through the network, calculate the loss, and 18 | return the training stats for the input data 19 | args: 20 | data - A TensorDict containing all the necessary data blocks. 21 | 22 | returns: 23 | loss - loss for the input data 24 | stats - a dict containing detailed losses 25 | """ 26 | raise NotImplementedError 27 | 28 | def to(self, device): 29 | """ Move the network to device 30 | args: 31 | device - device to use. 'cpu' or 'cuda' 32 | """ 33 | self.net.to(device) 34 | 35 | def train(self, mode=True): 36 | """ Set whether the network is in train mode. 37 | args: 38 | mode (True) - Bool specifying whether in training mode. 39 | """ 40 | self.net.train(mode) 41 | 42 | def eval(self): 43 | """ Set network to eval mode""" 44 | self.train(False) -------------------------------------------------------------------------------- /lib/train/actors/untrack.py: -------------------------------------------------------------------------------- 1 | import pdb 2 | 3 | from . import BaseActor 4 | from lib.utils.box_ops import box_cxcywh_to_xyxy, box_xywh_to_xyxy 5 | import torch 6 | from ...utils.heapmap_utils import generate_heatmap 7 | from ...utils.ce_utils import generate_mask_cond, adjust_keep_rate 8 | from lib.train.admin import multigpu 9 | 10 | 11 | class UntrackActor(BaseActor): 12 | """ Actor for training UnTrack models """ 13 | 14 | def __init__(self, net, objective, loss_weight, settings, cfg=None): 15 | super().__init__(net, objective) 16 | self.loss_weight = loss_weight 17 | self.settings = settings 18 | self.bs = self.settings.batchsize # batch size 19 | self.cfg = cfg 20 | 21 | def fix_bns(self): 22 | net = self.net.module if multigpu.is_multi_gpu(self.net) else self.net 23 | net.box_head.apply(self.fix_bn) 24 | 25 | def fix_bn(self, m): 26 | classname = m.__class__.__name__ 27 | if classname.find('BatchNorm') != -1: 28 | m.eval() 29 | 30 | def __call__(self, data): 31 | """ 32 | args: 33 | data - The input data, should contain the fields 'template', 'search', 'gt_bbox'. 34 | template_images: (N_t, batch, 3, H, W) 35 | search_images: (N_s, batch, 3, H, W) 36 | returns: 37 | loss - the training loss 38 | status - dict containing detailed losses 39 | """ 40 | # forward pass 41 | out_dict = self.forward_pass(data) 42 | # compute losses 43 | loss, status = self.compute_losses(out_dict, data) 44 | 45 | return loss, status 46 | 47 | def forward_pass(self, data): 48 | # currently only support 1 template and 1 search region 49 | assert len(data['template_images']) == 1 50 | assert len(data['search_images']) == 1 51 | 52 | template_list = [] 53 | for i in range(self.settings.num_template): 54 | template_img_i = data['template_images'][i].view(-1, 55 | *data['template_images'].shape[2:]) # (batch, 6, 128, 128) 56 | template_list.append(template_img_i) 57 | 58 | search_img = data['search_images'][0].view(-1, *data['search_images'].shape[2:]) # (batch, 6, 320, 320) 59 | 60 | box_mask_z = None 61 | ce_keep_rate = None 62 | if self.cfg.MODEL.BACKBONE.CE_LOC: 63 | box_mask_z = generate_mask_cond(self.cfg, template_list[0].shape[0], template_list[0].device, 64 | data['template_anno'][0]) 65 | 66 | ce_start_epoch = self.cfg.TRAIN.CE_START_EPOCH 67 | ce_warm_epoch = self.cfg.TRAIN.CE_WARM_EPOCH 68 | ce_keep_rate = adjust_keep_rate(data['epoch'], warmup_epochs=ce_start_epoch, 69 | total_epochs=ce_start_epoch + ce_warm_epoch, 70 | ITERS_PER_EPOCH=1, 71 | base_keep_rate=self.cfg.MODEL.BACKBONE.CE_KEEP_RATIO[0]) 72 | # ce_keep_rate = 0.7 73 | 74 | if len(template_list) == 1: 75 | template_list = template_list[0] 76 | 77 | out_dict = self.net(template=template_list, 78 | search=search_img, 79 | ce_template_mask=box_mask_z, 80 | ce_keep_rate=ce_keep_rate, 81 | return_last_attn=False) 82 | 83 | return out_dict 84 | 85 | def compute_losses(self, pred_dict, gt_dict, return_status=True): 86 | #infonce = pred_dict['infonce'] 87 | 88 | # gt gaussian map 89 | gt_bbox = gt_dict['search_anno'][-1] # (Ns, batch, 4) (x1,y1,w,h) -> (batch, 4) 90 | gt_gaussian_maps = generate_heatmap(gt_dict['search_anno'], self.cfg.DATA.SEARCH.SIZE, self.cfg.MODEL.BACKBONE.STRIDE) 91 | gt_gaussian_maps = gt_gaussian_maps[-1].unsqueeze(1) # (B,1,H,W) 92 | 93 | # Get boxes 94 | pred_boxes = pred_dict['pred_boxes'] 95 | if torch.isnan(pred_boxes).any(): 96 | raise ValueError("Network outputs is NAN! Stop Training") 97 | num_queries = pred_boxes.size(1) 98 | pred_boxes_vec = box_cxcywh_to_xyxy(pred_boxes).view(-1, 4) # (B,N,4) --> (BN,4) (x1,y1,x2,y2) 99 | gt_boxes_vec = box_xywh_to_xyxy(gt_bbox)[:, None, :].repeat((1, num_queries, 1)).view(-1, 4).clamp(min=0.0, 100 | max=1.0) # (B,4) --> (B,1,4) --> (B,N,4) 101 | # compute giou and iou 102 | try: 103 | giou_loss, iou = self.objective['giou'](pred_boxes_vec, gt_boxes_vec) # (BN,4) (BN,4) 104 | except: 105 | giou_loss, iou = torch.tensor(0.0).cuda(), torch.tensor(0.0).cuda() 106 | # compute l1 loss 107 | l1_loss = self.objective['l1'](pred_boxes_vec, gt_boxes_vec) # (BN,4) (BN,4) 108 | # compute location loss 109 | if 'score_map' in pred_dict: 110 | location_loss = self.objective['focal'](pred_dict['score_map'], gt_gaussian_maps) 111 | else: 112 | location_loss = torch.tensor(0.0, device=l1_loss.device) 113 | # weighted sum 114 | loss = self.loss_weight['giou'] * giou_loss + self.loss_weight['l1'] * l1_loss + self.loss_weight['focal'] * location_loss 115 | if return_status: 116 | # status for log 117 | mean_iou = iou.detach().mean() 118 | status = {"Loss/total": loss.item(), 119 | "Loss/giou": giou_loss.item(), 120 | "Loss/l1": l1_loss.item(), 121 | "Loss/location": location_loss.item(), 122 | "IoU": mean_iou.item(), 123 | } 124 | return loss, status 125 | else: 126 | return loss -------------------------------------------------------------------------------- /lib/train/admin/__init__.py: -------------------------------------------------------------------------------- 1 | from .environment import env_settings, create_default_local_file_train 2 | from .tensorboard import TensorboardWriter 3 | from .stats import AverageMeter, StatValue -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/environment.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/environment.cpython-310.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/environment.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/environment.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/local.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/local.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/multigpu.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/multigpu.cpython-310.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/multigpu.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/multigpu.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/settings.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/settings.cpython-310.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/settings.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/settings.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/stats.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/stats.cpython-310.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/stats.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/stats.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/tensorboard.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/tensorboard.cpython-310.pyc -------------------------------------------------------------------------------- /lib/train/admin/__pycache__/tensorboard.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/admin/__pycache__/tensorboard.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/admin/environment.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import os 3 | from collections import OrderedDict 4 | 5 | 6 | def create_default_local_file(): 7 | path = os.path.join(os.path.dirname(__file__), 'local.py') 8 | 9 | empty_str = '\'\'' 10 | default_settings = OrderedDict({ 11 | 'workspace_dir': empty_str, 12 | 'tensorboard_dir': 'self.workspace_dir + \'/tensorboard/\'', 13 | 'pretrained_networks': 'self.workspace_dir + \'/pretrained_networks/\'', 14 | 'lasot_dir': empty_str, 15 | 'got10k_dir': empty_str, 16 | 'trackingnet_dir': empty_str, 17 | 'coco_dir': empty_str, 18 | 'lvis_dir': empty_str, 19 | 'sbd_dir': empty_str, 20 | 'imagenet_dir': empty_str, 21 | 'imagenetdet_dir': empty_str, 22 | 'ecssd_dir': empty_str, 23 | 'hkuis_dir': empty_str, 24 | 'msra10k_dir': empty_str, 25 | 'davis_dir': empty_str, 26 | 'youtubevos_dir': empty_str}) 27 | 28 | comment = {'workspace_dir': 'Base directory for saving network checkpoints.', 29 | 'tensorboard_dir': 'Directory for tensorboard files.'} 30 | 31 | with open(path, 'w') as f: 32 | f.write('class EnvironmentSettings:\n') 33 | f.write(' def __init__(self):\n') 34 | 35 | for attr, attr_val in default_settings.items(): 36 | comment_str = None 37 | if attr in comment: 38 | comment_str = comment[attr] 39 | if comment_str is None: 40 | f.write(' self.{} = {}\n'.format(attr, attr_val)) 41 | else: 42 | f.write(' self.{} = {} # {}\n'.format(attr, attr_val, comment_str)) 43 | 44 | 45 | def create_default_local_file_train(workspace_dir, data_dir): 46 | path = os.path.join(os.path.dirname(__file__), 'local.py') 47 | 48 | empty_str = '\'\'' 49 | default_settings = OrderedDict({ 50 | 'workspace_dir': workspace_dir, 51 | 'tensorboard_dir': os.path.join(workspace_dir, 'tensorboard'), # Directory for tensorboard files. 52 | 'pretrained_networks': os.path.join(workspace_dir, 'pretrained_networks'), 53 | 'got10k_val_dir': os.path.join(data_dir, 'got10k/val'), 54 | 'lasot_lmdb_dir': os.path.join(data_dir, 'lasot_lmdb'), 55 | 'got10k_lmdb_dir': os.path.join(data_dir, 'got10k_lmdb'), 56 | 'trackingnet_lmdb_dir': os.path.join(data_dir, 'trackingnet_lmdb'), 57 | 'coco_lmdb_dir': os.path.join(data_dir, 'coco_lmdb'), 58 | 'coco_dir': os.path.join(data_dir, 'coco'), 59 | 'lasot_dir': os.path.join(data_dir, 'lasot'), 60 | 'got10k_dir': os.path.join(data_dir, 'got10k/train'), 61 | 'trackingnet_dir': os.path.join(data_dir, 'trackingnet'), 62 | 'depthtrack_dir': os.path.join(data_dir, 'depthtrack/train'), 63 | 'lasher_dir': os.path.join(data_dir, 'lasher/trainingset'), 64 | 'visevent_dir': os.path.join(data_dir, 'visevent/train'), 65 | }) 66 | 67 | comment = {'workspace_dir': 'Base directory for saving network checkpoints.', 68 | 'tensorboard_dir': 'Directory for tensorboard files.'} 69 | 70 | with open(path, 'w') as f: 71 | f.write('class EnvironmentSettings:\n') 72 | f.write(' def __init__(self):\n') 73 | 74 | for attr, attr_val in default_settings.items(): 75 | comment_str = None 76 | if attr in comment: 77 | comment_str = comment[attr] 78 | if comment_str is None: 79 | if attr_val == empty_str: 80 | f.write(' self.{} = {}\n'.format(attr, attr_val)) 81 | else: 82 | f.write(' self.{} = \'{}\'\n'.format(attr, attr_val)) 83 | else: 84 | f.write(' self.{} = \'{}\' # {}\n'.format(attr, attr_val, comment_str)) 85 | 86 | 87 | def env_settings(): 88 | env_module_name = 'lib.train.admin.local' 89 | try: 90 | env_module = importlib.import_module(env_module_name) 91 | return env_module.EnvironmentSettings() 92 | except: 93 | env_file = os.path.join(os.path.dirname(__file__), 'local.py') 94 | 95 | create_default_local_file() 96 | raise RuntimeError('YOU HAVE NOT SETUP YOUR local.py!!!\n Go to "{}" and set all the paths you need. Then try to run again.'.format(env_file)) 97 | -------------------------------------------------------------------------------- /lib/train/admin/local.py: -------------------------------------------------------------------------------- 1 | class EnvironmentSettings: 2 | def __init__(self): 3 | self.workspace_dir = '/home/zwu/Tracking' # Base directory for saving network checkpoints. 4 | self.tensorboard_dir = '/home/zwu/Tracking/tensorboard' # Directory for tensorboard files. 5 | self.pretrained_networks = '/home/zwu/Tracking/pretrained_networks' 6 | self.got10k_val_dir = '/home/zwu/Tracking/data/got10k/val' 7 | self.lasot_lmdb_dir = '/home/zwu/Tracking/data/lasot_lmdb' 8 | self.got10k_lmdb_dir = '/home/zwu/Tracking/data/got10k_lmdb' 9 | self.trackingnet_lmdb_dir = '/home/zwu/Tracking/data/trackingnet_lmdb' 10 | self.coco_lmdb_dir = '/home/zwu/Tracking/data/coco_lmdb' 11 | self.coco_dir = '/home/zwu/Tracking/data/coco' 12 | self.lasot_dir = '/home/zwu/Tracking/data/lasot' 13 | self.got10k_dir = '/home/zwu/Tracking/data/got10k/train' 14 | self.trackingnet_dir = '/home/zwu/Tracking/data/trackingnet' 15 | self.depthtrack_dir = '/home/zwu/Tracking/data/depthtrack/train' 16 | self.lasher_dir = '/home/zwu/Tracking/data/lasher/trainingset' 17 | self.visevent_dir = '/home/zwu/Tracking/data/visevent/train' 18 | -------------------------------------------------------------------------------- /lib/train/admin/multigpu.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | # Here we use DistributedDataParallel(DDP) rather than DataParallel(DP) for multiple GPUs training 3 | 4 | 5 | def is_multi_gpu(net): 6 | return isinstance(net, (MultiGPU, nn.parallel.distributed.DistributedDataParallel)) 7 | 8 | 9 | class MultiGPU(nn.parallel.distributed.DistributedDataParallel): 10 | def __getattr__(self, item): 11 | try: 12 | return super().__getattr__(item) 13 | except: 14 | pass 15 | return getattr(self.module, item) 16 | -------------------------------------------------------------------------------- /lib/train/admin/settings.py: -------------------------------------------------------------------------------- 1 | from lib.train.admin.environment import env_settings 2 | 3 | 4 | class Settings: 5 | """ Training settings, e.g. the paths to datasets and networks.""" 6 | def __init__(self): 7 | self.set_default() 8 | 9 | def set_default(self): 10 | self.env = env_settings() 11 | self.use_gpu = True 12 | 13 | 14 | -------------------------------------------------------------------------------- /lib/train/admin/stats.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class StatValue: 4 | def __init__(self): 5 | self.clear() 6 | 7 | def reset(self): 8 | self.val = 0 9 | 10 | def clear(self): 11 | self.reset() 12 | self.history = [] 13 | 14 | def update(self, val): 15 | self.val = val 16 | self.history.append(self.val) 17 | 18 | 19 | class AverageMeter(object): 20 | """Computes and stores the average and current value""" 21 | def __init__(self): 22 | self.clear() 23 | self.has_new_data = False 24 | 25 | def reset(self): 26 | self.avg = 0 27 | self.val = 0 28 | self.sum = 0 29 | self.count = 0 30 | 31 | def clear(self): 32 | self.reset() 33 | self.history = [] 34 | 35 | def update(self, val, n=1): 36 | self.val = val 37 | self.sum += val * n 38 | self.count += n 39 | self.avg = self.sum / self.count 40 | 41 | def new_epoch(self): 42 | if self.count > 0: 43 | self.history.append(self.avg) 44 | self.reset() 45 | self.has_new_data = True 46 | else: 47 | self.has_new_data = False 48 | 49 | 50 | def topk_accuracy(output, target, topk=(1,)): 51 | """Computes the precision@k for the specified values of k""" 52 | single_input = not isinstance(topk, (tuple, list)) 53 | if single_input: 54 | topk = (topk,) 55 | 56 | maxk = max(topk) 57 | batch_size = target.size(0) 58 | 59 | _, pred = output.topk(maxk, 1, True, True) 60 | pred = pred.t() 61 | correct = pred.eq(target.view(1, -1).expand_as(pred)) 62 | 63 | res = [] 64 | for k in topk: 65 | correct_k = correct[:k].view(-1).float().sum(0, keepdim=True)[0] 66 | res.append(correct_k * 100.0 / batch_size) 67 | 68 | if single_input: 69 | return res[0] 70 | 71 | return res 72 | -------------------------------------------------------------------------------- /lib/train/admin/tensorboard.py: -------------------------------------------------------------------------------- 1 | import os 2 | from collections import OrderedDict 3 | 4 | try: 5 | from torch.utils.tensorboard import SummaryWriter 6 | except: 7 | print('WARNING: You are using tensorboardX instead sis you have a too old pytorch version.') 8 | from tensorboardX import SummaryWriter 9 | 10 | 11 | class TensorboardWriter: 12 | def __init__(self, directory, loader_names): 13 | self.directory = directory 14 | self.writer = OrderedDict({name: SummaryWriter(os.path.join(self.directory, name)) for name in loader_names}) 15 | 16 | def write_info(self, script_name, description): 17 | tb_info_writer = SummaryWriter(os.path.join(self.directory, 'info')) 18 | tb_info_writer.add_text('Script_name', script_name) 19 | tb_info_writer.add_text('Description', description) 20 | tb_info_writer.close() 21 | 22 | def write_epoch(self, stats: OrderedDict, epoch: int, ind=-1): 23 | for loader_name, loader_stats in stats.items(): 24 | if loader_stats is None: 25 | continue 26 | for var_name, val in loader_stats.items(): 27 | if hasattr(val, 'history') and getattr(val, 'has_new_data', True): 28 | self.writer[loader_name].add_scalar(var_name, val.history[ind], epoch) -------------------------------------------------------------------------------- /lib/train/data/__init__.py: -------------------------------------------------------------------------------- 1 | from .loader import LTRLoader 2 | from .image_loader import jpeg4py_loader, opencv_loader, jpeg4py_loader_w_failsafe, default_image_loader 3 | -------------------------------------------------------------------------------- /lib/train/data/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/data/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/data/__pycache__/image_loader.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/data/__pycache__/image_loader.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/data/__pycache__/loader.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/data/__pycache__/loader.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/data/__pycache__/processing.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/data/__pycache__/processing.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/data/__pycache__/processing_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/data/__pycache__/processing_utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/data/__pycache__/sampler.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/data/__pycache__/sampler.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/data/__pycache__/transforms.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/data/__pycache__/transforms.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/data/__pycache__/wandb_logger.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/data/__pycache__/wandb_logger.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/data/bounding_box_utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | def rect_to_rel(bb, sz_norm=None): 5 | """Convert standard rectangular parametrization of the bounding box [x, y, w, h] 6 | to relative parametrization [cx/sw, cy/sh, log(w), log(h)], where [cx, cy] is the center coordinate. 7 | args: 8 | bb - N x 4 tensor of boxes. 9 | sz_norm - [N] x 2 tensor of value of [sw, sh] (optional). sw=w and sh=h if not given. 10 | """ 11 | 12 | c = bb[...,:2] + 0.5 * bb[...,2:] 13 | if sz_norm is None: 14 | c_rel = c / bb[...,2:] 15 | else: 16 | c_rel = c / sz_norm 17 | sz_rel = torch.log(bb[...,2:]) 18 | return torch.cat((c_rel, sz_rel), dim=-1) 19 | 20 | 21 | def rel_to_rect(bb, sz_norm=None): 22 | """Inverts the effect of rect_to_rel. See above.""" 23 | 24 | sz = torch.exp(bb[...,2:]) 25 | if sz_norm is None: 26 | c = bb[...,:2] * sz 27 | else: 28 | c = bb[...,:2] * sz_norm 29 | tl = c - 0.5 * sz 30 | return torch.cat((tl, sz), dim=-1) 31 | 32 | 33 | def masks_to_bboxes(mask, fmt='c'): 34 | 35 | """ Convert a mask tensor to one or more bounding boxes. 36 | Note: This function is a bit new, make sure it does what it says. /Andreas 37 | :param mask: Tensor of masks, shape = (..., H, W) 38 | :param fmt: bbox layout. 'c' => "center + size" or (x_center, y_center, width, height) 39 | 't' => "top left + size" or (x_left, y_top, width, height) 40 | 'v' => "vertices" or (x_left, y_top, x_right, y_bottom) 41 | :return: tensor containing a batch of bounding boxes, shape = (..., 4) 42 | """ 43 | batch_shape = mask.shape[:-2] 44 | mask = mask.reshape((-1, *mask.shape[-2:])) 45 | bboxes = [] 46 | 47 | for m in mask: 48 | mx = m.sum(dim=-2).nonzero() 49 | my = m.sum(dim=-1).nonzero() 50 | bb = [mx.min(), my.min(), mx.max(), my.max()] if (len(mx) > 0 and len(my) > 0) else [0, 0, 0, 0] 51 | bboxes.append(bb) 52 | 53 | bboxes = torch.tensor(bboxes, dtype=torch.float32, device=mask.device) 54 | bboxes = bboxes.reshape(batch_shape + (4,)) 55 | 56 | if fmt == 'v': 57 | return bboxes 58 | 59 | x1 = bboxes[..., :2] 60 | s = bboxes[..., 2:] - x1 + 1 61 | 62 | if fmt == 'c': 63 | return torch.cat((x1 + 0.5 * s, s), dim=-1) 64 | elif fmt == 't': 65 | return torch.cat((x1, s), dim=-1) 66 | 67 | raise ValueError("Undefined bounding box layout '%s'" % fmt) 68 | 69 | 70 | def masks_to_bboxes_multi(mask, ids, fmt='c'): 71 | assert mask.dim() == 2 72 | bboxes = [] 73 | 74 | for id in ids: 75 | mx = (mask == id).sum(dim=-2).nonzero() 76 | my = (mask == id).float().sum(dim=-1).nonzero() 77 | bb = [mx.min(), my.min(), mx.max(), my.max()] if (len(mx) > 0 and len(my) > 0) else [0, 0, 0, 0] 78 | 79 | bb = torch.tensor(bb, dtype=torch.float32, device=mask.device) 80 | 81 | x1 = bb[:2] 82 | s = bb[2:] - x1 + 1 83 | 84 | if fmt == 'v': 85 | pass 86 | elif fmt == 'c': 87 | bb = torch.cat((x1 + 0.5 * s, s), dim=-1) 88 | elif fmt == 't': 89 | bb = torch.cat((x1, s), dim=-1) 90 | else: 91 | raise ValueError("Undefined bounding box layout '%s'" % fmt) 92 | bboxes.append(bb) 93 | 94 | return bboxes 95 | -------------------------------------------------------------------------------- /lib/train/data/image_loader.py: -------------------------------------------------------------------------------- 1 | import jpeg4py 2 | import cv2 as cv 3 | from PIL import Image 4 | import numpy as np 5 | 6 | davis_palette = np.repeat(np.expand_dims(np.arange(0,256), 1), 3, 1).astype(np.uint8) 7 | davis_palette[:22, :] = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0], 8 | [0, 0, 128], [128, 0, 128], [0, 128, 128], [128, 128, 128], 9 | [64, 0, 0], [191, 0, 0], [64, 128, 0], [191, 128, 0], 10 | [64, 0, 128], [191, 0, 128], [64, 128, 128], [191, 128, 128], 11 | [0, 64, 0], [128, 64, 0], [0, 191, 0], [128, 191, 0], 12 | [0, 64, 128], [128, 64, 128]] 13 | 14 | 15 | def default_image_loader(path): 16 | """The default image loader, reads the image from the given path. It first tries to use the jpeg4py_loader, 17 | but reverts to the opencv_loader if the former is not available.""" 18 | if default_image_loader.use_jpeg4py is None: 19 | # Try using jpeg4py 20 | im = jpeg4py_loader(path) 21 | if im is None: 22 | default_image_loader.use_jpeg4py = False 23 | print('Using opencv_loader instead.') 24 | else: 25 | default_image_loader.use_jpeg4py = True 26 | return im 27 | if default_image_loader.use_jpeg4py: 28 | return jpeg4py_loader(path) 29 | return opencv_loader(path) 30 | 31 | default_image_loader.use_jpeg4py = None 32 | 33 | 34 | def jpeg4py_loader(path): 35 | """ Image reading using jpeg4py https://github.com/ajkxyz/jpeg4py""" 36 | try: 37 | return jpeg4py.JPEG(path).decode() 38 | except Exception as e: 39 | print('ERROR: Could not read image "{}"'.format(path)) 40 | print(e) 41 | return None 42 | 43 | 44 | def opencv_loader(path): 45 | """ Read image using opencv's imread function and returns it in rgb format""" 46 | try: 47 | im = cv.imread(path, cv.IMREAD_COLOR) 48 | 49 | # convert to rgb and return 50 | return cv.cvtColor(im, cv.COLOR_BGR2RGB) 51 | except Exception as e: 52 | print('ERROR: Could not read image "{}"'.format(path)) 53 | print(e) 54 | return None 55 | 56 | 57 | def jpeg4py_loader_w_failsafe(path): 58 | """ Image reading using jpeg4py https://github.com/ajkxyz/jpeg4py""" 59 | try: 60 | return jpeg4py.JPEG(path).decode() 61 | except: 62 | try: 63 | im = cv.imread(path, cv.IMREAD_COLOR) 64 | 65 | # convert to rgb and return 66 | return cv.cvtColor(im, cv.COLOR_BGR2RGB) 67 | except Exception as e: 68 | print('ERROR: Could not read image "{}"'.format(path)) 69 | print(e) 70 | return None 71 | 72 | 73 | def opencv_seg_loader(path): 74 | """ Read segmentation annotation using opencv's imread function""" 75 | try: 76 | return cv.imread(path) 77 | except Exception as e: 78 | print('ERROR: Could not read image "{}"'.format(path)) 79 | print(e) 80 | return None 81 | 82 | 83 | def imread_indexed(filename): 84 | """ Load indexed image with given filename. Used to read segmentation annotations.""" 85 | 86 | im = Image.open(filename) 87 | 88 | annotation = np.atleast_3d(im)[...,0] 89 | return annotation 90 | 91 | 92 | def imwrite_indexed(filename, array, color_palette=None): 93 | """ Save indexed image as png. Used to save segmentation annotation.""" 94 | 95 | if color_palette is None: 96 | color_palette = davis_palette 97 | 98 | if np.atleast_3d(array).shape[2] != 1: 99 | raise Exception("Saving indexed PNGs requires 2D array.") 100 | 101 | im = Image.fromarray(array) 102 | im.putpalette(color_palette.ravel()) 103 | im.save(filename, format='PNG') -------------------------------------------------------------------------------- /lib/train/data/wandb_logger.py: -------------------------------------------------------------------------------- 1 | from collections import OrderedDict 2 | 3 | try: 4 | import wandb 5 | except ImportError: 6 | raise ImportError( 7 | 'Please run "pip install wandb" to install wandb') 8 | 9 | 10 | class WandbWriter: 11 | def __init__(self, exp_name, cfg, output_dir, cur_step=0, step_interval=0): 12 | self.wandb = wandb 13 | self.step = cur_step 14 | self.interval = step_interval 15 | wandb.init(project="tracking", name=exp_name, config=cfg, dir=output_dir) 16 | 17 | def write_log(self, stats: OrderedDict, epoch=-1): 18 | self.step += 1 19 | for loader_name, loader_stats in stats.items(): 20 | if loader_stats is None: 21 | continue 22 | 23 | log_dict = {} 24 | for var_name, val in loader_stats.items(): 25 | if hasattr(val, 'avg'): 26 | log_dict.update({loader_name + '/' + var_name: val.avg}) 27 | else: 28 | log_dict.update({loader_name + '/' + var_name: val.val}) 29 | 30 | if epoch >= 0: 31 | log_dict.update({loader_name + '/epoch': epoch}) 32 | 33 | self.wandb.log(log_dict, step=self.step*self.interval) -------------------------------------------------------------------------------- /lib/train/data_specs/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | ## Description for different text files 4 | GOT10K 5 | - got10k_train_full_split.txt: the complete GOT-10K training set. (9335 videos) 6 | - got10k_train_split.txt: part of videos from the GOT-10K training set 7 | - got10k_val_split.txt: another part of videos from the GOT-10K training set 8 | - got10k_vot_exclude.txt: 1k videos that are forbidden from "using to train models then testing on VOT" (as required by [VOT Challenge](https://www.votchallenge.net/vot2020/participation.html)) 9 | - got10k_vot_train_split.txt: part of videos from the "VOT-permitted" GOT-10K training set 10 | - got10k_vot_val_split.txt: another part of videos from the "VOT-permitted" GOT-10K training set 11 | 12 | LaSOT 13 | - lasot_train_split.txt: the complete LaSOT training set 14 | 15 | TrackingNnet 16 | - trackingnet_classmap.txt: The map from the sequence name to the target class for the TrackingNet -------------------------------------------------------------------------------- /lib/train/data_specs/depthtrack_train.txt: -------------------------------------------------------------------------------- 1 | adapter02_indoor 2 | bag03_indoor 3 | bag05_indoor 4 | ball02_indoor 5 | ball03_indoor 6 | ball04_indoor 7 | ball05_indoor 8 | ball07_indoor 9 | ball08_wild 10 | ball09_wild 11 | ball12_wild 12 | ball13_indoor 13 | ball14_wild 14 | ball17_wild 15 | ball19_indoor 16 | ball21_indoor 17 | basket_indoor 18 | beautifullight01_indoor 19 | bike01_wild 20 | bike02_wild 21 | bike03_wild 22 | book01_indoor 23 | book02_indoor 24 | book04_indoor 25 | book05_indoor 26 | book06_indoor 27 | bottle01_indoor 28 | bottle02_indoor 29 | bottle05_indoor 30 | bottle06_indoor 31 | box_indoor 32 | candlecup_indoor 33 | car01_indoor 34 | car02_indoor 35 | cart_indoor 36 | cat02_indoor 37 | cat03_indoor 38 | cat04_indoor 39 | cat05_indoor 40 | chair01_indoor 41 | chair02_indoor 42 | clothes_indoor 43 | colacan01_indoor 44 | colacan02_indoor 45 | colacan04_indoor 46 | container01_indoor 47 | container02_indoor 48 | cube01_indoor 49 | cube04_indoor 50 | cube06_indoor 51 | cup03_indoor 52 | cup05_indoor 53 | cup06_indoor 54 | cup07_indoor 55 | cup08_indoor 56 | cup09_indoor 57 | cup10_indoor 58 | cup11_indoor 59 | cup13_indoor 60 | cup14_indoor 61 | duck01_wild 62 | duck02_wild 63 | duck04_wild 64 | duck05_wild 65 | duck06_wild 66 | dumbbells02_indoor 67 | earphone02_indoor 68 | egg_indoor 69 | file02_indoor 70 | flower01_indoor 71 | flower02_wild 72 | flowerbasket_indoor 73 | ghostmask_indoor 74 | glass02_indoor 75 | glass03_indoor 76 | glass04_indoor 77 | glass05_indoor 78 | guitarbag_indoor 79 | gymring_wild 80 | hand02_indoor 81 | hat01_indoor 82 | hat02_indoor_320 83 | hat03_indoor 84 | hat04_indoor 85 | human01_indoor 86 | human03_wild 87 | human04_wild 88 | human05_wild 89 | human06_indoor 90 | leaves01_wild 91 | leaves02_indoor 92 | leaves03_wild 93 | leaves04_indoor 94 | leaves05_indoor 95 | leaves06_wild 96 | lock01_wild 97 | mac_indoor 98 | milkbottle_indoor 99 | mirror_indoor 100 | mobilephone01_indoor 101 | mobilephone02_indoor 102 | mobilephone04_indoor 103 | mobilephone05_indoor 104 | mobilephone06_indoor 105 | mushroom01_indoor 106 | mushroom02_wild 107 | mushroom03_wild 108 | mushroom04_indoor 109 | mushroom05_indoor 110 | notebook02_indoor 111 | notebook03_indoor 112 | paintbottle_indoor 113 | painting_indoor_320 114 | parkingsign_wild 115 | pigeon03_wild 116 | pigeon06_wild 117 | pigeon07_wild 118 | pine01_indoor 119 | pine02_wild_320 120 | shoes01_indoor 121 | shoes03_indoor 122 | skateboard01_indoor 123 | skateboard02_indoor 124 | speaker_indoor 125 | stand_indoor 126 | suitcase_indoor 127 | swing01_wild 128 | swing02_wild 129 | teacup_indoor 130 | thermos01_indoor 131 | thermos02_indoor 132 | toiletpaper02_indoor 133 | toiletpaper03_indoor 134 | toiletpaper04_indoor 135 | toy01_indoor 136 | toy04_indoor 137 | toy05_indoor 138 | toy06_indoor 139 | toy07_indoor_320 140 | toy08_indoor 141 | toy10_indoor 142 | toydog_indoor 143 | trashbin_indoor 144 | tree_wild 145 | trophy_indoor 146 | ukulele02_indoor 147 | -------------------------------------------------------------------------------- /lib/train/data_specs/depthtrack_val.txt: -------------------------------------------------------------------------------- 1 | toy03_indoor 2 | pigeon05_wild 3 | bottle03_indoor 4 | ball16_indoor 5 | bag04_indoor 6 | flower03_indoor -------------------------------------------------------------------------------- /lib/train/data_specs/lasher_val.txt: -------------------------------------------------------------------------------- 1 | boywalkinginsnow3 2 | leftdrillmasterstanding 3 | leftgirlunderthelamp 4 | girlridesbike 5 | midboyplayingphone 6 | boywithumbrella 7 | manrun 8 | ab_pingpongball 9 | whitecarturnl 10 | girltakemoto 11 | rightgirlatbike 12 | easy_blackboy 13 | man_with_black_clothes2 14 | 7runone 15 | turnblkbike 16 | motobesidescar 17 | bikeafterwhitecar 18 | 2runsix 19 | rightboy_1227 20 | whitesuvcome 21 | AQrightofcomingmotos 22 | 7one 23 | blackman_0115 24 | rightmirrornotshining 25 | AQmanfromdarktrees 26 | bikeboy128 27 | orangegirl 28 | girlturnbike 29 | blackman2 30 | blackcarback 31 | rightof2cupsattached 32 | whitecar2west 33 | hatboy`shead 34 | whitebetweenblackandblue 35 | 2rdcarcome 36 | whitemancome 37 | nearmangotoD 38 | farmanrightwhitesmallhouse 39 | lightmotocoming 40 | boymototakesgirl 41 | leftblackboy 42 | righttallholdball 43 | blackcarcome 44 | twolinefirstone-gai 45 | lowerfoam2throw 46 | Awhitecargo 47 | car2north3 48 | rightfirstboy-ly 49 | girltakingplate 50 | left2ndgreenboy 51 | ab_bolster 52 | 9hatboy 53 | whitecarturn2 54 | midboyblue 55 | basketboywhite 56 | nightmototurn 57 | girlbike 58 | mantoground 59 | pickuptheyellowbook 60 | 8lastone 61 | AQbikeback 62 | girlsquattingbesidesleftbar 63 | blkbikefromnorth 64 | whitecar 65 | Amidredgirl 66 | blackbag 67 | AQblkgirlbike 68 | manwithyellowumbrella 69 | browncar2north 70 | carstop 71 | whiteboywithbag 72 | theleftestrunningboy 73 | girlafterglassdoor2 74 | rightmirrorlikesky 75 | redgirl1497 76 | midboy 77 | folderatlefthand 78 | bikecome 79 | leftfallenchair_inf_white 80 | Agirlrideback 81 | rightgirl 82 | belowrightwhiteboy 83 | moto2north1 84 | truckk 85 | highright2ndboy 86 | girl`sheadoncall 87 | whiteboy 88 | truckwhite 89 | AQgirlbiketurns 90 | left2ndboy 91 | whitegirl2right 92 | rightboywithwhite 93 | girlplayingphone 94 | girlumbrella 95 | truck 96 | manfarbesidespool 97 | dotat43 -------------------------------------------------------------------------------- /lib/train/dataset/__init__.py: -------------------------------------------------------------------------------- 1 | from .lasot import Lasot 2 | from .got10k import Got10k 3 | from .tracking_net import TrackingNet 4 | from .imagenetvid import ImagenetVID 5 | from .coco import MSCOCO 6 | from .coco_seq import MSCOCOSeq 7 | from .got10k_lmdb import Got10k_lmdb 8 | from .lasot_lmdb import Lasot_lmdb 9 | from .imagenetvid_lmdb import ImagenetVID_lmdb 10 | from .coco_seq_lmdb import MSCOCOSeq_lmdb 11 | from .tracking_net_lmdb import TrackingNet_lmdb 12 | # RGBT dataloader 13 | from .lasher import LasHeR 14 | # RGBD dataloader 15 | from .depthtrack import DepthTrack 16 | # Event dataloader 17 | from .visevent import VisEvent -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/COCO_tool.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/COCO_tool.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/base_image_dataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/base_image_dataset.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/base_video_dataset.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/base_video_dataset.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/coco.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/coco.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/coco_seq.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/coco_seq.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/coco_seq_lmdb.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/coco_seq_lmdb.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/depth_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/depth_utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/depthtrack.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/depthtrack.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/got10k.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/got10k.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/got10k_lmdb.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/got10k_lmdb.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/imagenetvid.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/imagenetvid.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/imagenetvid_lmdb.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/imagenetvid_lmdb.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/lasher.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/lasher.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/lasot.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/lasot.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/lasot_lmdb.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/lasot_lmdb.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/tracking_net.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/tracking_net.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/tracking_net_lmdb.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/tracking_net_lmdb.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/__pycache__/visevent.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/__pycache__/visevent.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/dataset/base_image_dataset.py: -------------------------------------------------------------------------------- 1 | import torch.utils.data 2 | from lib.train.data.image_loader import jpeg4py_loader 3 | 4 | 5 | class BaseImageDataset(torch.utils.data.Dataset): 6 | """ Base class for image datasets """ 7 | 8 | def __init__(self, name, root, image_loader=jpeg4py_loader): 9 | """ 10 | args: 11 | root - The root path to the dataset 12 | image_loader (jpeg4py_loader) - The function to read the images. jpeg4py (https://github.com/ajkxyz/jpeg4py) 13 | is used by default. 14 | """ 15 | self.name = name 16 | self.root = root 17 | self.image_loader = image_loader 18 | 19 | self.image_list = [] # Contains the list of sequences. 20 | self.class_list = [] 21 | 22 | def __len__(self): 23 | """ Returns size of the dataset 24 | returns: 25 | int - number of samples in the dataset 26 | """ 27 | return self.get_num_images() 28 | 29 | def __getitem__(self, index): 30 | """ Not to be used! Check get_frames() instead. 31 | """ 32 | return None 33 | 34 | def get_name(self): 35 | """ Name of the dataset 36 | 37 | returns: 38 | string - Name of the dataset 39 | """ 40 | raise NotImplementedError 41 | 42 | def get_num_images(self): 43 | """ Number of sequences in a dataset 44 | 45 | returns: 46 | int - number of sequences in the dataset.""" 47 | return len(self.image_list) 48 | 49 | def has_class_info(self): 50 | return False 51 | 52 | def get_class_name(self, image_id): 53 | return None 54 | 55 | def get_num_classes(self): 56 | return len(self.class_list) 57 | 58 | def get_class_list(self): 59 | return self.class_list 60 | 61 | def get_images_in_class(self, class_name): 62 | raise NotImplementedError 63 | 64 | def has_segmentation_info(self): 65 | return False 66 | 67 | def get_image_info(self, seq_id: object) -> object: 68 | """ Returns information about a particular image, 69 | 70 | args: 71 | seq_id - index of the image 72 | 73 | returns: 74 | Dict 75 | """ 76 | raise NotImplementedError 77 | 78 | def get_image(self, image_id, anno=None): 79 | """ Get a image 80 | 81 | args: 82 | image_id - index of image 83 | anno(None) - The annotation for the sequence (see get_sequence_info). If None, they will be loaded. 84 | 85 | returns: 86 | image - 87 | anno - 88 | dict - A dict containing meta information about the sequence, e.g. class of the target object. 89 | 90 | """ 91 | raise NotImplementedError 92 | 93 | -------------------------------------------------------------------------------- /lib/train/dataset/base_video_dataset.py: -------------------------------------------------------------------------------- 1 | import torch.utils.data 2 | # 2021.1.5 use jpeg4py_loader_w_failsafe as default 3 | from lib.train.data.image_loader import jpeg4py_loader_w_failsafe 4 | 5 | 6 | class BaseVideoDataset(torch.utils.data.Dataset): 7 | """ Base class for video datasets """ 8 | 9 | def __init__(self, name, root, image_loader=jpeg4py_loader_w_failsafe): 10 | """ 11 | args: 12 | root - The root path to the dataset 13 | image_loader (jpeg4py_loader) - The function to read the images. jpeg4py (https://github.com/ajkxyz/jpeg4py) 14 | is used by default. 15 | """ 16 | self.name = name 17 | self.root = root 18 | self.image_loader = image_loader 19 | 20 | self.sequence_list = [] # Contains the list of sequences. 21 | self.class_list = [] 22 | 23 | def __len__(self): 24 | """ Returns size of the dataset 25 | returns: 26 | int - number of samples in the dataset 27 | """ 28 | return self.get_num_sequences() 29 | 30 | def __getitem__(self, index): 31 | """ Not to be used! Check get_frames() instead. 32 | """ 33 | return None 34 | 35 | def is_video_sequence(self): 36 | """ Returns whether the dataset is a video dataset or an image dataset 37 | 38 | returns: 39 | bool - True if a video dataset 40 | """ 41 | return True 42 | 43 | def is_synthetic_video_dataset(self): 44 | """ Returns whether the dataset contains real videos or synthetic 45 | 46 | returns: 47 | bool - True if a video dataset 48 | """ 49 | return False 50 | 51 | def get_name(self): 52 | """ Name of the dataset 53 | 54 | returns: 55 | string - Name of the dataset 56 | """ 57 | raise NotImplementedError 58 | 59 | def get_num_sequences(self): 60 | """ Number of sequences in a dataset 61 | 62 | returns: 63 | int - number of sequences in the dataset.""" 64 | return len(self.sequence_list) 65 | 66 | def has_class_info(self): 67 | return False 68 | 69 | def has_occlusion_info(self): 70 | return False 71 | 72 | def get_num_classes(self): 73 | return len(self.class_list) 74 | 75 | def get_class_list(self): 76 | return self.class_list 77 | 78 | def get_sequences_in_class(self, class_name): 79 | raise NotImplementedError 80 | 81 | def has_segmentation_info(self): 82 | return False 83 | 84 | def get_sequence_info(self, seq_id): 85 | """ Returns information about a particular sequences, 86 | 87 | args: 88 | seq_id - index of the sequence 89 | 90 | returns: 91 | Dict 92 | """ 93 | raise NotImplementedError 94 | 95 | def get_frames(self, seq_id, frame_ids, anno=None): 96 | """ Get a set of frames from a particular sequence 97 | 98 | args: 99 | seq_id - index of sequence 100 | frame_ids - a list of frame numbers 101 | anno(None) - The annotation for the sequence (see get_sequence_info). If None, they will be loaded. 102 | 103 | returns: 104 | list - List of frames corresponding to frame_ids 105 | list - List of dicts for each frame 106 | dict - A dict containing meta information about the sequence, e.g. class of the target object. 107 | 108 | """ 109 | raise NotImplementedError 110 | 111 | -------------------------------------------------------------------------------- /lib/train/dataset/imagenetvid_lmdb.py: -------------------------------------------------------------------------------- 1 | import os 2 | from .base_video_dataset import BaseVideoDataset 3 | from lib.train.data import jpeg4py_loader 4 | import torch 5 | from collections import OrderedDict 6 | from lib.train.admin import env_settings 7 | from lib.utils.lmdb_utils import decode_img, decode_json 8 | 9 | 10 | def get_target_to_image_ratio(seq): 11 | anno = torch.Tensor(seq['anno']) 12 | img_sz = torch.Tensor(seq['image_size']) 13 | return (anno[0, 2:4].prod() / (img_sz.prod())).sqrt() 14 | 15 | 16 | class ImagenetVID_lmdb(BaseVideoDataset): 17 | """ Imagenet VID dataset. 18 | 19 | Publication: 20 | ImageNet Large Scale Visual Recognition Challenge 21 | Olga Russakovsky, Jia Deng, Hao Su, Jonathan Krause, Sanjeev Satheesh, Sean Ma, Zhiheng Huang, Andrej Karpathy, 22 | Aditya Khosla, Michael Bernstein, Alexander C. Berg and Li Fei-Fei 23 | IJCV, 2015 24 | https://arxiv.org/pdf/1409.0575.pdf 25 | 26 | Download the dataset from http://image-net.org/ 27 | """ 28 | def __init__(self, root=None, image_loader=jpeg4py_loader, min_length=0, max_target_area=1): 29 | """ 30 | args: 31 | root - path to the imagenet vid dataset. 32 | image_loader (default_image_loader) - The function to read the images. If installed, 33 | jpeg4py (https://github.com/ajkxyz/jpeg4py) is used by default. Else, 34 | opencv's imread is used. 35 | min_length - Minimum allowed sequence length. 36 | max_target_area - max allowed ratio between target area and image area. Can be used to filter out targets 37 | which cover complete image. 38 | """ 39 | root = env_settings().imagenet_dir if root is None else root 40 | super().__init__("imagenetvid_lmdb", root, image_loader) 41 | 42 | sequence_list_dict = decode_json(root, "cache.json") 43 | self.sequence_list = sequence_list_dict 44 | 45 | # Filter the sequences based on min_length and max_target_area in the first frame 46 | self.sequence_list = [x for x in self.sequence_list if len(x['anno']) >= min_length and 47 | get_target_to_image_ratio(x) < max_target_area] 48 | 49 | def get_name(self): 50 | return 'imagenetvid_lmdb' 51 | 52 | def get_num_sequences(self): 53 | return len(self.sequence_list) 54 | 55 | def get_sequence_info(self, seq_id): 56 | bb_anno = torch.Tensor(self.sequence_list[seq_id]['anno']) 57 | valid = (bb_anno[:, 2] > 0) & (bb_anno[:, 3] > 0) 58 | visible = torch.ByteTensor(self.sequence_list[seq_id]['target_visible']) & valid.byte() 59 | return {'bbox': bb_anno, 'valid': valid, 'visible': visible} 60 | 61 | def _get_frame(self, sequence, frame_id): 62 | set_name = 'ILSVRC2015_VID_train_{:04d}'.format(sequence['set_id']) 63 | vid_name = 'ILSVRC2015_train_{:08d}'.format(sequence['vid_id']) 64 | frame_number = frame_id + sequence['start_frame'] 65 | frame_path = os.path.join('Data', 'VID', 'train', set_name, vid_name, 66 | '{:06d}.JPEG'.format(frame_number)) 67 | return decode_img(self.root, frame_path) 68 | 69 | def get_frames(self, seq_id, frame_ids, anno=None): 70 | sequence = self.sequence_list[seq_id] 71 | 72 | frame_list = [self._get_frame(sequence, f) for f in frame_ids] 73 | 74 | if anno is None: 75 | anno = self.get_sequence_info(seq_id) 76 | 77 | # Create anno dict 78 | anno_frames = {} 79 | for key, value in anno.items(): 80 | anno_frames[key] = [value[f_id, ...].clone() for f_id in frame_ids] 81 | 82 | # added the class info to the meta info 83 | object_meta = OrderedDict({'object_class': sequence['class_name'], 84 | 'motion_class': None, 85 | 'major_class': None, 86 | 'root_class': None, 87 | 'motion_adverb': None}) 88 | 89 | return frame_list, anno_frames, object_meta 90 | 91 | -------------------------------------------------------------------------------- /lib/train/dataset/open_set.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/dataset/open_set.py -------------------------------------------------------------------------------- /lib/train/run_training.py: -------------------------------------------------------------------------------- 1 | import os 2 | os.chdir('/home/zwu/Tracking') 3 | import sys 4 | import argparse 5 | import importlib 6 | import cv2 as cv 7 | import torch.backends.cudnn 8 | import torch.distributed as dist 9 | 10 | import random 11 | import numpy as np 12 | torch.backends.cudnn.benchmark = False 13 | 14 | import _init_paths 15 | import lib.train.admin.settings as ws_settings 16 | import warnings 17 | warnings.filterwarnings("ignore") 18 | 19 | def init_seeds(seed): 20 | random.seed(seed) 21 | np.random.seed(seed) 22 | torch.manual_seed(seed) 23 | torch.cuda.manual_seed(seed) 24 | torch.backends.cudnn.deterministic = True 25 | torch.backends.cudnn.benchmark = False 26 | 27 | 28 | def run_training(script_name, config_name, cudnn_benchmark=True, local_rank=-1, save_dir=None, base_seed=None, 29 | use_lmdb=False, script_name_prv=None, config_name_prv=None, use_wandb=False, 30 | distill=None, script_teacher=None, config_teacher=None): 31 | """Run the train script. 32 | args: 33 | script_name: Name of emperiment in the "experiments/" folder. 34 | config_name: Name of the yaml file in the "experiments/". 35 | cudnn_benchmark: Use cudnn benchmark or not (default is True). 36 | """ 37 | if save_dir is None: 38 | print("save_dir dir is not given. Use the default dir instead.") 39 | # This is needed to avoid strange crashes related to opencv 40 | cv.setNumThreads(0) 41 | 42 | torch.backends.cudnn.benchmark = cudnn_benchmark 43 | 44 | print('script_name: {}.py config_name: {}.yaml'.format(script_name, config_name)) 45 | 46 | '''2021.1.5 set seed for different process''' 47 | if base_seed is not None: 48 | if local_rank != -1: 49 | init_seeds(base_seed + local_rank) 50 | else: 51 | init_seeds(base_seed) 52 | 53 | settings = ws_settings.Settings() 54 | settings.script_name = script_name 55 | settings.config_name = config_name 56 | settings.project_path = 'train/{}/{}'.format(script_name, config_name) #train/untrack/deep_rgbx 57 | if script_name_prv is not None and config_name_prv is not None: 58 | settings.project_path_prv = 'train/{}/{}'.format(script_name_prv, config_name_prv) 59 | settings.local_rank = local_rank 60 | settings.save_dir = os.path.abspath(save_dir) 61 | settings.use_lmdb = use_lmdb 62 | prj_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) 63 | settings.cfg_file = os.path.join(prj_dir, 'experiments/%s/%s.yaml' % (script_name, config_name)) 64 | settings.use_wandb = use_wandb 65 | print('project_path:', settings.project_path) 66 | if distill: 67 | settings.distill = distill 68 | settings.script_teacher = script_teacher 69 | settings.config_teacher = config_teacher 70 | if script_teacher is not None and config_teacher is not None: 71 | settings.project_path_teacher = 'train/{}/{}'.format(script_teacher, config_teacher) 72 | settings.cfg_file_teacher = os.path.join(prj_dir, 'experiments/%s/%s.yaml' % (script_teacher, config_teacher)) 73 | expr_module = importlib.import_module('lib.train.train_script_distill') 74 | print('dis') 75 | else: 76 | expr_module = importlib.import_module('lib.train.train_script') 77 | print('undistill') 78 | expr_func = getattr(expr_module, 'run') 79 | 80 | expr_func(settings) 81 | 82 | 83 | def main(): 84 | parser = argparse.ArgumentParser(description='Run a train scripts in train_settings.') 85 | parser.add_argument('--script', type=str, required=True, help='Name of the train script.') 86 | parser.add_argument('--config', type=str, required=True, help="Name of the config file.") 87 | parser.add_argument('--cudnn_benchmark', type=bool, default=True, help='Set cudnn benchmark on (1) or off (0) (default is on).') 88 | parser.add_argument('--local_rank', default=-1, type=int, help='node rank for distributed training') 89 | parser.add_argument('--save_dir', type=str, help='the directory to save checkpoints and logs') # ./output 90 | parser.add_argument('--seed', type=int, default=0, help='seed for random numbers') 91 | parser.add_argument('--use_lmdb', type=int, choices=[0, 1], default=0) # whether datasets are in lmdb format 92 | parser.add_argument('--script_prv', type=str, default=None, help='Name of the train script of previous model.') 93 | parser.add_argument('--config_prv', type=str, default=None, help="Name of the config file of previous model.") 94 | parser.add_argument('--use_wandb', type=int, choices=[0, 1], default=0) # whether to use wandb 95 | # for knowledge distillation 96 | parser.add_argument('--distill', type=int, choices=[0, 1], default=0) # whether to use knowledge distillation 97 | parser.add_argument('--script_teacher', type=str, help='teacher script name') 98 | parser.add_argument('--config_teacher', type=str, help='teacher yaml configure file name') 99 | 100 | args = parser.parse_args() 101 | 102 | 103 | if args.local_rank != -1: 104 | dist.init_process_group(backend='nccl') 105 | torch.cuda.set_device(args.local_rank) 106 | else: 107 | torch.cuda.set_device(0) 108 | run_training(args.script, args.config, cudnn_benchmark=args.cudnn_benchmark, 109 | local_rank=args.local_rank, save_dir=args.save_dir, base_seed=args.seed, 110 | use_lmdb=args.use_lmdb, script_name_prv=args.script_prv, config_name_prv=args.config_prv, 111 | use_wandb=args.use_wandb, 112 | distill=args.distill, script_teacher=args.script_teacher, config_teacher=args.config_teacher) 113 | 114 | 115 | if __name__ == '__main__': 116 | main() 117 | -------------------------------------------------------------------------------- /lib/train/train_script.py: -------------------------------------------------------------------------------- 1 | import os 2 | # loss function related 3 | from lib.utils.box_ops import giou_loss 4 | from torch.nn.functional import l1_loss 5 | from torch.nn import BCEWithLogitsLoss 6 | # train pipeline related 7 | from lib.train.trainers import LTRTrainer 8 | # distributed training related 9 | from torch.nn.parallel import DistributedDataParallel as DDP 10 | # some more advanced functions 11 | from .base_functions import * 12 | # network related 13 | from lib.models.untrack import build_ostrack 14 | from lib.models.untrack import build_untrack 15 | # forward propagation related 16 | from lib.train.actors import UntrackActor 17 | # for import modules 18 | import importlib 19 | 20 | from ..utils.focal_loss import FocalLoss 21 | 22 | 23 | def run(settings): 24 | settings.description = 'Training script for untrack' 25 | 26 | # update the default configs with config file 27 | if not os.path.exists(settings.cfg_file): 28 | raise ValueError("%s doesn't exist." % settings.cfg_file) 29 | config_module = importlib.import_module("lib.config.%s.config" % settings.script_name) 30 | cfg = config_module.cfg 31 | config_module.update_config_from_file(settings.cfg_file) 32 | if settings.local_rank in [-1, 0]: 33 | print("New configuration is shown below.") 34 | for key in cfg.keys(): 35 | print("%s configuration:" % key, cfg[key]) 36 | print('\n') 37 | 38 | # update settings based on cfg 39 | update_settings(settings, cfg) 40 | 41 | # Record the training log 42 | log_dir = os.path.join(settings.save_dir, 'logs') 43 | if settings.local_rank in [-1, 0]: 44 | if not os.path.exists(log_dir): 45 | os.makedirs(log_dir) 46 | settings.log_file = os.path.join(log_dir, "%s-%s.log" % (settings.script_name, settings.config_name)) 47 | 48 | # Build dataloaders 49 | loader_train, loader_val = build_dataloaders(cfg, settings) 50 | # Create network 51 | if settings.script_name == "untrack": 52 | net = build_untrack(cfg) 53 | else: 54 | raise ValueError("illegal script name") 55 | 56 | # wrap networks to distributed one 57 | net.cuda() 58 | if settings.local_rank != -1: 59 | # net = torch.nn.SyncBatchNorm.convert_sync_batchnorm(net) # add syncBN converter 60 | net = DDP(net, device_ids=[settings.local_rank], find_unused_parameters=True) 61 | settings.device = torch.device("cuda:%d" % settings.local_rank) 62 | else: 63 | settings.device = torch.device("cuda:0") 64 | settings.deep_sup = getattr(cfg.TRAIN, "DEEP_SUPERVISION", False) 65 | settings.distill = getattr(cfg.TRAIN, "DISTILL", False) 66 | settings.distill_loss_type = getattr(cfg.TRAIN, "DISTILL_LOSS_TYPE", "KL") 67 | # Loss functions and Actors 68 | if settings.script_name == "untrack": 69 | # here cls loss and cls weight are not use 70 | focal_loss = FocalLoss() 71 | objective = {'giou': giou_loss, 'l1': l1_loss, 'focal': focal_loss, 'cls': BCEWithLogitsLoss()} 72 | loss_weight = {'giou': cfg.TRAIN.GIOU_WEIGHT, 'l1': cfg.TRAIN.L1_WEIGHT, 'focal': 1., 'cls': 1.0, 'nce': 1.0} 73 | actor = UntrackActor(net=net, objective=objective, loss_weight=loss_weight, settings=settings, cfg=cfg) 74 | else: 75 | raise ValueError("illegal script name") 76 | 77 | # Optimizer, parameters, and learning rates 78 | optimizer, lr_scheduler = get_optimizer_scheduler(net, cfg) 79 | use_amp = getattr(cfg.TRAIN, "AMP", False) 80 | settings.save_epoch_interval = getattr(cfg.TRAIN, "SAVE_EPOCH_INTERVAL", 1) 81 | settings.save_last_n_epoch = getattr(cfg.TRAIN, "SAVE_LAST_N_EPOCH", 1) 82 | 83 | if loader_val is None: 84 | trainer = LTRTrainer(actor, [loader_train], optimizer, settings, lr_scheduler, use_amp=use_amp) 85 | else: 86 | trainer = LTRTrainer(actor, [loader_train, loader_val], optimizer, settings, lr_scheduler, use_amp=use_amp) 87 | 88 | # train process 89 | trainer.train(cfg.TRAIN.EPOCH, load_latest=True, fail_safe=True) 90 | -------------------------------------------------------------------------------- /lib/train/trainers/__init__.py: -------------------------------------------------------------------------------- 1 | from .base_trainer import BaseTrainer 2 | from .ltr_trainer import LTRTrainer 3 | -------------------------------------------------------------------------------- /lib/train/trainers/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/trainers/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/trainers/__pycache__/base_trainer.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/trainers/__pycache__/base_trainer.cpython-37.pyc -------------------------------------------------------------------------------- /lib/train/trainers/__pycache__/ltr_trainer.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/train/trainers/__pycache__/ltr_trainer.cpython-37.pyc -------------------------------------------------------------------------------- /lib/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .tensor import TensorDict, TensorList 2 | -------------------------------------------------------------------------------- /lib/utils/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/utils/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/box_ops.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/utils/__pycache__/box_ops.cpython-37.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/ce_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/utils/__pycache__/ce_utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/focal_loss.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/utils/__pycache__/focal_loss.cpython-37.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/heapmap_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/utils/__pycache__/heapmap_utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/lmdb_utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/utils/__pycache__/lmdb_utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/misc.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/utils/__pycache__/misc.cpython-37.pyc -------------------------------------------------------------------------------- /lib/utils/__pycache__/tensor.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/utils/__pycache__/tensor.cpython-37.pyc -------------------------------------------------------------------------------- /lib/utils/box_ops.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torchvision.ops.boxes import box_area 3 | import numpy as np 4 | 5 | 6 | def box_cxcywh_to_xyxy(x): 7 | x_c, y_c, w, h = x.unbind(-1) 8 | b = [(x_c - 0.5 * w), (y_c - 0.5 * h), 9 | (x_c + 0.5 * w), (y_c + 0.5 * h)] 10 | return torch.stack(b, dim=-1) 11 | 12 | 13 | def box_xywh_to_xyxy(x): 14 | x1, y1, w, h = x.unbind(-1) 15 | b = [x1, y1, x1 + w, y1 + h] 16 | return torch.stack(b, dim=-1) 17 | 18 | 19 | def box_xyxy_to_xywh(x): 20 | x1, y1, x2, y2 = x.unbind(-1) 21 | b = [x1, y1, x2 - x1, y2 - y1] 22 | return torch.stack(b, dim=-1) 23 | 24 | 25 | def box_xyxy_to_cxcywh(x): 26 | x0, y0, x1, y1 = x.unbind(-1) 27 | b = [(x0 + x1) / 2, (y0 + y1) / 2, 28 | (x1 - x0), (y1 - y0)] 29 | return torch.stack(b, dim=-1) 30 | 31 | 32 | # modified from torchvision to also return the union 33 | '''Note that this function only supports shape (N,4)''' 34 | 35 | 36 | def box_iou(boxes1, boxes2): 37 | """ 38 | 39 | :param boxes1: (N, 4) (x1,y1,x2,y2) 40 | :param boxes2: (N, 4) (x1,y1,x2,y2) 41 | :return: 42 | """ 43 | area1 = box_area(boxes1) # (N,) 44 | area2 = box_area(boxes2) # (N,) 45 | 46 | lt = torch.max(boxes1[:, :2], boxes2[:, :2]) # (N,2) 47 | rb = torch.min(boxes1[:, 2:], boxes2[:, 2:]) # (N,2) 48 | 49 | wh = (rb - lt).clamp(min=0) # (N,2) 50 | inter = wh[:, 0] * wh[:, 1] # (N,) 51 | 52 | union = area1 + area2 - inter 53 | 54 | iou = inter / union 55 | return iou, union 56 | 57 | 58 | '''Note that this implementation is different from DETR's''' 59 | 60 | 61 | def generalized_box_iou(boxes1, boxes2): 62 | """ 63 | Generalized IoU from https://giou.stanford.edu/ 64 | 65 | The boxes should be in [x0, y0, x1, y1] format 66 | 67 | boxes1: (N, 4) 68 | boxes2: (N, 4) 69 | """ 70 | # degenerate boxes gives inf / nan results 71 | # so do an early check 72 | # try: 73 | assert (boxes1[:, 2:] >= boxes1[:, :2]).all() 74 | assert (boxes2[:, 2:] >= boxes2[:, :2]).all() 75 | iou, union = box_iou(boxes1, boxes2) # (N,) 76 | 77 | lt = torch.min(boxes1[:, :2], boxes2[:, :2]) 78 | rb = torch.max(boxes1[:, 2:], boxes2[:, 2:]) 79 | 80 | wh = (rb - lt).clamp(min=0) # (N,2) 81 | area = wh[:, 0] * wh[:, 1] # (N,) 82 | 83 | return iou - (area - union) / area, iou 84 | 85 | 86 | def giou_loss(boxes1, boxes2): 87 | """ 88 | 89 | :param boxes1: (N, 4) (x1,y1,x2,y2) 90 | :param boxes2: (N, 4) (x1,y1,x2,y2) 91 | :return: 92 | """ 93 | giou, iou = generalized_box_iou(boxes1, boxes2) 94 | return (1 - giou).mean(), iou 95 | 96 | 97 | def clip_box(box: list, H, W, margin=0): 98 | x1, y1, w, h = box 99 | x2, y2 = x1 + w, y1 + h 100 | x1 = min(max(0, x1), W-margin) 101 | x2 = min(max(margin, x2), W) 102 | y1 = min(max(0, y1), H-margin) 103 | y2 = min(max(margin, y2), H) 104 | w = max(margin, x2-x1) 105 | h = max(margin, y2-y1) 106 | return [x1, y1, w, h] 107 | -------------------------------------------------------------------------------- /lib/utils/ce_utils.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | import torch 4 | import torch.nn.functional as F 5 | 6 | 7 | def generate_bbox_mask(bbox_mask, bbox): 8 | b, h, w = bbox_mask.shape 9 | for i in range(b): 10 | bbox_i = bbox[i].cpu().tolist() 11 | bbox_mask[i, int(bbox_i[1]):int(bbox_i[1] + bbox_i[3] - 1), int(bbox_i[0]):int(bbox_i[0] + bbox_i[2] - 1)] = 1 12 | return bbox_mask 13 | 14 | 15 | def generate_mask_cond(cfg, bs, device, gt_bbox): 16 | template_size = cfg.DATA.TEMPLATE.SIZE 17 | stride = cfg.MODEL.BACKBONE.STRIDE 18 | template_feat_size = template_size // stride 19 | 20 | if cfg.MODEL.BACKBONE.CE_TEMPLATE_RANGE == 'ALL': 21 | box_mask_z = None 22 | elif cfg.MODEL.BACKBONE.CE_TEMPLATE_RANGE == 'CTR_POINT': 23 | if template_feat_size == 8: 24 | index = slice(3, 4) 25 | elif template_feat_size == 12: 26 | index = slice(5, 6) 27 | elif template_feat_size == 7: 28 | index = slice(3, 4) 29 | elif template_feat_size == 14: 30 | index = slice(6, 7) 31 | else: 32 | raise NotImplementedError 33 | box_mask_z = torch.zeros([bs, template_feat_size, template_feat_size], device=device) 34 | box_mask_z[:, index, index] = 1 35 | box_mask_z = box_mask_z.flatten(1).to(torch.bool) 36 | elif cfg.MODEL.BACKBONE.CE_TEMPLATE_RANGE == 'CTR_REC': 37 | # use fixed 4x4 region, 3:5 for 8x8 38 | # use fixed 4x4 region 5:6 for 12x12 39 | if template_feat_size == 8: 40 | index = slice(3, 5) 41 | elif template_feat_size == 12: 42 | index = slice(5, 7) 43 | elif template_feat_size == 7: 44 | index = slice(3, 4) 45 | else: 46 | raise NotImplementedError 47 | box_mask_z = torch.zeros([bs, template_feat_size, template_feat_size], device=device) 48 | box_mask_z[:, index, index] = 1 49 | box_mask_z = box_mask_z.flatten(1).to(torch.bool) 50 | 51 | elif cfg.MODEL.BACKBONE.CE_TEMPLATE_RANGE == 'GT_BOX': 52 | box_mask_z = torch.zeros([bs, template_size, template_size], device=device) 53 | # box_mask_z_ori = data['template_seg'][0].view(-1, 1, *data['template_seg'].shape[2:]) # (batch, 1, 128, 128) 54 | box_mask_z = generate_bbox_mask(box_mask_z, gt_bbox * template_size).unsqueeze(1).to( 55 | torch.float) # (batch, 1, 128, 128) 56 | # box_mask_z_vis = box_mask_z.cpu().numpy() 57 | box_mask_z = F.interpolate(box_mask_z, scale_factor=1. / cfg.MODEL.BACKBONE.STRIDE, mode='bilinear', 58 | align_corners=False) 59 | box_mask_z = box_mask_z.flatten(1).to(torch.bool) 60 | # box_mask_z_vis = box_mask_z[:, 0, ...].cpu().numpy() 61 | # gaussian_maps_vis = generate_heatmap(data['template_anno'], self.cfg.DATA.TEMPLATE.SIZE, self.cfg.MODEL.STRIDE)[0].cpu().numpy() 62 | else: 63 | raise NotImplementedError 64 | 65 | return box_mask_z 66 | 67 | 68 | def adjust_keep_rate(epoch, warmup_epochs, total_epochs, ITERS_PER_EPOCH, base_keep_rate=0.5, max_keep_rate=1, iters=-1): 69 | if epoch < warmup_epochs: 70 | return 1 71 | if epoch >= total_epochs: 72 | return base_keep_rate 73 | if iters == -1: 74 | iters = epoch * ITERS_PER_EPOCH 75 | total_iters = ITERS_PER_EPOCH * (total_epochs - warmup_epochs) 76 | iters = iters - ITERS_PER_EPOCH * warmup_epochs 77 | keep_rate = base_keep_rate + (max_keep_rate - base_keep_rate) \ 78 | * (math.cos(iters / total_iters * math.pi) + 1) * 0.5 79 | 80 | return keep_rate 81 | -------------------------------------------------------------------------------- /lib/utils/focal_loss.py: -------------------------------------------------------------------------------- 1 | from abc import ABC 2 | 3 | import torch 4 | import torch.nn as nn 5 | import torch.nn.functional as F 6 | 7 | 8 | class FocalLoss(nn.Module, ABC): 9 | def __init__(self, alpha=2, beta=4): 10 | super(FocalLoss, self).__init__() 11 | self.alpha = alpha 12 | self.beta = beta 13 | 14 | def forward(self, prediction, target): 15 | positive_index = target.eq(1).float() 16 | negative_index = target.lt(1).float() 17 | 18 | negative_weights = torch.pow(1 - target, self.beta) 19 | # clamp min value is set to 1e-12 to maintain the numerical stability 20 | prediction = torch.clamp(prediction, 1e-12) 21 | 22 | positive_loss = torch.log(prediction) * torch.pow(1 - prediction, self.alpha) * positive_index 23 | negative_loss = torch.log(1 - prediction) * torch.pow(prediction, 24 | self.alpha) * negative_weights * negative_index 25 | 26 | num_positive = positive_index.float().sum() 27 | positive_loss = positive_loss.sum() 28 | negative_loss = negative_loss.sum() 29 | 30 | if num_positive == 0: 31 | loss = -negative_loss 32 | else: 33 | loss = -(positive_loss + negative_loss) / num_positive 34 | 35 | return loss 36 | 37 | 38 | class LBHinge(nn.Module): 39 | """Loss that uses a 'hinge' on the lower bound. 40 | This means that for samples with a label value smaller than the threshold, the loss is zero if the prediction is 41 | also smaller than that threshold. 42 | args: 43 | error_matric: What base loss to use (MSE by default). 44 | threshold: Threshold to use for the hinge. 45 | clip: Clip the loss if it is above this value. 46 | """ 47 | def __init__(self, error_metric=nn.MSELoss(), threshold=None, clip=None): 48 | super().__init__() 49 | self.error_metric = error_metric 50 | self.threshold = threshold if threshold is not None else -100 51 | self.clip = clip 52 | 53 | def forward(self, prediction, label, target_bb=None): 54 | negative_mask = (label < self.threshold).float() 55 | positive_mask = (1.0 - negative_mask) 56 | 57 | prediction = negative_mask * F.relu(prediction) + positive_mask * prediction 58 | 59 | loss = self.error_metric(prediction, positive_mask * label) 60 | 61 | if self.clip is not None: 62 | loss = torch.min(loss, torch.tensor([self.clip], device=loss.device)) 63 | return loss -------------------------------------------------------------------------------- /lib/utils/lmdb_utils.py: -------------------------------------------------------------------------------- 1 | import lmdb 2 | import numpy as np 3 | import cv2 4 | import json 5 | 6 | LMDB_ENVS = dict() 7 | LMDB_HANDLES = dict() 8 | LMDB_FILELISTS = dict() 9 | 10 | 11 | def get_lmdb_handle(name): 12 | global LMDB_HANDLES, LMDB_FILELISTS 13 | item = LMDB_HANDLES.get(name, None) 14 | if item is None: 15 | env = lmdb.open(name, readonly=True, lock=False, readahead=False, meminit=False) 16 | LMDB_ENVS[name] = env 17 | item = env.begin(write=False) 18 | LMDB_HANDLES[name] = item 19 | 20 | return item 21 | 22 | 23 | def decode_img(lmdb_fname, key_name): 24 | handle = get_lmdb_handle(lmdb_fname) 25 | binfile = handle.get(key_name.encode()) 26 | if binfile is None: 27 | print("Illegal data detected. %s %s" % (lmdb_fname, key_name)) 28 | s = np.frombuffer(binfile, np.uint8) 29 | x = cv2.cvtColor(cv2.imdecode(s, cv2.IMREAD_COLOR), cv2.COLOR_BGR2RGB) 30 | return x 31 | 32 | 33 | def decode_str(lmdb_fname, key_name): 34 | handle = get_lmdb_handle(lmdb_fname) 35 | binfile = handle.get(key_name.encode()) 36 | string = binfile.decode() 37 | return string 38 | 39 | 40 | def decode_json(lmdb_fname, key_name): 41 | return json.loads(decode_str(lmdb_fname, key_name)) 42 | 43 | 44 | if __name__ == "__main__": 45 | lmdb_fname = "/data/sda/v-yanbi/iccv21/LittleBoy_clean/data/got10k_lmdb" 46 | '''Decode image''' 47 | # key_name = "test/GOT-10k_Test_000001/00000001.jpg" 48 | # img = decode_img(lmdb_fname, key_name) 49 | # cv2.imwrite("001.jpg", img) 50 | '''Decode str''' 51 | # key_name = "test/list.txt" 52 | # key_name = "train/GOT-10k_Train_000001/groundtruth.txt" 53 | key_name = "train/GOT-10k_Train_000001/absence.label" 54 | str_ = decode_str(lmdb_fname, key_name) 55 | print(str_) 56 | -------------------------------------------------------------------------------- /lib/utils/merge.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | def merge_template_search(inp_list, return_search=False, return_template=False): 5 | """NOTICE: search region related features must be in the last place""" 6 | seq_dict = {"feat": torch.cat([x["feat"] for x in inp_list], dim=0), 7 | "mask": torch.cat([x["mask"] for x in inp_list], dim=1), 8 | "pos": torch.cat([x["pos"] for x in inp_list], dim=0)} 9 | if return_search: 10 | x = inp_list[-1] 11 | seq_dict.update({"feat_x": x["feat"], "mask_x": x["mask"], "pos_x": x["pos"]}) 12 | if return_template: 13 | z = inp_list[0] 14 | seq_dict.update({"feat_z": z["feat"], "mask_z": z["mask"], "pos_z": z["pos"]}) 15 | return seq_dict 16 | 17 | 18 | def get_qkv(inp_list): 19 | """The 1st element of the inp_list is about the template, 20 | the 2nd (the last) element is about the search region""" 21 | dict_x = inp_list[-1] 22 | dict_c = {"feat": torch.cat([x["feat"] for x in inp_list], dim=0), 23 | "mask": torch.cat([x["mask"] for x in inp_list], dim=1), 24 | "pos": torch.cat([x["pos"] for x in inp_list], dim=0)} # concatenated dict 25 | q = dict_x["feat"] + dict_x["pos"] 26 | k = dict_c["feat"] + dict_c["pos"] 27 | v = dict_c["feat"] 28 | key_padding_mask = dict_c["mask"] 29 | return q, k, v, key_padding_mask 30 | -------------------------------------------------------------------------------- /lib/vis/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/vis/__init__.py -------------------------------------------------------------------------------- /lib/vis/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/vis/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /lib/vis/__pycache__/plotting.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/vis/__pycache__/plotting.cpython-37.pyc -------------------------------------------------------------------------------- /lib/vis/__pycache__/utils.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/vis/__pycache__/utils.cpython-37.pyc -------------------------------------------------------------------------------- /lib/vis/__pycache__/visdom_cus.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/lib/vis/__pycache__/visdom_cus.cpython-37.pyc -------------------------------------------------------------------------------- /lib/vis/plotting.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | import torch 4 | import cv2 5 | 6 | 7 | def draw_figure(fig): 8 | fig.canvas.draw() 9 | fig.canvas.flush_events() 10 | plt.pause(0.001) 11 | 12 | 13 | def show_tensor(a: torch.Tensor, fig_num = None, title = None, range=(None, None), ax=None): 14 | """Display a 2D tensor. 15 | args: 16 | fig_num: Figure number. 17 | title: Title of figure. 18 | """ 19 | a_np = a.squeeze().cpu().clone().detach().numpy() 20 | if a_np.ndim == 3: 21 | a_np = np.transpose(a_np, (1, 2, 0)) 22 | 23 | if ax is None: 24 | fig = plt.figure(fig_num) 25 | plt.tight_layout() 26 | plt.cla() 27 | plt.imshow(a_np, vmin=range[0], vmax=range[1]) 28 | plt.axis('off') 29 | plt.axis('equal') 30 | if title is not None: 31 | plt.title(title) 32 | draw_figure(fig) 33 | else: 34 | ax.cla() 35 | ax.imshow(a_np, vmin=range[0], vmax=range[1]) 36 | ax.set_axis_off() 37 | ax.axis('equal') 38 | if title is not None: 39 | ax.set_title(title) 40 | draw_figure(plt.gcf()) 41 | 42 | 43 | def plot_graph(a: torch.Tensor, fig_num = None, title = None): 44 | """Plot graph. Data is a 1D tensor. 45 | args: 46 | fig_num: Figure number. 47 | title: Title of figure. 48 | """ 49 | a_np = a.squeeze().cpu().clone().detach().numpy() 50 | if a_np.ndim > 1: 51 | raise ValueError 52 | fig = plt.figure(fig_num) 53 | # plt.tight_layout() 54 | plt.cla() 55 | plt.plot(a_np) 56 | if title is not None: 57 | plt.title(title) 58 | draw_figure(fig) 59 | 60 | 61 | def show_image_with_boxes(im, boxes, iou_pred=None, disp_ids=None): 62 | im_np = im.clone().cpu().squeeze().numpy() 63 | im_np = np.ascontiguousarray(im_np.transpose(1, 2, 0).astype(np.uint8)) 64 | 65 | boxes = boxes.view(-1, 4).cpu().numpy().round().astype(int) 66 | 67 | # Draw proposals 68 | for i_ in range(boxes.shape[0]): 69 | if disp_ids is None or disp_ids[i_]: 70 | bb = boxes[i_, :] 71 | disp_color = (i_*38 % 256, (255 - i_*97) % 256, (123 + i_*66) % 256) 72 | cv2.rectangle(im_np, (bb[0], bb[1]), (bb[0] + bb[2], bb[1] + bb[3]), 73 | disp_color, 1) 74 | 75 | if iou_pred is not None: 76 | text_pos = (bb[0], bb[1] - 5) 77 | cv2.putText(im_np, 'ID={} IOU = {:3.2f}'.format(i_, iou_pred[i_]), text_pos, 78 | cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1, bottomLeftOrigin=False) 79 | 80 | im_tensor = torch.from_numpy(im_np.transpose(2, 0, 1)).float() 81 | 82 | return im_tensor 83 | 84 | 85 | 86 | def _pascal_color_map(N=256, normalized=False): 87 | """ 88 | Python implementation of the color map function for the PASCAL VOC data set. 89 | Official Matlab version can be found in the PASCAL VOC devkit 90 | http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html#devkit 91 | """ 92 | 93 | def bitget(byteval, idx): 94 | return (byteval & (1 << idx)) != 0 95 | 96 | dtype = 'float32' if normalized else 'uint8' 97 | cmap = np.zeros((N, 3), dtype=dtype) 98 | for i in range(N): 99 | r = g = b = 0 100 | c = i 101 | for j in range(8): 102 | r = r | (bitget(c, 0) << 7 - j) 103 | g = g | (bitget(c, 1) << 7 - j) 104 | b = b | (bitget(c, 2) << 7 - j) 105 | c = c >> 3 106 | 107 | cmap[i] = np.array([r, g, b]) 108 | 109 | cmap = cmap / 255 if normalized else cmap 110 | return cmap 111 | 112 | 113 | def overlay_mask(im, ann, alpha=0.5, colors=None, contour_thickness=None): 114 | """ Overlay mask over image. 115 | Source: https://github.com/albertomontesg/davis-interactive/blob/master/davisinteractive/utils/visualization.py 116 | This function allows you to overlay a mask over an image with some 117 | transparency. 118 | # Arguments 119 | im: Numpy Array. Array with the image. The shape must be (H, W, 3) and 120 | the pixels must be represented as `np.uint8` data type. 121 | ann: Numpy Array. Array with the mask. The shape must be (H, W) and the 122 | values must be intergers 123 | alpha: Float. Proportion of alpha to apply at the overlaid mask. 124 | colors: Numpy Array. Optional custom colormap. It must have shape (N, 3) 125 | being N the maximum number of colors to represent. 126 | contour_thickness: Integer. Thickness of each object index contour draw 127 | over the overlay. This function requires to have installed the 128 | package `opencv-python`. 129 | # Returns 130 | Numpy Array: Image of the overlay with shape (H, W, 3) and data type 131 | `np.uint8`. 132 | """ 133 | im, ann = np.asarray(im, dtype=np.uint8), np.asarray(ann, dtype=np.int) 134 | if im.shape[:-1] != ann.shape: 135 | raise ValueError('First two dimensions of `im` and `ann` must match') 136 | if im.shape[-1] != 3: 137 | raise ValueError('im must have three channels at the 3 dimension') 138 | 139 | colors = colors or _pascal_color_map() 140 | colors = np.asarray(colors, dtype=np.uint8) 141 | 142 | mask = colors[ann] 143 | fg = im * alpha + (1 - alpha) * mask 144 | 145 | img = im.copy() 146 | img[ann > 0] = fg[ann > 0] 147 | 148 | if contour_thickness: # pragma: no cover 149 | import cv2 150 | for obj_id in np.unique(ann[ann > 0]): 151 | contours = cv2.findContours((ann == obj_id).astype( 152 | np.uint8), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)[-2:] 153 | cv2.drawContours(img, contours[0], -1, colors[obj_id].tolist(), 154 | contour_thickness) 155 | return img 156 | -------------------------------------------------------------------------------- /lib/vis/utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import numpy as np 3 | 4 | 5 | def numpy_to_torch(a: np.ndarray): 6 | return torch.from_numpy(a).float().permute(2, 0, 1).unsqueeze(0) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | absl-py==1.4.0 2 | appdirs==1.4.4 3 | attributee==0.1.8 4 | attrs==23.1.0 5 | bidict==0.22.1 6 | brotlipy==0.7.0 7 | cachetools==5.3.1 8 | certifi @ file:///croot/certifi_1671487769961/work/certifi 9 | cffi @ file:///croot/cffi_1670423208954/work 10 | chardet @ file:///tmp/build/80754af9/chardet_1607706768982/work 11 | charset-normalizer==3.2.0 12 | click==8.1.7 13 | colorama==0.4.6 14 | cryptography @ file:///croot/cryptography_1677533068310/work 15 | cycler==0.11.0 16 | Cython==3.0.0 17 | dataclasses==0.6 18 | docker-pycreds==0.4.0 19 | dominate==2.8.0 20 | easydict==1.10 21 | fonttools==4.38.0 22 | future==0.18.3 23 | gitdb==4.0.10 24 | GitPython==3.1.32 25 | google-auth==2.22.0 26 | google-auth-oauthlib==0.4.6 27 | grpcio==1.56.2 28 | idna @ file:///croot/idna_1666125576474/work 29 | importlib-metadata==6.7.0 30 | importlib-resources==5.12.0 31 | info-nce-pytorch==0.1.4 32 | install==1.3.5 33 | jpeg4py==0.1.4 34 | jsonpatch==1.33 35 | jsonpointer==2.4 36 | jsonschema==4.17.3 37 | kiwisolver==1.4.4 38 | lazy-object-proxy==1.9.0 39 | llvmlite==0.39.1 40 | lmdb==1.4.1 41 | Markdown==3.4.3 42 | MarkupSafe==2.1.3 43 | matplotlib==3.5.3 44 | mkl-fft==1.3.1 45 | mkl-random @ file:///tmp/build/80754af9/mkl_random_1626179032232/work 46 | mkl-service==2.4.0 47 | networkx==2.6.3 48 | numba==0.56.4 49 | numpy @ file:///opt/conda/conda-bld/numpy_and_numpy_base_1653915516269/work 50 | oauthlib==3.2.2 51 | opencv-python==4.8.0.74 52 | ordered-set==4.1.0 53 | packaging==23.1 54 | pandas==1.3.5 55 | pathtools==0.1.2 56 | phx-class-registry==4.0.6 57 | Pillow==9.4.0 58 | pkgutil_resolve_name==1.3.10 59 | protobuf==3.20.3 60 | psutil==5.9.5 61 | pyasn1==0.5.0 62 | pyasn1-modules==0.3.0 63 | pycocotools==2.0.6 64 | pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work 65 | PyLaTeX==1.4.1 66 | pyOpenSSL @ file:///croot/pyopenssl_1677607685877/work 67 | pyparsing==3.1.0 68 | pyrsistent==0.19.3 69 | PySocks @ file:///tmp/build/80754af9/pysocks_1594394576006/work 70 | python-dateutil==2.8.2 71 | pytz==2023.3 72 | PyYAML==6.0.1 73 | requests==2.31.0 74 | requests-oauthlib==1.3.1 75 | rsa==4.9 76 | scipy==1.7.3 77 | sentry-sdk==1.30.0 78 | setproctitle==1.3.2 79 | six @ file:///tmp/build/80754af9/six_1644875935023/work 80 | smmap==5.0.0 81 | tb-nightly==2.12.0a20230113 82 | tensorboard-data-server==0.6.1 83 | tensorboard-plugin-wit==1.8.1 84 | tensorly==0.8.1 85 | timm==0.5.4 86 | torch==1.13.1 87 | torchaudio==0.13.1 88 | torchvision==0.14.1 89 | tornado==6.2 90 | tqdm @ file:///opt/conda/conda-bld/tqdm_1664392687731/work 91 | typing_extensions @ file:///tmp/abs_ben9emwtky/croots/recipe/typing_extensions_1659638822008/work 92 | urllib3==1.26.16 93 | visdom==0.2.4 94 | vot-toolkit==0.5.3 95 | vot-trax==3.0.2 96 | wandb==0.15.9 97 | websocket-client==1.6.1 98 | Werkzeug==2.2.3 99 | zipp==3.15.0 100 | -------------------------------------------------------------------------------- /tracking/__pycache__/_init_paths.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zongwei97/UnTrack/8eec76ec912c19e326e2b0020444f8f20c7d4355/tracking/__pycache__/_init_paths.cpython-37.pyc -------------------------------------------------------------------------------- /tracking/_init_paths.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | from __future__ import division 3 | from __future__ import print_function 4 | 5 | import os.path as osp 6 | import sys 7 | 8 | 9 | def add_path(path): 10 | if path not in sys.path: 11 | sys.path.insert(0, path) 12 | 13 | 14 | this_dir = osp.dirname(__file__) 15 | 16 | prj_path = osp.join(this_dir, '..') 17 | add_path(prj_path) 18 | -------------------------------------------------------------------------------- /tracking/create_default_local_file.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | import _init_paths 4 | from lib.train.admin import create_default_local_file_train 5 | from lib.test.evaluation import create_default_local_file_test 6 | 7 | 8 | def parse_args(): 9 | parser = argparse.ArgumentParser(description='Create default local file on ITP or PAI') 10 | parser.add_argument("--workspace_dir", type=str, required=True) 11 | parser.add_argument("--data_dir", type=str, required=True) 12 | parser.add_argument("--save_dir", type=str, required=True) 13 | args = parser.parse_args() 14 | return args 15 | 16 | 17 | if __name__ == "__main__": 18 | args = parse_args() 19 | workspace_dir = os.path.realpath(args.workspace_dir) 20 | data_dir = os.path.realpath(args.data_dir) 21 | save_dir = os.path.realpath(args.save_dir) 22 | create_default_local_file_train(workspace_dir, data_dir) 23 | create_default_local_file_test(workspace_dir, data_dir, save_dir) 24 | -------------------------------------------------------------------------------- /tracking/test.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import argparse 4 | 5 | prj_path = os.path.join(os.path.dirname(__file__), '..') 6 | if prj_path not in sys.path: 7 | sys.path.append(prj_path) 8 | 9 | from lib.test.evaluation import get_dataset 10 | from lib.test.evaluation.running import run_dataset 11 | from lib.test.evaluation.tracker import Tracker 12 | 13 | 14 | def run_tracker(tracker_name, tracker_param, run_id=None, dataset_name='otb', sequence=None, debug=0, threads=0, 15 | num_gpus=8): 16 | """Run tracker on sequence or dataset. 17 | args: 18 | tracker_name: Name of tracking method. 19 | tracker_param: Name of parameter file. 20 | run_id: The run id. 21 | dataset_name: Name of dataset (otb, nfs, uav, tpl, vot, tn, gott, gotv, lasot). 22 | sequence: Sequence number or name. 23 | debug: Debug level. 24 | threads: Number of threads. 25 | """ 26 | 27 | dataset = get_dataset(dataset_name) 28 | 29 | if sequence is not None: 30 | dataset = [dataset[sequence]] 31 | 32 | trackers = [Tracker(tracker_name, tracker_param, dataset_name, run_id)] 33 | 34 | run_dataset(dataset, trackers, debug, threads, num_gpus=num_gpus) 35 | 36 | 37 | def main(): 38 | parser = argparse.ArgumentParser(description='Run tracker on sequence or dataset.') 39 | parser.add_argument('tracker_name', type=str, help='Name of tracking method.') 40 | parser.add_argument('tracker_param', type=str, help='Name of config file.') 41 | parser.add_argument('--runid', type=int, default=None, help='The run id.') 42 | parser.add_argument('--dataset_name', type=str, default='otb', help='Name of dataset (otb, nfs, uav, tpl, vot, tn, gott, gotv, lasot).') 43 | parser.add_argument('--sequence', type=str, default=None, help='Sequence number or name.') 44 | parser.add_argument('--debug', type=int, default=0, help='Debug level.') 45 | parser.add_argument('--threads', type=int, default=1, help='Number of threads.') 46 | parser.add_argument('--num_gpus', type=int, default=1) 47 | 48 | args = parser.parse_args() 49 | 50 | try: 51 | seq_name = int(args.sequence) 52 | except: 53 | seq_name = args.sequence 54 | 55 | run_tracker(args.tracker_name, args.tracker_param, args.runid, args.dataset_name, seq_name, args.debug, 56 | args.threads, num_gpus=args.num_gpus) 57 | 58 | 59 | if __name__ == '__main__': 60 | main() -------------------------------------------------------------------------------- /tracking/train.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | import random 4 | import torch 5 | 6 | 7 | def parse_args(): 8 | """ 9 | args for training. --script untrack --config deep_rgbx --save_dir ./output_x --mode multiple 10 | """ 11 | parser = argparse.ArgumentParser(description='Parse args for training') 12 | # for train 13 | parser.add_argument('--script', type=str, default='untrack', help='training script name') 14 | parser.add_argument('--config', type=str, default='deep_rgbx', help='yaml configure file name') 15 | parser.add_argument('--save_dir', type=str, default='./output_x', help='root directory to save checkpoints, logs, and tensorboard') 16 | parser.add_argument('--mode', type=str, choices=["single", "multiple", "multi_node"], default="multiple", 17 | help="train on single gpu or multiple gpus") 18 | parser.add_argument('--nproc_per_node', type=int, default=torch.cuda.device_count(), help="number of GPUs per node") # specify when mode is multiple 19 | parser.add_argument('--use_lmdb', type=int, choices=[0, 1], default=0) # whether datasets are in lmdb format 20 | parser.add_argument('--script_prv', type=str, help='training script name') 21 | parser.add_argument('--config_prv', type=str, default='baseline', help='yaml configure file name') 22 | parser.add_argument('--use_wandb', type=int, choices=[0, 1], default=1) # whether to use wandb 23 | # for knowledge distillation 24 | parser.add_argument('--distill', type=int, choices=[0, 1], default=0) # whether to use knowledge distillation 25 | parser.add_argument('--script_teacher', type=str, help='teacher script name') 26 | parser.add_argument('--config_teacher', type=str, help='teacher yaml configure file name') 27 | 28 | # for multiple machines 29 | parser.add_argument('--rank', type=int, help='Rank of the current process.') 30 | parser.add_argument('--world-size', type=int, help='Number of processes participating in the job.') 31 | parser.add_argument('--ip', type=str, default='127.0.0.1', help='IP of the current rank 0.') 32 | parser.add_argument('--port', type=int, default='20000', help='Port of the current rank 0.') 33 | 34 | args = parser.parse_args() 35 | 36 | return args 37 | 38 | 39 | def main(): 40 | args = parse_args() 41 | print('args.config ', args.config) 42 | if args.mode == "single": 43 | train_cmd = "python lib/train/run_training.py --script %s --config %s --save_dir %s --use_lmdb %d " \ 44 | "--script_prv %s --config_prv %s --distill %d --script_teacher %s --config_teacher %s --use_wandb %d"\ 45 | % (args.script, args.config, args.save_dir, args.use_lmdb, args.script_prv, args.config_prv, 46 | args.distill, args.script_teacher, args.config_teacher, args.use_wandb) 47 | # elif args.mode == "multiple": 48 | # train_cmd = "python -m torch.distributed.launch --nproc_per_node %d --master_port %d lib/train/run_training.py " \ 49 | # "--script %s --config %s --save_dir %s --use_lmdb %d --script_prv %s --config_prv %s --use_wandb %d " \ 50 | # "--distill %d --script_teacher %s --config_teacher %s" \ 51 | # % (args.nproc_per_node, random.randint(10000, 50000), args.script, args.config, args.save_dir, args.use_lmdb, args.script_prv, args.config_prv, args.use_wandb, 52 | # args.distill, args.script_teacher, args.config_teacher) 53 | elif args.mode == "multiple": 54 | train_cmd = "python /home/zwu/Tracking/lib/train/run_training.py " \ 55 | "--script %s --config %s --save_dir %s --use_lmdb %d --script_prv %s --config_prv %s --use_wandb %d " \ 56 | "--distill %d --script_teacher %s --config_teacher %s" \ 57 | % (args.script, args.config, args.save_dir, args.use_lmdb, args.script_prv, args.config_prv, args.use_wandb, 58 | args.distill, args.script_teacher, args.config_teacher) 59 | elif args.mode == "multi_node": 60 | train_cmd = "python -m torch.distributed.launch --nproc_per_node %d --master_addr %s --master_port %d --nnodes %d --node_rank %d lib/train/run_training.py " \ 61 | "--script %s --config %s --save_dir %s --use_lmdb %d --script_prv %s --config_prv %s --use_wandb %d " \ 62 | "--distill %d --script_teacher %s --config_teacher %s" \ 63 | % (args.nproc_per_node, args.ip, args.port, args.world_size, args.rank, args.script, args.config, args.save_dir, args.use_lmdb, args.script_prv, args.config_prv, args.use_wandb, 64 | args.distill, args.script_teacher, args.config_teacher) 65 | else: 66 | raise ValueError("mode should be 'single' or 'multiple' or 'multi_node'.") 67 | os.system(train_cmd) 68 | 69 | 70 | if __name__ == "__main__": 71 | main() 72 | -------------------------------------------------------------------------------- /train.sh: -------------------------------------------------------------------------------- 1 | # Training UnTrack 2 | python tracking/train.py --script untrack --config deep_rgbx --save_dir ./output_x --mode single 3 | --------------------------------------------------------------------------------