Ubuntu20.04 环境配置 YOLACT++

1 篇文章 0 订阅
1 篇文章 0 订阅

整体参考,致敬!!

超详细ubuntu20.04运行安装yolact++,编译DCNv2,pytorch=1.11.0 cudatoolkit=11.3_dcnv2编译-CSDN博客文章浏览阅读2.4k次,点赞4次,收藏31次。超详细ubuntu20.04运行安装yolact++,编译DCNv2,pytorch=1.11.0 torchvision=0.12.0 torchaudio=0.11.0 cudatoolkit=11.3 _dcnv2编译https://blog.csdn.net/u013454780/article/details/129970449尽量跟上面的版本号保持一致

1、安装Ubuntu20.04系统,配置网络环境

笔者是一开始搭建18.04,后续换了20.04
记录重装系统的博文:

Ubuntu18.04安装教程——超详细的图文教程_ubuntu系统18.04-CSDN博客文章浏览阅读10w+次,点赞113次,收藏989次。Ubuntu18.04镜像_ubuntu系统18.04https://blog.csdn.net/weixin_44623637/article/details/106723462安装好Ubuntu18.04之后要做的事!!大全、详细教程!_安装完ubuntu18.04后-CSDN博客文章浏览阅读9.4w次,点赞127次,收藏1.2k次。安装Ubuntu18.04之后的要做的事:1、更新源,使用软件更新器选择中国的服务器aliyun即可自动更新缓存,已经各种软件之后每天更新, shell更新:sudo apt update sudo apt upgrade2、安装vim、wget、curlsudo apt install vim配置十字光标:用户目录下 vim .vimrc..._安装完ubuntu18.04后https://blog.csdn.net/haeasringnar/article/details/81809040?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecaseUbuntu 20.04 LTS 桌面版详细安装指南 - 系统极客Ubuntu 20.04 LTS 代号 Focal Fossa,于 2020 年 4 月 23 日正式发布,附带 Kernel 5.4、GNOME 3.36、ZFS 安装支持、更快的启动速度、GameMode 性能工具、Snap Store,改进的外观和大量软件更新。下面系统就一步一步详细介绍,如何安装一台全新的 Ubuntu 20.04 LTS 桌面版计算机。icon-default.png?t=N7T8https://www.sysgeek.cn/install-ubuntu-20-04-lts-desktop/

安装了搜狗输入法以及wps,以及

Ubuntu 配置xxx的四种方式 – 日拱一卒

这个安装之后,就不用后续再配置清华源等国内镜像了

/****************************************安装完成Ubuntu20.04*******************************************/

2、配置CUDA11.4.0、cuDNN8.2.4

Ubuntu20.04下CUDA、cuDNN的详细安装与配置过程(图文)_ubuntu cudnn安装-CSDN博客文章浏览阅读10w+次,点赞202次,收藏1.7k次。Ubuntu20.04安装NVIDIA显卡驱动及CUDA深度学习环境配置(图文)安装准备,重要!NVIDIA(英伟达)显卡驱动安装安装CUDA安装cudnnCUDA测试我发现在终端输入sudo apt install nvidia-cuda-toolkit就能自动安装CUDA了,但是有没有安装cudnn安装准备,重要!NVIDIA(英伟达)显卡驱动安装由于新安装的Ubuntu20.04系统并没有安装NVIDIA显卡驱动,所以需要先安装它。如果系统已经安装过驱动,可以通过指令nvidia-smi查看,_ubuntu cudnn安装https://blog.csdn.net/weixin_37926734/article/details/123033286?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167137139716782395325426%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=167137139716782395325426&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-123033286-null-null.142%5Ev68%5Econtrol,201%5Ev4%5Eadd_ask,213%5Ev2%5Et3_control2&utm_term=ubuntu20.04%E5%AE%89%E8%A3%85cuda&spm=1018.2226.3001.4187但是!!!yolact环境也需要的是CUDA11.4,上面的链接是安装的是CUDA11.0,要注意替换!

终端输入nvidia-smi,CUDA Version:11.4表示驱动支持的CUDA最高版本为11.4

在这里插入图片描述

注意!!!这个博文有个地方不太对:

这一块的顺序改变一下,而且要加sudo ,而且版本号得改成cuDNN v8.2.4

sudo dpkg -i libcudnn8_8.0.5.39-1+cuda11.0_amd64.deb

sudo dpkg -i libcudnn8-dev_8.0.5.39-1+cuda11.0_amd64.deb

sudo dpkg -i libcudnn8-samples_8.0.5.39-1+cuda11.0_amd64.deb

我没有检测cudnn,耗时间较长,不建议下载这三个安装包

3、安装Anaconda

超详细Ubuntu安装Anaconda步骤+Anconda常用命令_ubuntu 安装anaconda-CSDN博客文章浏览阅读8.6w次,点赞232次,收藏1.2k次。Ubuntu安装Anaconda1. 下载Anconda安装包1.1 网页手动下载1.2 wget命令行下载2. 安装Anaconda3. Anconda常用命令1. 下载Anconda安装包安装Anaconda之前需要先下载安装包,这里提供两种下载方式:网页手动下载、wget命令行下载。两种方式均可,我自己使用的是wget命令行下载。因为wget命令非常稳定。1.1 网页手动下载在Ubuntu系统里面使用firefox浏览器进入Anaconda官网:https://www.anaconda._ubuntu 安装anacondahttps://blog.csdn.net/KRISNAT/article/details/124041869?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-3-124041869-blog-82079943.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-3-124041869-blog-82079943.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=6

4、克隆YOLACT库

超详细ubuntu20.04运行安装yolact++,编译DCNv2,pytorch=1.11.0 cudatoolkit=11.3_dcnv2编译-CSDN博客文章浏览阅读2.4k次,点赞4次,收藏31次。超详细ubuntu20.04运行安装yolact++,编译DCNv2,pytorch=1.11.0 torchvision=0.12.0 torchaudio=0.11.0 cudatoolkit=11.3 _dcnv2编译https://blog.csdn.net/u013454780/article/details/129970449跟着这个的第二章,但是有一些修改:

git clone https://github.com/dbolya/yolact.git
cd yolact

5、设置conda虚拟环境yolact

  • 手动地使用pip创建yolact 环境,这里换成了Python3.8
# 创建yolact 环境,环境名为yolact ,python版本选择3.8
conda create -n yolact python=3.8 
cgm@cgm:~/yolact$ conda create -n yolact python=3.8
Collecting package metadata (current_repodata.json): done                                                                                                                                                                       
Solving environment: done                                                                                                                                                                                                       
                                                                                                                                                                                                                                
## Package Plan ##                                                                                                                                                                                                              
                                                                                                                                                                                                                                
  environment location: /home/cgm/anaconda3/envs/yolact                                                                                                                                                                         
                                                                                                                                                                                                                                
  added / updated specs:                                                                                                                                                                                                        
    - python=3.8                                                                                                                                                                                                                
                                                                                                                                                                                                                                
                                                                                                                                                                                                                                
The following packages will be downloaded:                                                                                                                                                                                      

    package                    |            build
    ---------------------------|-----------------
    certifi-2022.12.7          |   py37h06a4308_0         150 KB
    pip-22.3.1                 |   py37h06a4308_0         2.7 MB
    python-3.7.16              |       h7a1cb2a_0        44.8 MB
    setuptools-65.6.3          |   py37h06a4308_0         1.1 MB
    wheel-0.38.4               |   py37h06a4308_0          63 KB
    ------------------------------------------------------------
                                           Total:        48.9 MB

The following NEW packages will be INSTALLED:

  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main 
  _openmp_mutex      pkgs/main/linux-64::_openmp_mutex-5.1-1_gnu 
  ca-certificates    pkgs/main/linux-64::ca-certificates-2023.01.10-h06a4308_0 
  certifi            pkgs/main/linux-64::certifi-2022.12.7-py37h06a4308_0 
  ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.38-h1181459_1 
  libffi             pkgs/main/linux-64::libffi-3.4.2-h6a678d5_6 
  libgcc-ng          pkgs/main/linux-64::libgcc-ng-11.2.0-h1234567_1 
  libgomp            pkgs/main/linux-64::libgomp-11.2.0-h1234567_1 
  libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-11.2.0-h1234567_1 
  ncurses            pkgs/main/linux-64::ncurses-6.4-h6a678d5_0 
  openssl            pkgs/main/linux-64::openssl-1.1.1t-h7f8727e_0 
  pip                pkgs/main/linux-64::pip-22.3.1-py37h06a4308_0 
  python             pkgs/main/linux-64::python-3.7.16-h7a1cb2a_0 
  readline           pkgs/main/linux-64::readline-8.2-h5eee18b_0 
  setuptools         pkgs/main/linux-64::setuptools-65.6.3-py37h06a4308_0 
  sqlite             pkgs/main/linux-64::sqlite-3.41.1-h5eee18b_0 
  tk                 pkgs/main/linux-64::tk-8.6.12-h1ccaba5_0 
  wheel              pkgs/main/linux-64::wheel-0.38.4-py37h06a4308_0 
  xz                 pkgs/main/linux-64::xz-5.2.10-h5eee18b_1 
  zlib               pkgs/main/linux-64::zlib-1.2.13-h5eee18b_0 


Proceed ([y]/n)? y


Downloading and Extracting Packages
                                                                                                                                                                                                                                
Preparing transaction: done                                                                                                                                                                                                     
Verifying transaction: done                                                                                                                                                                                                     
Executing transaction: done                                                                                                                                                                                                     
#                                                                                                                                                                                                                               
# To activate this environment, use
#
#     $ conda activate yolact
#
# To deactivate an active environment, use
#
#     $ conda deactivate

  • 使用 conda activate yolact 激活yolact环境

  • 由于第一步我们配置过了网络,这里就不用添加镜像了
  • 安装需要的依赖项
pip install cython
pip install opencv-python pillow pycocotools matplotlib 

 6、安装pytorch

# CUDA 11.3  用这个
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
  • 安装完成后再次运行这个命令是这样的(有别的博文说要用pip下载,但是笔者还是使用conda下载)
(yolact) cgm@cgm:~/yolact$ conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.
  • 验证 pytorch cuda可用

安装完成后,进入python交互环境,然后输入import torchtorch.__version__,如下所示:

(yolact) cgm@cgm:~/yolact/external/DCNv2$ python
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:21) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.__version__
'1.11.0'
>>> exit()

7、选择编译DCNv2_latest

因为这个仓库支持pytorch1.11,还在ubuntu20.04、python3.8(conda)、cuda_11.4上进行了测试

  • 下载DCNv2_latest并把文件放入yolact/external/DCNv2文件夹
    (其实就是把yolact/external/DCNv2文件夹里的东西全部换成DCNv2_latest里的内容)

  • 安装DCNv2_latest

  •  安装DCNv2_latest,输入
  •  python3 setup.py build develop

     

    效果如下,会出现几个错误:

    cgm@cgm:~$ conda activate yolact
    (yolact) cgm@cgm:~$ cd yolact/
    (yolact) cgm@cgm:~/yolact$ cd external/DCNv2/
    (yolact) cgm@cgm:~/yolact/external/DCNv2$ python3 setup.py build develop
    running build
    running build_ext
    /home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/utils/cpp_extension.py:387: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
      warnings.warn(msg.format('we could not find ninja.'))
    error: [Errno 2] No such file or directory: ':/usr/local/cuda/bin/nvcc': ':/usr/local/cuda/bin/nvcc'
    

        一个警告:we could not find ninja.
        解决办法:conda install ninja

        一个错误:No such file or directory: ':/usr/local/cuda/bin/nvcc': ':/usr/local/cuda/bin/nvcc'
        解决办法:export CUDA_HOME=/usr/local/cuda-11.4

    error:function "automicADD(doule*,doule)" has already been define

    解决方法:在dcn_v2_psroi_pooling_cuda.cu添加代码

    #ifndef CAFFE_COMMON_CUH_
    #define CAFFE_COMMON_CUH_
    
      #include <cuda.h>
    
      #if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 600
      static __inline__ __device__ double atomicAdd(double *address, double val) {
        unsigned long long int* address_as_ull = (unsigned long long int*)address;
        unsigned long long int old = *address_as_ull, assumed;
        if (val==0.0)
          return __longlong_as_double(old);
        do {
          assumed = old;
          old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val +__longlong_as_double(assumed)));
        } while (assumed != old);
        return __longlong_as_double(old);
      }
      #endif
    
    #endif
    

    dcn_v2_psroi_pooling_cuda.cu文件:

    注意!!!!!每次编译都要把上次生成的"build“文件夹删掉

    成功编译效果:

(yolact) cgm@cgm:~/yolact/external/DCNv2$ python testcuda.py 
torch.Size([2, 64, 128, 128])
torch.Size([20, 32, 7, 7])
torch.Size([20, 32, 7, 7])
torch.Size([20, 32, 7, 7])
0.971507, 1.943014
0.971507, 1.943014
Zero offset failed
tensor([[[[-0.7596, -0.1410, -0.3335,  0.8734],
          [ 0.3883,  0.9641, -0.4845,  0.0139],
          [ 1.0427, -1.5031, -1.3956, -0.7286],
          [-0.4027,  1.0158, -1.4057,  0.4795]],

         [[-0.2074,  0.2585,  0.0192,  1.7720],
          [ 2.3009,  1.1745, -0.7150, -0.5564],
          [ 0.9626,  0.3455,  0.9791, -0.8539],
          [ 0.6182,  0.0554, -1.0775, -1.2543]]],


        [[[ 1.0509, -0.2816,  1.3106,  1.8552],
          [ 0.3615,  0.4687, -0.0643, -0.1565],
          [ 0.4575,  2.1677,  0.1354, -1.0271],
          [ 1.2323, -1.2368,  0.8022, -0.3021]],

         [[-0.2007,  1.0510,  0.5536, -1.3705],
          [ 1.4579, -1.3516, -0.0833, -0.8850],
          [-0.8864,  0.9026,  0.2035,  1.5334],
          [-0.7752,  0.1500,  1.2292, -0.4139]]]], device='cuda:0')
tensor([[[[-0.7598, -0.1410, -0.3335,  0.8735],
          [ 0.3884,  0.9639, -0.4846,  0.0139],
          [ 1.0430, -1.5029, -1.3955, -0.7285],
          [-0.4026,  1.0156, -1.4053,  0.4795]],

         [[-0.2074,  0.2585,  0.0192,  1.7725],
          [ 2.3008,  1.1748, -0.7148, -0.5566],
          [ 0.9624,  0.3455,  0.9790, -0.8540],
          [ 0.6182,  0.0554, -1.0771, -1.2539]]],


        [[[ 1.0508, -0.2817,  1.3105,  1.8555],
          [ 0.3616,  0.4688, -0.0643, -0.1565],
          [ 0.4575,  2.1680,  0.1354, -1.0273],
          [ 1.2324, -1.2363,  0.8022, -0.3022]],

         [[-0.2007,  1.0508,  0.5537, -1.3701],
          [ 1.4580, -1.3516, -0.0833, -0.8848],
          [-0.8862,  0.9028,  0.2035,  1.5332],
          [-0.7754,  0.1499,  1.2295, -0.4138]]]], device='cuda:0',
       grad_fn=<MulBackward0>)
/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py:648: UserWarning: Input #0 requires gradient and is not a double precision floating point or complex. This check will likely fail if all the inputs are not of double precision floating point or complex. 
  f'Input #{idx} requires gradient and '
/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py:648: UserWarning: Input #2 requires gradient and is not a double precision floating point or complex. This check will likely fail if all the inputs are not of double precision floating point or complex. 
  f'Input #{idx} requires gradient and '
check_gradient_dpooling: True
/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py:648: UserWarning: Input #1 requires gradient and is not a double precision floating point or complex. This check will likely fail if all the inputs are not of double precision floating point or complex. 
  f'Input #{idx} requires gradient and '
/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py:648: UserWarning: Input #3 requires gradient and is not a double precision floating point or complex. This check will likely fail if all the inputs are not of double precision floating point or complex. 
  f'Input #{idx} requires gradient and '
/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py:648: UserWarning: Input #4 requires gradient and is not a double precision floating point or complex. This check will likely fail if all the inputs are not of double precision floating point or complex. 
  f'Input #{idx} requires gradient and '
Traceback (most recent call last):
  File "testcuda.py", line 265, in <module>
    check_gradient_dconv()
  File "testcuda.py", line 97, in check_gradient_dconv
    eps=1e-3, atol=1e-4, rtol=1e-2))
  File "/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py", line 1400, in gradcheck
    return _gradcheck_helper(**args)
  File "/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py", line 1417, in _gradcheck_helper
    check_undefined_grad=check_undefined_grad)
  File "/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py", line 1062, in _gradcheck_real_imag
    rtol, atol, check_grad_dtypes, nondet_tol)
  File "/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py", line 1110, in _slow_gradcheck
    analytical = _check_analytical_jacobian_attributes(tupled_inputs, o, nondet_tol, check_grad_dtypes)
  File "/home/cgm/anaconda3/envs/yolact/lib/python3.7/site-packages/torch/autograd/gradcheck.py", line 548, in _check_analytical_jacobian_attributes
    FAILED_NONDET_MSG)
torch.autograd.gradcheck.GradcheckError: Backward is not reentrant, i.e., running backward with same input and grad_output multiple times gives different values, although analytical gradient matches numerical gradient.The tolerance for nondeterminism was 0.0.

NOTE: If your op relies on non-deterministic operations i.e., it is listed here:
https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html
this failure might be expected.

If you are adding a new operator, please file an issue and then use one of the
workarounds. The workaround depends on how your test invokes gradcheck/gradgradcheck.
If the test
- manually invokes gradcheck/gradgradcheck, then call gradcheck/gradgradcheck
  with `nondet_tol=<tol>` as a keyword argument.
- is OpInfo-based (e.g., in test_ops.py), then modify the OpInfo for the test
  to have `gradcheck_nondet_tol=<tol>`.
- is a Module test (e.g., in common_nn.py), then modify the corresponding
  module_test entry to have `gradcheck_nondet_tol=<tol>

8、测试图片

  • 将你的下载好的测试的图片放入文件夹里

  • 测试images的命令
# 在指定图像上显示定性结果
python eval.py --trained_model=weights/yolact_base_54_800000.pth --score_threshold=0.15 --top_k=15 --image=你的图像.png
# 处理图像并将其保存到另一个文件
python eval.py --trained_model=weights/yolact_base_54_800000.pth --score_threshold=0.15 --top_k=15 --image=你输入的图像.png:输出图像.png
# 处理整个文件夹的图像
python eval.py --trained_model=weights/yolact_base_54_800000.pth --score_threshold=0.15 --top_k=15 --images=你输入图像的文件夹路径:你输出图像的文件夹路径

完结~~撒花✿✿ヽ(°▽°)ノ✿

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值