pytracking 是基于 PyTorch 的视觉目标跟踪算法官方实现。其包括 ToMP (CVPR 2022), KeepTrack (ICCV 2021), LWL (ECCV 2020), KYS (ECCV 2020), PrDiMP (CVPR 2020), DiMP (ICCV 2019), and ATOM (CVPR 2019) 跟踪器,包含这些算法的完整的训练代码和训练模型。本篇记录 pytracking 代码测试运行的经过,包括代码下载、环境配置、模型测试等。以 Ubuntu18.04、miniconda 为例演示。

代码下载

直接访问 github 网址:GitHub - visionml/pytracking: Visual tracking library based on PyTorch.

首先,克隆 pytracking 源码下载到本地,本篇为了方便把工程放到用户目录下

1
2
cd
git clone https://github.com/visionml/pytracking.git

然后,克隆子模块到本地

1
2
cd ~/pytracking
git submodule update --init

安装依赖配置环境

假设 nvidia drivers、cuda-toolkit、cudnn 均已经安装好,我这里各版本信息如下:

1
2
# cuda 编译器工具的版本,即 cuda runtime 版本
nvcc -V
1
2
3
4
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89
1
2
3
# cuda 驱动版本,即 driver api
# driver api 的版本能向下兼容 runtime api 的版本。因此,当 nvidia-smi 显示的 cuda 版本大于 nvcc -V 显示的 cuda 版本时一般是没有问题的,但是反过来小于就不行。
nvidia-smi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Fri Jul  8 08:49:38 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.33.01 Driver Version: 440.33.01 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 Tesla V100-PCIE... Off | 00000000:3B:00.0 Off | 0 |
| N/A 29C P0 34W / 250W | 0MiB / 32510MiB | 0% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+

GPU 环境一切正常,接下来开始配置 pytracking 的 Python 其他运行环境。

创建 conda 虚拟环境

1
2
conda create -n pytracking python=3.7.0
conda activate pytracking

安装依赖包

1
2
3
4
5
6
7
8
pip install "matplotlib==3.5.2" "pandas==1.1.5" "tqdm==4.64.0" "opencv-python==4.6.0.66" 
pip install "visdom==0.1.8.9" "tb-nightly==2.10.0a20220707" "scikit-image==0.19.3"
pip install "tikzplotlib==0.10.1" "gdown==4.5.1" "pycocotools==2.0.4" "Cython==0.29.30" "lvis==0.5.3" "Pillow==9.0.1"
sudo apt update
sudo apt install ninja-build
pip install jpeg4py
# 注意 pytracking/libs/fourier.py 中的快速傅里叶变换是采用旧版本,因此,pytorch 版本不能高于 1.7.1
conda install pytorch==1.7.1 torchvision cudatoolkit=10.2 -c pytorch

生成配置文件

1
2
3
4
5
6
cd ~/pytracking
# Environment settings for pytracking. Saved at pytracking/evaluation/local.py
python -c "from pytracking.evaluation.environment import create_default_local_file; create_default_local_file()"

# Environment settings for ltr. Saved at ltr/admin/local.py
python -c "from ltr.admin.environment import create_default_local_file; create_default_local_file()"

生成配置文件后,需要根据你自己的数据路径修改相应的参数值。

下载模型

1
2
3
4
5
6
7
8
9
# Download the default network for DiMP-50 and DiMP-18
gdown https://drive.google.com/uc\?id\=1qgachgqks2UGjKx-GdO1qylBDdB1f9KN -O pytracking/networks/dimp50.pth
gdown https://drive.google.com/uc\?id\=1MAjrRJDCbL0DSjUKFyDkUuYS1-cYBNjk -O pytracking/networks/dimp18.pth

# Download the default network for ATOM
gdown https://drive.google.com/uc\?id\=1VNyr-Ds0khjM0zaq6lU-xfY74-iWxBvU -O pytracking/networks/atom_default.pth

# Download the default network for ECO
gdown https://drive.google.com/uc\?id\=1aWC4waLv_te-BULoy0k-n_zS-ONms21S -O pytracking/networks/resnet18_vggmconv1.pth

注意,模型下载路径可以更改,不过更改后需要修改 pytracking/evaluation/local.py 中的参数:settings.network_path

测试

先用一个终端运行 visdom

1
visdom

visdom 打开后,访问:http://localhost:8097

然后,在另一个终端运行跟踪算法

1
2
cd ~/pytracking
python pytracking/run_tracker.py atom default --dataset_name otb --sequence Soccer --debug 1 --threads 0

运行成功后,会在 visdom 页面的 main 环境中查看到跟踪的情况。

环境配置成功后,我的安装包的情况如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$ pip freeze
absl-py==1.1.0
beautifulsoup4==4.11.1
cachetools==5.2.0
certifi @ file:///opt/conda/conda-bld/certifi_1655968806487/work/certifi
cffi==1.15.1
charset-normalizer==2.1.0
cycler==0.11.0
Cython==0.29.30
filelock==3.7.1
fonttools==4.34.4
gdown==4.5.1
google-auth==2.9.0
google-auth-oauthlib==0.4.6
grpcio==1.47.0
idna==3.3
imageio==2.19.3
importlib-metadata==4.12.0
jpeg4py==0.1.4
jsonpatch==1.32
jsonpointer==2.3
kiwisolver==1.4.3
lvis==0.5.3
Markdown==3.3.7
matplotlib==3.5.2
mkl-fft==1.3.1
mkl-random @ file:///tmp/build/80754af9/mkl_random_1626179032232/work
mkl-service==2.4.0
networkx==2.6.3
numpy==1.21.6
oauthlib==3.2.0
opencv-python==4.6.0.66
packaging==21.3
pandas==1.1.5
Pillow==9.0.1
protobuf==3.19.4
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycocotools==2.0.4
pycparser==2.21
pyparsing==3.0.9
PySocks==1.7.1
python-dateutil==2.8.2
pytz==2022.1
PyWavelets==1.3.0
pyzmq==23.2.0
requests==2.28.1
requests-oauthlib==1.3.1
rsa==4.8
scikit-image==0.19.3
scipy==1.7.3
six @ file:///tmp/build/80754af9/six_1644875935023/work
soupsieve==2.3.2.post1
tb-nightly==2.10.0a20220707
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tifffile==2021.11.2
tikzplotlib==0.10.1
torch==1.7.1
torchfile==0.1.0
torchvision==0.2.2
tornado==6.2
tqdm==4.64.0
typing_extensions==4.3.0
urllib3==1.26.10
visdom==0.1.8.9
webcolors==1.12
websocket-client==1.3.3
Werkzeug==2.1.2
zipp==3.8.0

参考文献

  1. pytracking 环境安装_健0000的博客-CSDN博客_pytracking 环境配置
  2. Pytracking代码运行笔记_而濡木染-程序员