注:配置环境为windows10系统。比较麻烦,还是推荐使用Ubuntu系统配置
Ubuntu版本配置见博客:
https://blog.csdn.net/qq_17783559/article/details/117933369
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、安装依赖库
pip install matplotlib pandas jpeg4py
pip install opencv-python visdom tb-nightly
6、安装coco toolkit
pip install cython pycocotools
7、安装Precise ROI pooling
1)下载module
https://github.com/vacancy/PreciseRoIPooling
将解压后的pytorch文件夹拷贝到路径E:\Codes\PyCharm\pytracking-master\ltr\external\PreciseRoIPooling\
2)下载prroi_pool.pyd
这个文件是使用C++生成的库文件,DiMP和ATOM算法会用到。下载作者提供的文件路径如下,
https://visionml.github.io/dimp/prroi_pool.pyd
保存到路径:D:\Softwares\Anaconda3\envs\pytracking\Lib\site-packages\
只要是python的检索到的环境变量路径都可以。本工程放到新建虚拟python环境的依赖库路径下。
3)添加环境变量:
此处添加环境变量是为了python能够找到文件prroi_pool.pyd
4)打开E:\Codes\PyCharm\pytracking-master\pytracking-master\ltr\external\PreciseRoIPooling\pytorch\prroi_pool\functional.py
添加如下代码:
# load the prroi_pool module
import imp
file, path, description = imp.find_module('prroi_pool')
with file:
_prroi_pooling = imp.load_module('prroi_pool', file, path, description)
8、下载预训练模型
下载地址:
https://github.com/visionml/pytracking/blob/master/MODEL_ZOO.md
百度云下载地址:
链接:https://pan.baidu.com/s/12R58DNaRJqHodNcT5YzjUQ
提取码:wbrq
新建networks路径保存下载的预训练模型
9、创造配置文件
在工程路径下新建createlocalfiles.py,并写入如下代码:
import ltr.admin.environment as ltrae
import pytracking.evaluation.environment as pyee
ltrae.create_default_local_file()
pyee.create_default_local_file()
运行python createlocalfiles.py
运行之后,会在\pytracking\evaluation\路径和\ltr\admin\路径下生成local.py,打开这两个文件可以配置一些我们的实验参数。如指定数据集路径和预训练模型路径等。
10、打开可视服务器
python -m visdom.server
运行成功会有个IP地址,用来看我们的可视化数据的
11、另开一个终端运行
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运行的线程数
可能会遇到错误:
File "E:\Codes\PyCharm\pytracking\pytracking\utils\load_text.py", line 14, in load_text_numpy
raise Exception('Could not read file {}'.format(path))
Exception: Could not read file E:\Datasets\OTB2015/BlurCar1/groundtruth_rect.txt
这是由于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
12、如果你是天选之子,恭喜你,到这一步就应该配置完成了!!!再次运行,用浏览器打开地址:http://localhost:8097/查看结果
13、再次运行遇到错误(可能遇到)
File "D:\Softwares\Anaconda3\envs\pytracking\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
......
File "D:\Softwares\Anaconda3\envs\pytracking\lib\site-packages\torch\utils\cpp_extension.py", line 889, in _write_ninja_file_and_build
verify_ninja_availability()
File "D:\Softwares\Anaconda3\envs\pytracking\lib\site-packages\torch\utils\cpp_extension.py", line 931, in verify_ninja_availability
raise RuntimeError("Ninja is required to load C++ extensions")
RuntimeError: Ninja is required to load C++ extensions
不知道原因是什么,我的解决方法是:pip install Ninja
14、再次运行遇到错误(可能遇到)
D:\Softwares\Anaconda3\envs\pytracking\lib\site-packages\torch\utils\cpp_extension.py:209: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找不到指定的文件。
warnings.warn('Error checking compiler version for {}: {}'.format(compiler, error))
Detected CUDA files, patching ldflags
Emitting ninja build file C:\Users\HuangBo\AppData\Local\Temp\torch_extensions\_prroi_pooling\build.ninja...
信息: 用提供的模式无法找到文件。
.....
File "D:\Softwares\Anaconda3\envs\pytracking\lib\subprocess.py", line 468, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['where', 'cl']' returned non-zero exit status 1.
错误原因:python找不到visual studio编译器cl.exe。我的环境的cl.exe所在路径如下:
D:\Softwares\VisualStudio\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64
解决方法:
将这个路径添加到系统环境变量,然后重启
方法来源:Windows10下配置VS2017 环境变量_qing666888的专栏-CSDN博客_vs2017环境变量配置
15、再次运行遇到错误(可能遇到)
File "
File "
File "
File "
File "
ImportError: DLL load failed: 找不到指定的程序。
错误原因:作者提供的prroi_pool.pyd与系统不兼容,这个问题最为头疼,我们需要使用visual studio编译来生成依赖库prroi_pool.pyd
或者用我编译好的prroi_pool.pyd试试,下载:
链接:https://pan.baidu.com/s/1N3wakNfcHcYmj-GsHfCxsQ
提取码:jeza
过程如下:
1)下载依赖库文件
Precise ROI pooling:
https://github.com/vacancy/PreciseRoIPooling
pybind11
GitHub - pybind/pybind11: Seamless operability between C++11 and Python
2)打开visual studio新建空工程
更改项目属性为Release x64
3)将第1)步骤下载文件拷贝到VS工程路径(注意路径不一样)
文件1:\PreciseRoIPooling-master\PreciseRoIPooling-master\pytorch\prroi_pool\src\prroi_pooling_gpu.c
文件2:\PreciseRoIPooling-master\PreciseRoIPooling-master\pytorch\prroi_pool\src\prroi_pooling_gpu.h
文件3:\PreciseRoIPooling-master\PreciseRoIPooling-master\src\prroi_pooling_gpu_impl.cu
文件4:\PreciseRoIPooling-master\PreciseRoIPooling-master\src\prroi_pooling_gpu_impl.cuh
将这四个文件添加到VS工程,并更改prroi_pooling_gpu.c为prroi_pooling_gpu.cpp
4)设置工程属性
常规页:拓展名改为:.pyd
平台工具集改为:VS2015(注:我的VS版本是VS2017)
配置类型改为:动态库.dll
VC++目录页:
包含路径添加:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include;(CUDA路径)
E:\Codes\PyCharm\pytracking-master\addition\pybind11-master\pybind11-master\include;(这个路径即我们第一步骤下载的pybind11库所在路径)
D:\Softwares\Anaconda3\envs\pytracking\include;
D:\Softwares\Anaconda3\envs\pytracking\Lib\site-packages\torch\include\THC;
D:\Softwares\Anaconda3\envs\pytracking\Lib\site-packages\torch\include\torch\csrc\api\include;
D:\Softwares\Anaconda3\envs\pytracking\Lib\site-packages\torch\include\TH;
D:\Softwares\Anaconda3\envs\pytracking\Lib\site-packages\torch\include;
库路径添加:
D:\Softwares\Anaconda3\envs\pytracking\libs;
D:\Softwares\Anaconda3\envs\pytracking\Lib\site-packages\torch\lib;
linker->General页:
额外的库路径添加路径:
D:\Softwares\Anaconda3\envs\pytracking\Lib\site-packages\torch\lib;
D:\Softwares\Anaconda3\envs\pytracking\libs;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64;
linker->Input页:
添加额外依赖库:
python37.lib
python3.lib
cudart.lib
c10.lib
torch.lib
torch_python.lib
_C.lib
c10_cuda.lib
5)工程设置
右键工程->生成依赖项->生成自定义->勾选CUDA10.0
6)工程设置
右键点击prroi_pooling_gpu_impl.cuh->属性->更改为CUDA C/C++编译器
同理,对prroi_pooling_gpu_impl.cu做一样的操作
7)更改prroi_pooling_gpu.cpp
109行将
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
改为:
PYBIND11_MODULE(prroi_pool, m) {
8)点击生成->生成解决方案
出现错误如下:
点击第一个错误,直接注释掉:
点击2-6处错误:将data改为data_ptr
点击第7个错误,在std前加上::
9)再次编译成功
10)将生成的buildprroi_pool.pyd,拷贝到D:\Softwares\Anaconda3\envs\pytracking\Lib\site-packages路径并改名为:prroi_pool.pyd
我编译好的prroi_pool.pyd下载:
链接:https://pan.baidu.com/s/1N3wakNfcHcYmj-GsHfCxsQ
提取码:jeza
16、开两个终端
一个运行python -m visdom.server
一个运行python pytracking/run_tracker.py atom default --dataset_name otb --sequence Soccer --debug 1 --threads 0
至此,就可以愉快地运行pytracking了