整体参考,致敬!!
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 桌面版计算机。https://www.sysgeek.cn/install-ubuntu-20-04-lts-desktop/
安装了搜狗输入法以及wps,以及
这个安装之后,就不用后续再配置清华源等国内镜像了
/****************************************安装完成Ubuntu20.04*******************************************/
2、配置CUDA11.4.0、cuDNN8.2.4
终端输入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
4、克隆YOLACT库
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 torch
和torch.__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.4error: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、测试图片
- 在~/yolact文件夹下新建
weights文件夹以及images文件夹
- https://github.com/dbolya/yolact/tree/master#evaluationhttps://github.com/dbolya/yolact/tree/master#evaluation要评估模型,就需要在连接中下载
权重文件,放在 ./weights 目录中
并运行以下命令之一。每个配置的名称都是文件名中数字之前的所有内容(例如,yolact++
对应 yolact_plus_resnet50_54_800000.pth)
- 将你的下载好的测试的图片放入文件夹里
- 测试
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=你输入图像的文件夹路径:你输出图像的文件夹路径
完结~~撒花✿✿ヽ(°▽°)ノ✿