注:配置环境为Ubuntu系统。
Windows版本配置见博客:
pytracking系列跟踪算法的配置(LWL, KYS, PrDiMP, DiMP and ATOM Trackers)(windows10版本)_博博有个大大大的Dream-CSDN博客
1、论文下载地址:
LWL:Learning What to Learn for Video Object Segmentation.[paper]
KYS: Know Your Surroundings: Exploiting Scene Information for Object Tracking.[paper]
PrDiMP:Probabilistic Regression for Visual Tracking.[paper]
DiMP:Learning Discriminative Model Prediction for Tracking.[paper]
ATOM: Accurate Tracking by Overlap Maximization.[paper]
2、代码下载:
https://github.com/visionml/pytracking
3、新建虚拟环境并激活
conda create -n pytracking python=3.7.0
activate pytracking
4、安装pytorch
pip install torch===1.4.0 -f https://download.pytorch.org/whl/torch_stable.html
pip install torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
5、安装依赖库1
pip install matplotlib pandas tqdm
pip install opencv-python visdom tb-nightly scikit-image tikzplotlib gdown
6、安装依赖库2
pip install cython
pip install pycocotools
pip install lvis
7、安装Precise ROI pooling
1)安装ninja-build
sudo apt-get install ninja-build
如果不是sudoer账户,需要添加如下环境变量来使用ninja-build
export PATH="/usr/bin:/usr/lib:/usr/share:/usr/share/man:$PATH"
2)下载Precise ROI pooling库并将其拷贝到路径ltr/external/PreciseRoIPooling/
下载地址:https://github.com/vacancy/PreciseRoIPooling
3)用PreciseRoIPooling/src/prroi_pooling_gpu_impl.cu替换PreciseRoIPooling/pytorch/prroi_pool/src/prroi_pooling_gpu_impl.cu
用PreciseRoIPooling/src/prroi_pooling_gpu_impl.cuh替换PreciseRoIPooling/pytorch/prroi_pool/src/prroi_pooling_gpu_impl.cuh
cp projectdir/pytracking-master/ltr/external/PreciseRoIPooling/src/prroi_pooling_gpu_impl.cu* projectdir/pytracking-master/ltr/external/PreciseRoIPooling/pytorch/prroi_pool/src/
解释一下为什么要这么做: PreciseRoIPooling/pytorch/prroi_pool/src/prroi_pooling_gpu_impl.cuh和PreciseRoIPooling/pytorch/prroi_pool/src/prroi_pooling_gpu_impl.cu这个两个文件用的是相对路径软连接,我们的代码不是通过git clone的形式安装的,相对路径失效,所以需要拷贝替换。至于为什么不用git clone,是因为服务器经常上不去github网站。
8、安装spatial-correlation-sampler (KYS tracker需要的库)
pip install spatial-correlation-sampler
9、安装jpeg4py
sudo apt-get install libturbojpeg
pip install jpeg4py
10、下载预训练模型
下载预训练模型
下载地址:
https://github.com/visionml/pytracking/blob/master/MODEL_ZOO.md
百度云下载地址:
链接:https://pan.baidu.com/s/12R58DNaRJqHodNcT5YzjUQ
提取码:wbrq
新建networks路径保存下载的预训练模型
11、生成配置文件
运行:
python -c "from pytracking.evaluation.environment import create_default_local_file; create_default_local_file()"
python -c "from ltr.admin.environment import create_default_local_file; create_default_local_file()"
运行之后,会生成pytracking/evaluation/local.py和ltr/admin/local.py两个配置文件,设置预训练模型路径和评价数据集路径
12、运行
开一个终端运行可视化服务器
activate pytracking
python -m visdom.server
通过http://localhost:8097/地址观看结果。
开另一个终端运行代码
activate pytracking
python pytracking/run_tracker.py atom default --dataset_name otb --sequence Soccer --debug 1 --threads 0
参数解释一下:atom是需要运行的跟踪器名字
default是参数设置,在pytracking/parameter/atom路径下有很多参数可选。
otb是需要运行的数据集名称
Soccer是需要运行的视频序列名字
debug控制可视化等级
threads运行的线程数
13、遇到错误(1)
raise Exception('Could not read file {}'.format(path))
Exception: Could not read file /data3/publicData/Datasets/OTB/OTB2015/BlurCar1/groundtruth_rect.txt
解决办法:
打开pytracking/utils/load_text.py更改函数:
def load_text_numpy(path, delimiter, dtype)
为如下:
def load_text_numpy(path, delimiter, dtype):
if isinstance(delimiter, (tuple, list)):
for d in delimiter:
try:
# ground_truth_rect = np.loadtxt(path, delimiter=d, dtype=dtype)
# to deal with different delimeters
import io
with open(path,'r') as f:
ground_truth_rect=np.loadtxt(io.StringIO(f.read().replace(',',' ')))
return ground_truth_rect
except:
pass
raise Exception('Could not read file {}'.format(path))
else:
ground_truth_rect = np.loadtxt(path, delimiter=delimiter, dtype=dtype)
return ground_truth_rect
14、遇到错误(2)
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.
....
RuntimeError: Error building extension '_prroi_pooling'
问题原因:
pip安装的torch存在兼容性问题,无法生成_prroi_pooling库。用教程的conda方式安装即可。
解决方法:
pip uninstall torch
pip uninstall torchvision
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
15、再次运行12步骤
编译成功
再次运行12步骤
在http://localhost:8097/地址可查看跟踪结果