版本介绍:
电脑:笔记本
显卡:RTX3050
ubuntu:20.04
cuda:11.6.2
cudnn:8.4.1
ffmpeg:4.4.3
opencv:4.5.5
darknet-master:yolo-v4
TensorRT:8.4.3.1
python:3.8
pytorch:1.12.1
MySql:8.24
开始配置
sudo apt update
sudo apt upgrade
sudo apt install build-essential \
cmake \
mlocate \
git \
python3-pip
图形界面相关
sudo apt install lightdm
注:在弹出对话框选择"lightdm"
网址
https://developer.nvidia.com/cuda-toolkit-archive
依次点击
在"Installation Instructions:"下方为下载安装指令
下载指令(文件需下载到英文路径)
wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run
安装指令
sudo sh cuda_11.6.2_510.47.03_linux.run
sudo apt remove --purge nvidia*
sudo cp /etc/modprobe.d/blacklist.conf /etc/modprobe.d/blacklist.conf.backup
sudo gedit /etc/modprobe.d/blacklist.conf
在文件末尾添加如下内容
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
保存后关闭文件
echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
sudo update-initramfs -u
reboot
执行以下内容,没有任何输出内容则为成功禁用
lsmod | grep nouveau
注:进入界面后先登陆,先输入本机名回车后输入密码即可(小键盘不可用)
sudo service lightdm stop
cd /home/heqingchun/softWare/files/CUDA
chmod 755 cuda_11.6.2_510.47.03_linux.run
sudo sh cuda_11.6.2_510.47.03_linux.run
注:期间会弹出对话框,需手动输入"accept"回车,之后再弹出对话框向下选择"install"后等待安装完毕即可,安装完毕后驱动也一起装完了
sudo service lightdm start && reboot
注:
1.需要bios禁用安全启动
2.重启的时候如果电脑可切换独显与混合显示模式需要切换到独显直连
sudo gedit /etc/profile
在文件最后加上以下内容
export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
source /etc/profile
reboot
nvcc -V
显示如下:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_Mar__8_18:18:20_PST_2022
Cuda compilation tools, release 11.6, V11.6.124
Build cuda_11.6.r11.6/compiler.31057947_0
cat /usr/local/cuda/version.json
显示如下:
{
"cuda" : {
"name" : "CUDA SDK",
"version" : "11.6.20220318"
},
"cuda_cccl" : {
"name" : "CUDA C++ Core Compute Libraries",
"version" : "11.6.55"
},
"cuda_cudart" : {
"name" : "CUDA Runtime (cudart)",
"version" : "11.6.55"
},
"cuda_cuobjdump" : {
"name" : "cuobjdump",
"version" : "11.6.124"
},
"cuda_cupti" : {
"name" : "CUPTI",
"version" : "11.6.124"
},
"cuda_cuxxfilt" : {
"name" : "CUDA cu++ filt",
"version" : "11.6.124"
},
"cuda_demo_suite" : {
"name" : "CUDA Demo Suite",
"version" : "11.6.55"
},
"cuda_gdb" : {
"name" : "CUDA GDB",
"version" : "11.6.124"
},
"cuda_memcheck" : {
"name" : "CUDA Memcheck",
"version" : "11.6.124"
},
"cuda_nsight" : {
"name" : "Nsight Eclipse Plugins",
"version" : "11.6.124"
},
"cuda_nvcc" : {
"name" : "CUDA NVCC",
"version" : "11.6.124"
},
"cuda_nvdisasm" : {
"name" : "CUDA nvdisasm",
"version" : "11.6.124"
},
"cuda_nvml_dev" : {
"name" : "CUDA NVML Headers",
"version" : "11.6.55"
},
"cuda_nvprof" : {
"name" : "CUDA nvprof",
"version" : "11.6.124"
},
"cuda_nvprune" : {
"name" : "CUDA nvprune",
"version" : "11.6.124"
},
"cuda_nvrtc" : {
"name" : "CUDA NVRTC",
"version" : "11.6.124"
},
"cuda_nvtx" : {
"name" : "CUDA NVTX",
"version" : "11.6.124"
},
"cuda_nvvp" : {
"name" : "CUDA NVVP",
"version" : "11.6.124"
},
"cuda_samples" : {
"name" : "CUDA Samples",
"version" : "11.6.101"
},
"cuda_sanitizer_api" : {
"name" : "CUDA Compute Sanitizer API",
"version" : "11.6.124"
},
"libcublas" : {
"name" : "CUDA cuBLAS",
"version" : "11.9.2.110"
},
"libcufft" : {
"name" : "CUDA cuFFT",
"version" : "10.7.2.124"
},
"libcurand" : {
"name" : "CUDA cuRAND",
"version" : "10.2.9.124"
},
"libcusolver" : {
"name" : "CUDA cuSOLVER",
"version" : "11.3.4.124"
},
"libcusparse" : {
"name" : "CUDA cuSPARSE",
"version" : "11.7.2.124"
},
"libnpp" : {
"name" : "CUDA NPP",
"version" : "11.6.3.124"
},
"libnvjpeg" : {
"name" : "CUDA nvJPEG",
"version" : "11.6.2.124"
},
"nsight_compute" : {
"name" : "Nsight Compute",
"version" : "2022.1.1.2"
},
"nsight_systems" : {
"name" : "Nsight Systems",
"version" : "2021.5.2.53"
},
"nvidia_driver" : {
"name" : "NVIDIA Linux Driver",
"version" : "510.47.03"
}
}
cd /usr/local/cuda/extras/demo_suite
./deviceQuery
显示:
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.6, CUDA Runtime Version = 11.6, NumDevs = 1, Device0 = NVIDIA GeForce RTX 3050 Laptop GPU
Result = PASS
到这里显卡驱动与cuda安装完毕
网址
https://developer.nvidia.com/rdp/cudnn-archive
依次点击
注:需要登陆,登陆成功后即可下载
cd /home/heqingchun/softWare/files/CUDA
tar -xvf cudnn-linux-x86_64-8.4.1.50_cuda11.6-archive.tar.xz
cd cudnn-linux-x86_64-8.4.1.50_cuda11.6-archive
sudo cp include/* /usr/local/cuda-11.6/include && \
sudo cp -P lib/* /usr/local/cuda-11.6/lib64 && \
sudo chmod a+r /usr/local/cuda-11.6/include/cudnn*.h /usr/local/cuda-11.6/lib64/libcudnn*
与cuda同环境
cat /usr/local/cuda/include/cudnn_version.h
显示如下:
/**
* \file: The master cuDNN version file.
*/
#ifndef CUDNN_VERSION_H_
#define CUDNN_VERSION_H_
#define CUDNN_MAJOR 8
#define CUDNN_MINOR 4
#define CUDNN_PATCHLEVEL 1
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#endif /* CUDNN_VERSION_H */
到这里cudnn安装完毕
网址
http://ffmpeg.org/download.html#releases
点击
FFmpeg 4.4.3 “Rao"下的"Download xz tarball”
SDK头文件
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make
sudo make install
sudo apt install gnutls-dev \
libass-dev \
libdrm-dev \
libopus-dev \
libpulse-dev \
libspeex-dev \
libtheora-dev \
libtwolame-dev \
libv4l-dev \
libvorbis-dev \
libvpx-dev \
libx264-dev \
libx265-dev \
libxvidcore-dev \
libopenal-dev \
libomxil-bellagio-dev \
libxcb1-dev \
libsdl2-dev \
libva-dev \
libvdpau-dev
libfdk_aac
下载网址
https://www.linuxfromscratch.org/blfs/view/svn/multimedia/fdk-aac.html
解压
tar -xvf fdk-aac-2.0.2.tar.gz
编译安装
cd fdk-aac-2.0.2 && \
./configure --prefix=/usr --disable-static && \
make -j12 && \
sudo make install
libmp3lame
下载网址
https://sourceforge.net/projects/lame/files/lame/3.99/
解压
tar -xvf lame-3.99.5.tar.gz
编译安装
cd lame-3.99.5 && \
./configure --prefix=/usr --disable-static && \
make -j12 && \
sudo make install
libopencore_amrnb
下载网址
https://sourceforge.net/projects/opencore-amr/files/opencore-amr/
解压
tar -xvf opencore-amr-0.1.6.tar.gz
编译安装
cd opencore-amr-0.1.6 && \
./configure --prefix=/usr --disable-static && \
make -j12 && \
sudo make install
cd /home/heqingchun/softWare/files/ffmpeg && \
tar -xvf ffmpeg-4.4.3.tar.xz && \
cd ffmpeg-4.4.3
gedit configure
找到
nvccflags_default="-gencode arch=compute_30,code=sm_30 -O2"
改为
nvccflags_default="-gencode arch=compute_86,code=sm_86 -O2"
保存退出
注:75为显卡算力,根据自己的显卡输入即可,查看点这里
./configure --prefix=/usr/local/ffmpeg \
--disable-debug \
--disable-doc \
--disable-static \
--enable-cuda-nvcc \
--enable-cuvid \
--enable-libdrm \
--enable-ffplay \
--enable-gnutls \
--enable-gpl \
--enable-libass \
--enable-libfdk-aac \
--enable-libfontconfig \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libnpp \
--enable-libopencore_amrnb \
--enable-libopencore_amrwb \
--enable-libopus \
--enable-libpulse \
--enable-sdl2 \
--enable-libspeex \
--enable-libtheora \
--enable-libtwolame \
--enable-libv4l2 \
--enable-libvorbis \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-libxcb \
--enable-libxvid \
--enable-nonfree \
--enable-nvenc \
--enable-omx \
--enable-openal \
--enable-opencl \
--enable-runtime-cpudetect \
--enable-shared \
--enable-vaapi \
--enable-vdpau \
--enable-version3 \
--enable-xlib \
--extra-cflags=-I/usr/local/cuda/include \
--extra-ldflags=-L/usr/local/cuda/lib64 \
--libdir=/usr/lib/x86_64-linux-gnu \
--incdir=/usr/include/x86_64-linux-gnu \
--disable-asm \
--disable-x86asm \
--extra-cflags=-fPIC \
--toolchain=hardened \
--disable-stripping \
--extra-cflags=-I/usr/local/include/ffnvcodec
make -j12
sudo make install
sudo ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/bin/ffmpeg && \
sudo ln -s /usr/local/ffmpeg/bin/ffprobe /usr/bin/ffprobe && \
sudo ln -s /usr/local/ffmpeg/bin/ffplay /usr/bin/ffplay && \
sudo ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/local/bin/ffmpeg && \
sudo ln -s /usr/local/ffmpeg/bin/ffprobe /usr/local/bin/ffprobe && \
sudo ln -s /usr/local/ffmpeg/bin/ffplay /usr/local/bin/ffplay
打开文件
sudo gedit /etc/ld.so.conf.d/ffmpeg.conf
修改文件
/usr/local/ffmpeg/lib
保存更新
sudo ldconfig
查看支持的硬件加速选项
ffmpeg -hwaccels
显示如下:
Hardware acceleration methods:
vdpau
cuda
vaapi
drm
opencl
测试:
HEVC->H.264
ffmpeg -vcodec hevc_cuvid -an -gpu 0 -i -vcodec h264_nvenc -an -gpu 0 -y output.mp4
H.264->HEVC
ffmpeg -vcodec h264_cuvid -an -gpu 0 -i -vcodec hevc_nvenc -an -gpu 0 -y output.mp4
到这里ffmpeg安装完毕
网址
https://github.com/opencv
下载"opencv-4.5.5.zip"与"opencv_contrib-4.5.5.zip"
解压&整理
unzip opencv-4.5.5.zip && \
unzip opencv_contrib-4.5.5.zip && \
mv opencv_contrib-4.5.5 opencv-4.5.5 && \
文件存放路径
mkdir /home/heqingchun/opencv_cmake_download_files
cd opencv_cmake_download_files
1、
wget https://github.com/opencv/ade/archive/refs/tags/v0.1.1f.zip
2、
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i && \
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i && \
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i && \
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i && \
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i
3、
wget https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/a8b69ccc738421293254aec5ddb38bd523503252/detect.caffemodel && \
wget https://raw.githubusercontent.com/WeChatCV/opencv_3rdparty/a8b69ccc738421293254aec5ddb38bd523503252/detect.prototxt
4、
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/8afa57abc8229d611c4937165d20e2a2d9fc5a12/face_landmark_model.dat
5、
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_win_intel64_20191018_general.zip
6、
wget https://github.com/NVIDIA/NVIDIAOpticalFlowSDK/archive/edb50da3cf849840d680249aa6dbef248ebce2ca.zip
7、
wget https://github.com/01org/tbb/archive/v2020.2.tar.gz
8、
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i && \
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i && \
wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i
gtk
sudo apt install libgtk2.0-dev \
libcanberra-gtk-module
opengl
sudo apt install libgl1-mesa-dev \
libglew-dev \
libsdl2-dev \
libsdl2-image-dev \
libglm-dev \
libfreetype6-dev \
libglfw3-dev \
libglfw3 \
libglu1-mesa-dev \
freeglut3-dev \
libgtkglext1 \
libgtkglext1-dev
gstreamer
sudo apt install libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-bad1.0-dev \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
gstreamer1.0-doc \
gstreamer1.0-tools \
gstreamer1.0-x \
gstreamer1.0-alsa \
gstreamer1.0-gl \
gstreamer1.0-gtk3 \
gstreamer1.0-qt5 \
gstreamer1.0-pulseaudio
下载文件
https://developer.nvidia.com/nvidia-video-codec-sdk
依次点击" Get Started "、“I Agree to the Terms of the”、“DOWNLOAD NOW”
下载"Video_Codec_SDK_12.0.16.zip"文件
解压文件
unzip Video_Codec_SDK_12.0.16
复制文件
cd Video_Codec_SDK_12.0.16/Interface
sudo cp cuviddec.h nvcuvid.h nvEncodeAPI.h /usr/include
修改文件
opencv-4.5.5/cmake/OpenCVDetectCUDA.cmake文件中
PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}"
改为
PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}" "/usr/include"
将下列文件中网络路径改为前面下载文件的路径
opencv-4.5.5/modules/gapi/cmake/DownloadADE.cmake
opencv-4.5.5/opencv_contrib-4.5.5/modules/xfeatures2d/cmake/download_boostdesc.cmake
opencv-4.5.5/opencv_contrib-4.5.5/modules/wechat_qrcode/CMakeLists.txt
opencv-4.5.5/opencv_contrib-4.5.5/modules/face/CMakeLists.txt
opencv-4.5.5/3rdparty/ippicv/ippicv.cmake
opencv-4.5.5/opencv_contrib-4.5.5/modules/cudaoptflow/CMakeLists.txt
opencv-4.5.5/3rdparty/tbb/CMakeLists.txt
opencv-4.5.5/opencv_contrib-4.5.5/modules/xfeatures2d/cmake/download_vgg.cmake
如:
opencv-4.5.5/modules/gapi/cmake/DownloadADE.cmake中
"https://github.com/opencv/ade/archive/"
改为
"file:/home/heqingchun/opencv_cmake_download_files/"
cmake -D CMAKE_INSTALL_PREFIX=/usr/local \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_opencv_world=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_EXAMPLES=ON \
-D ENABLE_FAST_MATH=ON \
-D BUILD_ITT=OFF \
-D WITH_ITT=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.5/modules \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_GTK_2_X=ON \
-D WITH_OPENGL=ON \
-D WITH_VTK=ON \
-D WITH_OPENCL=ON \
-D WITH_V4L=ON \
-D BUILD_TBB=ON \
-D WITH_TBB=ON \
-D WITH_OPENMP=ON \
-D OPENCV_DNN_CUDA=ON \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=8.6 \
-D CUDA_ARCH_PTX=8.6 \
-D CUDA_FAST_MATH=1 \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-D WITH_CUDNN=ON \
-D WITH_NVCUVID=ON \
-D WITH_CUBLAS=ON \
..
其中
-D CUDA_ARCH_BIN=8.6
-D CUDA_ARCH_PTX=8.6
需要按照自己显卡的算力来填写
make -j12
sudo make install
打开文件
sudo gedit /etc/ld.so.conf.d/opencv.conf
修改文件
/usr/local/lib
保存退出&更新
sudo ldconfig
打开文件
sudo gedit /etc/profile
修改文件
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存更新
source /etc/profile
打开文件
/etc/ld.so.conf
修改文件
/usr/local/lib
保存更新
sudo ldconfig
pkg-config --modversion opencv4
显示如下:
4.5.5
到这里opencv安装完毕
以下待更新:
darknet-master:yolo-v4
TensorRT:8.4.3.1
python:3.8
pytorch:1.12.1
MySql:8.24