本文介绍: WSL使用Ubuntu 20.04版本运行py-bottom-up-attention的记录,及其可能错误的解决方法。

WSL使用Ubuntu 20.04版本运行py-bottom-up-attention的记录,及其可能错误的解决方法

github代码地址:

git clone https://github.com/airsplay/py-bottom-up-attention.git

环境:

  • wsl Ubuntu 20.04
  • 显卡:GTX 1660
  • gcc 8或者9应该都可以
  • 显卡驱动,现在win端和wsl是共用的,win装过了,wsl可以用,不需要安装驱动
  • cuda 10.1
  • python 3.7
  • 依赖版本:opencv-python== 4.8.1.78 、setuptools== 59.6.0
1. 切换linux的镜像

将wsl的默认Ubuntu镜像修改为阿里镜像,可以使速度下载得到很大提升。

打开镜像list文件,如下命令,然后使用ggdG删除当前文件中的内容。

sudo vim /etc/apt/sources.list

找到阿里云的镜像,直接复制过来,替换掉source.list的内容。

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

然后更新软件列表:

sudo apt-get update
sudo apt-get upgrade
2. 安装gcc

首先查看gcc的版本,使用命令gcc -v查看,如下图所示:

(base) wjx@wang:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.3' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-05ho5U/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.3)
3. 查看显卡驱动

然后查看wsl是否有显卡的驱动,命令nvidia-smi,输出如下所示,可以看到CUDA Version,表示支持最高的cuda版本是12.3,当然装低版本的cuda是没有问题的,是可以兼容的。

在这里插入图片描述

4. 安装gcc版本

我们可以安装gcc 8版本,使用命令 sudo apt-get install gcc-8,就可以成功安装,似乎gcc-9版本的也可以。

sudo apt-get install gcc-8

再次使用gcc -v查看是否显示对应的版本,应该会出现如下信息:

(base) wjx@wang:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.3' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-05ho5U/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.3)
5. wsl安装cuda 10.1

安装太高的cuda似乎是不行的,需要低一点的版本

使用nvcc -V查看是否安装了cuda环境,如果是第一次安装wsl,应该是没有cuda的,需要安装,使用如下命令:

(base) wjx@wang:~$ sudo apt install nvidia-cuda-toolkit

安装完成之后,使用nvcc -V查看cuda版本,我是Ubuntu 20.04 、gcc 9,好像是自动安装了cuda10.1的版本,挺好的,这样子可以运行之前的老仓库内容。

(base) wjx@wang:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

至此,nvidia驱动、gcc、cuda都已经安装好了,然后可以配置软件环境了,需要使用Miniconda,这个轻量化,占用空间小。

6. 新建虚拟环境

下载Miniconda,然后 bash Miniconda3-latest-Linux-x86_64.sh安装,安装到最后,是否初始化,选择yes,然后关闭wsl,重新进入,就可以激活conda环境,这时候用户前面就会显示base,代表是base环境。

conda新建环境就不说了,激活进入新建的环境,就可以配置依赖,之后运行程序了。

8. 安装依赖包

使用pip install -r requirments.txt安装依赖,因为该txt文件中有git+https://github.com/facebookresearch/fvcore.git,可能需要对应的上网环境才可以安装,否则可能报网络错误,例如 TSL、connect错误什么的。

如果出现了opencv-python的问题,那就是版本的问题,使用opencv-python==4.8.1.78这个版本即可。

再之后安装pip install ‘git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI’,这个也需要对应的网络环境,否则也会安装不上。

之后就是构建项目,是最容易出现问题的,使用命令python setup.py build develop,可能会出现很多错误

如果出现如下错误:

subprocess.CalledProcessError: Command ‘[‘which’, ‘g++’]’ returned non-zero exit status 1.

就使用如下命令:

sudo apt-get install build-essential

如果出现了setuptools对应的问题,可以安装setuptools的59.6.0的版本:

pip install setuptools==59.6.0

如果安装setuptools之后还报错如下:

在这里插入图片描述

那就把下面几个也安装了,

pip install absl-py
pip install google-auth
pip install google-auth-oauthlib
pip install grpcio

之后再次build构建项目,应该就不会出现问题了。

9. 运行代码错误
~/py-bottom-up-attention/detectron2/engine/hooks.py in <module>
     15 
     16 import detectron2.utils.comm as comm
---> 17 from detectron2.evaluation.testing import flatten_results_dict
     18 from detectron2.utils.events import EventStorage, EventWriter
     19 

~/py-bottom-up-attention/detectron2/evaluation/__init__.py in <module>
      1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
----> 2 from .cityscapes_evaluation import CityscapesEvaluator
...
---> 80 from types import CellType  # noqa: F401
     81 
     82 

ImportError: cannot import name 'CellType'

使用jupyter运行出现上述错误,需要更换python版本为3.7及以上,3.6会出现这个错误。

OpenCV(3.4.8) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

出现上述这个错误,看到很多博文说是有中文路径错误,实际上也有很大的可能是opencv-python版本的问题,可以使用pip install opencv-python==4.8.1.78该版本就会解决上述问题。

运行的所有历史命令如下
sudo  vim   /etc/apt/sources.list
sudo apt update
sudo apt upgrade
gcc -v
nvidia-smi
nvcc -v
sudo apt-get install gcc-8
nvcc -V
gcc -v
gcc --version
sudo apt-get install gcc-8
gcc-8 -v
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100
gcc -v
dpkg -l | grep gcc
gcc -v
nvidia-smi
nvcc -v
sudo apt install nvidia-cuda-toolkit
nvcc -V
nvidia-smi
ls
gcc -v
g++ -v
cd /mnt/d/
ls
cd ubantu/
ls
bash Miniconda3-latest-Linux-x86_64.sh
conda create -n torch python=3.6 -y
conda activate torch
ls
pip list
git clone https://github.com/airsplay/py-bottom-up-attention.git
cd py-bottom-up-attention/
ls
pip install -r requirements.txt
pip install opencv-python==111
pip install opencv-python==4.0.0.21
pip install -r requirements.txt
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
python setup.py build develop
sudo apt-get install build-essential
conda activate torch
cd /mnt/d/
ls
cd
ls
cd py-bottom-up-attention/
python setup.py build develop
pip list
pip install setuptools==111
pip install setuptools==59.6.0
pip install absl-py
pip install google-auth
pip install google-auth-oauthlib
pip install grpcio
pip install setuptools==59.6.0
python setup.py build develop
code .
pip install jupyter
code .
jupyter notebook
pip install importlib
jupyter notebook
pip list
conda install jupyter notebook
conda activte torch15
conda activate torch15
pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html
pip install opencv-python==4.0.0.21
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
gcc -v
conda activate torch
python
source activate torch
/home/wjx/miniconda3/envs/torch/bin/python /home/wjx/py-bottom-up-attention/test.py
pip list
ls
python setup.py build develop
/home/wjx/miniconda3/envs/torch/bin/python /home/wjx/py-bottom-up-attention/test.py
nvcc -v
nvcc -V
gcc -v
conda create -n torch15 pytyhon=3.6
conda create -n torch15 python=3.6
conda activate torch15
pip list
pip install -r requirements.txt
pip list
pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html
pip install numpy cypython
pip install numpy cython
pip install opencv-python
source activate torch15
/home/wjx/miniconda3/envs/torch15/bin/python /home/wjx/py-bottom-up-attention/test.py
pip install IPython
source activate torch15
/home/wjx/miniconda3/envs/torch15/bin/python /home/wjx/py-bottom-up-attention/test.py
source activate py37
/home/wjx/miniconda3/envs/py37/bin/python /home/wjx/py-bottom-up-attention/test.py
pip install IPython
curl baidu.com
curl google.com
setss
source ~/.zshrc
conda activate torch15
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
vim ~/.zshrc
source .zshrc
setss
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
unsetss
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
cd py-bottom-up-attention/
ls
python setup.py build develop
pip install setuptools
pip install setuptools==111
pip install setuptools==59.6.0
pip install absl-py google-auth google-auth-oauthlib  grpcio
python setup.py build develop
code .
pip install jupyter
jupyter notebook
pip install jupyter==111
pip install jupyter notebook==111
pip uninstall jupyter
python -m pip install jupyter
jupyter notebook
conda install jupyter notebook
jupyter notebook
code .
pip list
nvcc -V
pip install torch==1.5.1 torchvision==0.6.1
pip install torch==1.5.1+cpu torchvision==0.6.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
python
conda create -n py37 python=3.7
conda activate py37
pip install -r requirements.txt
code .
conda install jupyter notebook
conda activate torch
jupyter notebook
source activate py37
/home/wjx/miniconda3/envs/py37/bin/python /home/wjx/py-bottom-up-attention/test.py
python setup.py build develop
pip list
python setup.py build develop/home/wjx/miniconda3/envs/py37/bin/python /home/wjx/py-bottom-up-attention/test.py
source activate py37
/home/wjx/miniconda3/envs/py37/bin/python /home/wjx/py-bottom-up-attention/test.py
source activate torch
/home/wjx/miniconda3/envs/torch/bin/python /home/wjx/py-bottom-up-attention/test.py
source activate torch15
/home/wjx/miniconda3/envs/torch15/bin/python /home/wjx/py-bottom-up-attention/test.py
source activate py
/home/wjx/miniconda3/envs/py/bin/python /home/wjx/py-bottom-up-attention/test.py
python
source activate py
/home/wjx/miniconda3/envs/py/bin/python /home/wjx/py-bottom-up-attention/test.py
pip list
pip install cloudpickle=111
pip install cloudpickle==111
pip install cloudpickle==2.0.0
source activate py
/home/wjx/miniconda3/envs/py/bin/python /home/wjx/py-bottom-up-attention/test.py
pip install IPython
source activate py
/home/wjx/miniconda3/envs/py/bin/python /home/wjx/py-bottom-up-attention/test.py
cd data
ls
git clone https://github.com/peteanderson80/bottom-up-attention.git
source activate py
pip install opencv-python==11
pip list
pip install opencv-python==4.0.0.21
source activate py
pip install -U opencv-python==3.4.4.19
pip install -U opencv-python==311
pip install -U opencv-python==3.4.0.14
pip install -U opencv-python==3.4.9.31
source activate py
pip install opencv-python=3.4.2.17
pip install opencv-python==3.4.2.17
pip install opencv-python==3.4.2.18
pip install opencv-python==3.4.3.18
pwd
pip install opencv-python==3.4.4.19
source activate py
pip install opencv-python==3.4.5.20

原文地址:https://blog.csdn.net/qq_36693723/article/details/135468589

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_53160.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注