pytracking框架 服务器端配置采坑(ubuntu18.04+cuda11.3)

首先附上github链接,里面其实有比较详细的安装教程了,不过完全照做会有些小坑

GitHub - visionml/pytracking: Visual tracking library based on PyTorch.

1. Create and activate a conda environment

conda create --name pytracking python=3.7
conda activate pytracking

2. Install PyTorch

Install PyTorch with cuda10.

 由于我使用的是RTX3060不支持cuda10,正好试一下cuda11的支持情况,在pytorch官网找命令

Start Locally | PyTorch

pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio==0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

(注意,我使用pip安装下面会遇到坑,建议直接使用conda安装)

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

Note:

3. Install matplotlib, pandas, tqdm, opencv, scikit-image, visdom, tikzplotlib, gdown, and tensorboad

conda install matplotlib pandas tqdm
pip install opencv-python visdom tb-nightly scikit-image tikzplotlib gdown

Install the coco and lvis toolkits

conda install cython
pip install pycocotools
pip install lvis

Install ninja-build for Precise ROI pooling

To compile the Precise ROI pooling module (https://github.com/vacancy/PreciseRoIPooling), you may additionally have to install ninja-build.

sudo apt-get install ninja-build

In case of issues, we refer to https://github.com/vacancy/PreciseRoIPooling.

Install spatial-correlation-sampler (only required for KYS tracker)

pip install spatial-correlation-sampler

In case of issues, we refer to https://github.com/ClementPinard/Pytorch-Correlation-extension.

Install jpeg4py

In order to use jpeg4py for loading the images instead of OpenCV's imread(), install jpeg4py in the following way,

sudo apt-get install libturbojpeg
pip install jpeg4py 

Note: The first step (sudo apt-get install libturbojpeg) can be optionally ignored, in which case OpenCV's imread() will be used to read the images. However the second step is a must.

In case of issues, we refer to https://github.com/ajkxyz/jpeg4py.

4. Setup the environment

Create the default environment setting files.

# 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()"

You can modify these files to set the paths to datasets, results paths etc.

这两部会创建用于配置路径的两个local.py,等下会提到

5. Download the pre-trained networks

You can download the pre-trained networks from the google drive folder. The networks shoud be saved in the directory set by "network_path" in "pytracking/evaluation/local.py". By default, it is set to pytracking/networks. You can also download the networks using the gdown python package.

# 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

考虑到梯子问题,也可以自己下好,放到对应目录即可(对应位置同样可以查看local.py文件)

6.补全一些文件

我这边直接使用git的命令会缺失一些文件

github的issues里面有解决办法

git clone https://github.com/visionml/pytracking.git
cd pytracking
git submodule update --init

如果仍然报错,就需要挂梯子,或者手动下载,再加入目录里面

主要是这里的文件

7. 下载数据集并配置数据集位置

8.运行报错

Evaluating    1 trackers on     1 sequences
Tracker: atom default None ,  Sequence: Soccer
Setting up a new session...
../pytracking/features/featurebase.py:78: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
  return TensorList([im_sz // s for s in self.stride()])
../pytracking/features/preprocessing.py:109: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
  tl = posl - (szl - 1) // 2
../pytracking/features/preprocessing.py:110: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
  br = posl + szl//2 + 1
/home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/nn/functional.py:3635: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.
  "See the documentation of nn.Upsample for details.".format(mode)
Using /home/admin312/.cache/torch_extensions/py37_cu113 as PyTorch extensions root...
Detected CUDA files, patching ldflags
Emitting ninja build file /home/admin312/.cache/torch_extensions/py37_cu113/_prroi_pooling/build.ninja...
Building extension module _prroi_pooling...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
[1/3] :/usr/local/cuda-11.3/bin/nvcc  -DTORCH_EXTENSION_NAME=_prroi_pooling -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/TH -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/THC -isystem :/usr/local/cuda-11.3/include -isystem /home/admin312/anaconda3/envs/pytracking/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 --compiler-options '-fPIC' -std=c++14 -c /home/admin312/lzm_project/pytracking/pytracking/ltr/external/PreciseRoIPooling/pytorch/prroi_pool/src/prroi_pooling_gpu_impl.cu -o prroi_pooling_gpu_impl.cuda.o 
FAILED: prroi_pooling_gpu_impl.cuda.o 
:/usr/local/cuda-11.3/bin/nvcc  -DTORCH_EXTENSION_NAME=_prroi_pooling -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/TH -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/THC -isystem :/usr/local/cuda-11.3/include -isystem /home/admin312/anaconda3/envs/pytracking/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_BFLOAT16_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 --compiler-options '-fPIC' -std=c++14 -c /home/admin312/lzm_project/pytracking/pytracking/ltr/external/PreciseRoIPooling/pytorch/prroi_pool/src/prroi_pooling_gpu_impl.cu -o prroi_pooling_gpu_impl.cuda.o 
/bin/sh: 1: :/usr/local/cuda-11.3/bin/nvcc: not found
[2/3] c++ -MMD -MF prroi_pooling_gpu.o.d -DTORCH_EXTENSION_NAME=_prroi_pooling -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/TH -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/THC -isystem :/usr/local/cuda-11.3/include -isystem /home/admin312/anaconda3/envs/pytracking/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -std=c++14 -c /home/admin312/lzm_project/pytracking/pytracking/ltr/external/PreciseRoIPooling/pytorch/prroi_pool/src/prroi_pooling_gpu.c -o prroi_pooling_gpu.o 
FAILED: prroi_pooling_gpu.o 
c++ -MMD -MF prroi_pooling_gpu.o.d -DTORCH_EXTENSION_NAME=_prroi_pooling -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/TH -isystem /home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/THC -isystem :/usr/local/cuda-11.3/include -isystem /home/admin312/anaconda3/envs/pytracking/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -std=c++14 -c /home/admin312/lzm_project/pytracking/pytracking/ltr/external/PreciseRoIPooling/pytorch/prroi_pool/src/prroi_pooling_gpu.c -o prroi_pooling_gpu.o 
In file included from /home/admin312/lzm_project/pytracking/pytracking/ltr/external/PreciseRoIPooling/pytorch/prroi_pool/src/prroi_pooling_gpu.c:15:0:
/home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/include/ATen/cuda/CUDAContext.h:5:10: fatal error: cuda_runtime_api.h: 没有那个文件或目录
 #include <cuda_runtime_api.h>
          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "/home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1723, in _run_ninja_build
    env=env)
  File "/home/admin312/anaconda3/envs/pytracking/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "run_tracker.py", line 65, in <module>
    main()
  File "run_tracker.py", line 61, in main
    args.threads, {'use_visdom': args.use_visdom, 'server': args.visdom_server, 'port': args.visdom_port})
  File "run_tracker.py", line 37, in run_tracker
    run_dataset(dataset, trackers, debug, threads, visdom_info=visdom_info)
  File "../pytracking/evaluation/running.py", line 199, in run_dataset
    run_sequence(seq, tracker_info, debug=debug, visdom_info=visdom_info)
  File "../pytracking/evaluation/running.py", line 148, in run_sequence
    output = tracker.run_sequence(seq, debug=debug, visdom_info=visdom_info)
  File "../pytracking/evaluation/tracker.py", line 148, in run_sequence
    output = self._track_sequence(tracker, seq, init_info)
  File "../pytracking/evaluation/tracker.py", line 186, in _track_sequence
    out = tracker.initialize(image, init_info)
  File "../pytracking/tracker/atom/atom.py", line 115, in initialize
    self.init_iou_net()
  File "../pytracking/tracker/atom/atom.py", line 694, in init_iou_net
    target_feat = self.iou_predictor.get_modulation(iou_backbone_features, target_boxes)
  File "../ltr/models/bbreg/atom_iou_net.py", line 157, in get_modulation
    roi3r = self.prroi_pool3r(c3_r, roi1)
  File "/home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "../ltr/external/PreciseRoIPooling/pytorch/prroi_pool/prroi_pool.py", line 28, in forward
    return prroi_pool2d(features, rois, self.pooled_height, self.pooled_width, self.spatial_scale)
  File "../ltr/external/PreciseRoIPooling/pytorch/prroi_pool/functional.py", line 44, in forward
    _prroi_pooling = _import_prroi_pooling()
  File "../ltr/external/PreciseRoIPooling/pytorch/prroi_pool/functional.py", line 33, in _import_prroi_pooling
    verbose=True
  File "/home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1136, in load
    keep_intermediates=keep_intermediates)
  File "/home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1347, in _jit_compile
    is_standalone=is_standalone)
  File "/home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1452, in _write_ninja_file_and_build_library
    error_prefix=f"Error building extension '{name}'")
  File "/home/admin312/anaconda3/envs/pytracking/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1733, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error building extension '_prroi_pooling'

抓重点来看就是cuda的问题,cuda11真的万恶之源

我当时使用的是最新的cuda11.5,于是参照下面这篇帖子卸载重装了cuda11.4(因为之前11.3不行,pytorch1.10又只支持11.3以上)

  

9.torch需要降级

重装之后编译正常,但torch报错

于是conda卸载重装pytorch1.7,cuda则安装cuda11.0与cuda11.4并存,这个教程很多了 

10.然后cuda11.0没办法编译PreciseRolPooling

就是那个  compute_86 的错误,之前指github issues里看到过这个错误,更到11.3版本后可解,很好

11.其实改fft是最佳办法,如下

try:
    from torch import irfft
    from torch import rfft
except ImportError:
    from torch.fft import irfft2
    from torch.fft import rfft2
    def rfft(x, d):
        t = rfft2(x, dim = (-d))
        return torch.stack((t.real, t.imag), -1)
    def irfft(x, d, signal_sizes):
        return irfft2(torch.complex(x[:,:,0], x[:,:,1]), s = signal_sizes, dim = (-d))


 

参考链接

pytracking系列跟踪算法的配置(LWL, KYS, PrDiMP, DiMP and ATOM Trackers)(Ubuntu版本)_博博有个大大大的Dream-CSDN博客_pytracking训练

(5条消息) [Object Tracking][环境配置流程][Ubuntu16.04]ATOM【CVPR2019】pytracking_llzxz9628的博客-CSDN博客

Ubuntu之cuda11.4安装_月生的静心苑-CSDN博客

(21条消息) 解决报错:AttributeError: module ‘torch‘ has no attribute ‘irfft‘_羊城迷鹿的博客-CSDN博客

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
好的,以下是在Ubuntu 18.04上安装CUDA 11.3的步骤: 1. 下载CUDA Toolkit 11.3 在NVIDIA官网上下载CUDA Toolkit 11.3,下载链接为:https://developer.nvidia.com/cuda-downloads 2. 安装依赖项 在终端中执行以下命令安装依赖项: ``` sudo apt-get update sudo apt-get install build-essential dkms freeglut3 freeglut3-dev libxi-dev libxmu-dev ``` 3. 禁用nouveau驱动 在终端中执行以下命令禁用nouveau驱动: ``` sudo vim /etc/modprobe.d/blacklist-nouveau.conf ``` 在文件中添加以下内容: ``` blacklist nouveau options nouveau modeset=0 ``` 保存并关闭文件后,在终端中执行以下命令使配置生效: ``` sudo update-initramfs -u ``` 4. 重启系统 在终端中执行以下命令重启系统: ``` sudo reboot ``` 5. 安装CUDA Toolkit 11.3 进入下载的CUDA Toolkit 11.3所在的目录,在终端中执行以下命令进行安装: ``` sudo sh cuda_11.3.0_<version>_linux.run ``` 其中,`<version>`是下载的CUDA Toolkit 11.3的版本号。在安装过程中,需要按照提示进行操作。如果需要将CUDA加入环境变量,可以选择在安装过程中设置。 6. 验证CUDA安装是否成功 在终端中执行以下命令验证CUDA安装是否成功: ``` nvcc -V ``` 如果输出类似于以下内容,则说明CUDA安装成功: ``` nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2021 NVIDIA Corporation Built on Mon_Jun_14_19:14:37_PDT_2021 Cuda compilation tools, release 11.3, V11.3.109 Build cuda_11.3.r11.3/compiler.29920130_0 ``` 希望这些步骤可以帮助您在Ubuntu 18.04上成功安装CUDA 11.3。如果您遇到任何问题,请随时向我提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值