Python3.7+nvidia-470+cuda11.4+cuDNN+Anaconda3++pytorch1.11
搞了三天,问题一是pytorch1.11,安装要用国内源,二是不熟悉conda环境
安装Python3.7的参考教程
下载网址安装包
sudo cp -r /当前目录/Python-3.7.0 /usr/local/python
cd /usr/local/python/Python-3.7.0
sudo ./configure
sudo make
sudo make install
问题:ModuleNotFoundError: No module named ‘_ctypes
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev
ubuntu-drivers devices
系统推荐:driver : nvidia-driver-470 - distro non-free recommended
点击附加驱动对应的驱动左侧,应用更改。
reboot
重启时进入 perform mok management 界面,选择第二个 enroll mok,选择continue,再选择yes,输入之前的 secure boot 密码。
nvidia-smi//用于支持driver API的必要文件(如libcuda.so)是由GPU driver installer安装的。
nvcc -V//用于支持runtime API的必要文件(如libcudart.so以及nvcc)是由CUDA Toolkit installer安装的。
CUDA Toolkit 11.4 Update 4 Downloads
按照官方一步步来:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.4.4/local_installers/cuda-repo-ubuntu1804-11-4-local_11.4.4-470.82.01-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-11-4-local_11.4.4-470.82.01-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu1804-11-4-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
sudo gedit /etc/profile
文末添加:
export CUDA_HOME=/usr/local/cuda
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source /etc/profile
sudo gedit ~/.bashrc
文末添加:
### cuda path
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
source ~/.bashrc
sudo gedit /etc/ld.so.conf
文末添加:
/usr/local/cuda/lib64
sudo ldconfig
nvcc -V
此时和nvidia-smi的cuda一致。
可能注册有点麻烦,但是过程很简单啦,版本就是一一对应的。
Download cuDNN v8.2.4 (September 2nd, 2021), for CUDA 11.4
sudo cp cuda/lib64/* /usr/local/cuda/lib64
sudo cp cuda/include/* /usr/local/cuda/include
cat /usr/local/cuda/include/cudnn_version.h
我也踩了cudnn_version.h的雷,要使用/*全部复制。
这个步骤没问题,要选好自己的版本,我的后来提示更新,已换conda 4.12.0
查看安装版本
我的版本是:Anaconda3-2021.05-Linux-x86_64.sh
注意:1. 看过几个教程,还是建议安装带2021.05这类时间字样的版本。2. x86 是32位,x86_64 和 x64 以及AMD64 是64位。
下载
安装目录下bash
lanc@lanc-Y7000P:~/下载$ bash '/home/lanc/下载/Anaconda3-2021.05-Linux-x86_64.sh'
记录安装位置:/home/lanc/anaconda3
我也不知道有什么用,某个教程的建议。
查看版本
conda --version
版本:conda 4.10.1
Ubuntu打开终端时自动退出 base 虚拟环境命令
进入环境:
conda activate
conda activate
conda create -n pytorch python=3.7
conda activate pytorch
查看安装版本
添加源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
安装:
conda install pytorch torchvision torchaudio cudatoolkit=11.3
下载yolov5
conda activate
conda create -n yolov5 python=3.7
conda activate yolov5
pip3 install -r requirements.txt
python3 detect.py
会自动加载yolov5s.pt,可以暂不下载权重文件
python detect.py --source 0 # 笔记本相机
file.jpg # image
file.mp4 # video
path/ # directory
path/*.jpg # glob
'https://youtu.be/NUsoVlDFqZg' # YouTube video
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
ERROR: Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-build-tkzbit6g/opencv-python/
解决方式
ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
launchpadlib 1.10.6 requires testresources, which is not installed.
解决方式
只存了EuRoC数据集,如图:
–view-img 可视化结果 对于视频可以逐帧检测图标
–save-txt 存储实验结果至txt文件, 类别+两个顶点坐标
–save-conf 在上述txt文件中添加置信度
–nosave 不存储视频和图片
一些会用到的参数