今天是初五,民间有破五的习俗,简单来说就是说该工作啦。
回顾研究生毕业的一年半,期间从事过桌面应用开发、CAN\串口开发、无人机目标检测开发、爬虫、数据工程、大数据系统运维等。研究生期间学的深度学习也好久没再接触,自己配的深度学习机器(菜鸟攒机之深度学习(上))(菜鸟攒机之深度学习(下))在家吃灰了好久,当时还是卡皇的GTX 1080也已经被1080 Ti、2080、2080 Ti取代,TensorFlow也从1.8迭代到了2.1,Caffe、MXNet、Torch逐渐退出人们视野,形成TensorFlow、PyTorch双雄争霸的局面,Python2也退出历史舞台,Python3迭代到3.8。随着工作中的不断学习积累,我也从Linux、Python小白中的小白,成长为能够独立处理一些技术问题的中级用户,对Linux、Python也有了一些更深刻的认识。
虽然当前的工作主要集中在数据工程、后端、爬虫,但我还是更喜欢深度学习,那种从Top1 accuracy、Top5 accuracy曲线逐渐上升,Loss曲线逐渐下降带来的心理满足感是别的技术所无法取代的。趁着这两天不忙,打算把家里的机器重新部署一次深度学习环境,并把过程记录下来,希望能帮到更多人。
愿疫情早日结束!!!!!!!!!!!!!
系统环境:
2020-01-29
从Ubuntu官网下载ISO镜像
使用Startup Disk Creator图形化工具制作
如果找不到,则通过
>>> sudo apt install usb-creator-gtk
使用Refus图形化工具
使用Etcher图形化工具
按步骤安装即可
我建议是最小化安装,好多没用的软件如:libreoffice就不会装上去,节省空间
切记在BIOS将secure boot关闭,否则即便安装成功,启动也会出问题。
# 备份
>>> sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 修改为清华源
>>> sudo vi /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
>>> sudo apt update
>>> sudo apt upgrade
>>> sudo add-apt-repository ppa:graphics-drivers/ppa
>>> sudo apt update
>>> sudo ubuntu-drivers autoinstall
>>> nvidia-smi
Wed Jan 29 22:30:34 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.48.02 Driver Version: 440.48.02 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1080 Off | 00000000:01:00.0 On | N/A |
| 0% 36C P8 16W / 260W | 519MiB / 8116MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1206 G /usr/lib/xorg/Xorg 18MiB |
| 0 1252 G /usr/bin/gnome-shell 48MiB |
| 0 1506 G /usr/lib/xorg/Xorg 155MiB |
| 0 1649 G /usr/bin/gnome-shell 133MiB |
| 0 1982 G ...uest-channel-token=10485691146349354111 158MiB |
+-----------------------------------------------------------------------------+
>>> sudo reboot now
官网下载安装包,双击安装,再通过settings→Region&Language→Manage Installed Language将输入法框架从iBus换成fcitx
重新启动
到这里就能切换出搜狗拼音了
如果使用过程中出现候选框乱码现象:
则通过
>>> cd ~/.config
>>> sudo rm -rf SogouPY* sogou*
再注销重启就恢复正常了
ssh分为客户端与服务端
默认安装有客户端openssh-client
想要远程连接到本机,需要安装openssh-server
通过以下命令查看本机ssh相关进程
>>> dpkg -l | grep ssh
ii libssh-gcrypt-4:amd64 0.8.0~20170825.94fa1e38-1ubuntu0.5 amd64 tiny C SSH library (gcrypt flavor)
ii openssh-client 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) client, for secure access to remote machines
>>> sudo apt install openssh-server
>>> dpkg -l | grep ssh
ii libssh-gcrypt-4:amd64 0.8.0~20170825.94fa1e38-1ubuntu0.5 amd64 tiny C SSH library (gcrypt flavor)
ii openssh-client 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) client, for secure access to remote machines
ii openssh-server 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) server, for secure access from remote machines
ii openssh-sftp-server 1:7.6p1-4ubuntu0.3 amd64 secure shell (SSH) sftp server module, for SFTP access from remote machines
ii ssh-import-id 5.7-0ubuntu1.1 all securely retrieve an SSH public key and install it locally
开启、关闭、查看状态
>>> systemctl start sshd.service
>>> systemctl stop sshd.service
>>> systemctl status sshd.service
参考:
https://github.com/JinnLynn/genpac
https://askubuntu.com/questions/60218/how-to-add-a-directory-to-the-path
https://askubuntu.com/questions/799302/ubuntu-cant-find-an-executable-file-in-local-bin
https://www.litcc.com/2016/12/29/Ubuntu16-shadow \
socks-pac/index.html
http://www.phpvar.com/archives/4567.html
关于python3-pip和get-pip.py两种安装方法早有讨论:https://github.com/pypa/pip/issues/5599
目前的结论是,通过apt install python3-pip方式安装的是针对debin系统的pip,版本比较低,目前仅为9.0.1,而通过get-pip.py方式安装的为pypa提供的最新版pip,目前为20.0.2。但大部分人推荐使用python3-pip,而非最新的pip。如果不慎两种方法都安装了,可通过以下命令进行重置:
>>> python3 -m pip uninstall pip setuptools wheel
>>> sudo apt-get --reinstall install python3-setuptools python3-wheel python3-pip
但考虑到加速pip包下载,需要使用高版本pip才有的config功能,因而:
# 升级至最新版
>>> pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -U pip
>>> pip3 --version
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.0.2 from /home/microfat/.local/lib/python3.6/site-packages/pip (python 3.6)
# 通过设置config改变pip源为清华源
>>> pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
默认源:
https://pypi.python.org/simple
配置文件位置:~/.config/pip/pip.conf
参考:https://github.com/pypa/pip/issues/5599#issuecomment-416318017
略
如果在安装oh-my-zsh中存在下载过慢的问题,可通过socks5加速,前提是SS已经部署好了
>>> sh -c "$(curl --socks5 127.0.0.1:1080 -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
CUDA:
>>> sudo sh cuda_10.1.105_418.39_linux.run
│ CUDA Installer │
│ - [ ] Driver │
│ [ ] 418.39 │
│ + [X] CUDA Toolkit 10.1 │
│ [ ] CUDA Samples 10.1 │
│ [X] CUDA Demo Suite 10.1 │
│ [X] CUDA Documentation 10.1 │
│ Install │
│ Options
# 选择Install后
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-10.1/
Samples: Not Selected
Please make sure that
- PATH includes /usr/local/cuda-10.1/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-10.1/lib64, or, add /usr/local/cuda-10.1/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-10.1/bin
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.1/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 418.00 is required for CUDA 10.1 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run --silent --driver
Logfile is /var/log/cuda-installer.log
# 配置路径
>>> vim .zshrc
export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
# 使生效
>>> source .zshrc
# 检查是否安装成功
>>> nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Fri_Feb__8_19:08:17_PST_2019
Cuda compilation tools, release 10.1, V10.1.105
cuDNN:
# 解压
>>> tar -xzvf cudnn-10.1-linux-x64-v7.6.5.32.tgz
cuda/include/cudnn.h
cuda/NVIDIA_SLA_cuDNN_Support.txt
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.7
cuda/lib64/libcudnn.so.7.6.5
cuda/lib64/libcudnn_static.a
# 复制
>>> sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
>>> sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
# 修改权限
>>> cd /usr/local/cuda/lib64
>>> sudo chmod +r libcudnn.so.7.6.5
>>> sudo ln -sf libcudnn.so.7.6.5 libcudnn.so.7
>>> sudo ln -sf libcudnn.so.7 libcudnn.so
>>> sudo ldconfig
参考:https://blog.csdn.net/xinjieyuan/article/details/100667803
>>> pip3 install tensorflow-gpu
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting tensorflow-gpu
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0a/93/c7bca39b23aae45cd2e85ad3871c81eccc63b9c5276e926511e2e5b0879d/tensorflow_gpu-2.1.0-cp36-cp36m-manylinux2010_x86_64.whl (421.8 MB)
|████████████████████████████████| 421.8 MB 7.7 kB/s
Requirement already satisfied: six>=1.12.0 in /home/microfat/.local/lib/python3.6/site-packages (from tensorflow-gpu) (1.14.0)
Collecting grpcio>=1.8.6
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/17/8f/f79c5c174bebece41f824dd7b1ba98da45dc2d4c373b38ac6a7f6a5acb5e/grpcio-1.26.0-cp36-cp36m-manylinux2010_x86_64.whl (2.4 MB)
|████████████████████████████████| 2.4 MB 6.9 MB/s
Requirement already satisfied: wheel>=0.26; python_version >= "3" in /usr/lib/python3/dist-packages (from tensorflow-gpu) (0.30.0)
Requirement already satisfied: numpy<2.0,>=1.16.0 in /home/microfat/.local/lib/python3.6/site-packages (from tensorflow-gpu) (1.18.1)
Collecting google-pasta>=0.1.6
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c3/fd/1e86bc4837cc9a3a5faf3db9b1854aa04ad35b5f381f9648fbe81a6f94e4/google_pasta-0.1.8-py3-none-any.whl (57 kB)
|████████████████████████████████| 57 kB 5.1 MB/s
Collecting astor>=0.6.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c3/88/97eef84f48fa04fbd6750e62dcceafba6c63c81b7ac1420856c8dcc0a3f9/astor-0.8.1-py2.py3-none-any.whl (27 kB)
Collecting opt-einsum>=2.3.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b8/83/755bd5324777875e9dff19c2e59daec837d0378c09196634524a3d7269ac/opt_einsum-3.1.0.tar.gz (69 kB)
|████████████████████████████████| 69 kB 4.9 MB/s
Collecting wrapt>=1.11.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/67/b2/0f71ca90b0ade7fad27e3d20327c996c6252a2ffe88f50a95bba7434eda9/wrapt-1.11.1.tar.gz (27 kB)
Collecting keras-preprocessing>=1.1.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/28/6a/8c1f62c37212d9fc441a7e26736df51ce6f0e38455816445471f10da4f0a/Keras_Preprocessing-1.1.0-py2.py3-none-any.whl (41 kB)
|████████████████████████████████| 41 kB 2.8 MB/s
ERROR: Could not find a version that satisfies the requirement tensorboard<2.2.0,>=2.1.0 (from tensorflow-gpu) (from versions: 1.0.0a3, 1.0.0a4, 1.0.0a5, 1.0.0a6, 1.6.0rc0, 1.6.0, 1.7.0, 1.8.0, 1.9.0, 1.10.0, 1.11.0, 1.12.0, 1.12.1, 1.12.2, 1.13.0, 1.13.1, 1.14.0, 1.15.0, 2.0.0, 2.0.1, 2.0.2)
ERROR: No matching distribution found for tensorboard<2.2.0,>=2.1.0 (from tensorflow-gpu)
出现错误是因为前文修改了pip的源为清华源,而源中缺少tensorboard对应版本,因而需要改回官方源
>>> pip3 config set global.index-url https://pypi.python.org/simple
# 为避免安装过程中出现
ERROR: launchpadlib 1.10.6 requires testresources, which is not installed.
>>> sudo apt install python3-testresources
# 使用proxyc加速
>>> p104 pip3 install tensorflow-gpu
...
Successfully installed absl-py-0.9.0 astor-0.8.1 cachetools-4.0.0 gast-0.2.2 google-auth-1.11.0 google-auth-oauthlib-0.4.1 google-pasta-0.1.8 grpcio-1.26.0 h5py-2.10.0 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.1.1 oauthlib-3.1.0 opt-einsum-3.1.0 protobuf-3.11.2 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.22.0 requests-oauthlib-1.3.0 rsa-4.0 scipy-1.4.1 setuptools-45.1.0 tensorboard-2.1.0 tensorflow-estimator-2.1.0 tensorflow-gpu-2.1.0 termcolor-1.1.0 werkzeug-0.16.1 wrapt-1.11.2
# 测试
>>> ipython
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.11.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import tensorflow as tf
2020-01-31 21:43:18.502434: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda-10.1/lib64
2020-01-31 21:43:18.502499: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda-10.1/lib64
2020-01-31 21:43:18.502507: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
In [2]: tf.__version__
Out[2]: '2.1.0'
In [3]: exit
参考:https://www.discoverbits.in/864/error-launchpadlib-requires-testresources-which-installed
>>> ipython
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.11.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import torch
In [2]: torch.__version__
Out[2]: '1.4.0'
In [3]: exit
安装必要的依赖:
>>> sudo apt install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
>>> sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev libavresample-dev
>>> sudo apt install libxvidcore-dev libx264-dev libx265-dev
>>> sudo apt install libatlas-base-dev gfortran
>>> sudo apt-get --reinstall install ffmpeg
# 如果已经安装SS,可使用下面命令加速git clone
>>> git config --global https.proxy 'socks5://127.0.0.1:1080'
>>> git config --global http.proxy 'socks5://127.0.0.1:1080'
>>> git clone https://github.com/opencv/opencv.git
>>> cd opencv
>>> git clone https://github.com/opencv/opencv_contrib.git
>>> mkdir build
>>> cd build
>>> p104 cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_GENERATE_PKGCONFIG=ON \ # 安装darknet时需要
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_OPENGL=ON \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D CUDA_NVCC_FLAGS="-D_FORCE_INLINES" \
-D WITH_CUBLAS=1 \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..
-- Failed to download NVIDIA_Optical_Flow_1_0 Headers
--
-- General configuration for OpenCV 4.2.0-dev =====================================
-- Version control: 4.2.0-216-g0dd1ce1a4f
--
-- Extra modules:
-- Location (extra): /home/microfat/Git/opencv/opencv_contrib/modules
-- Version control (extra): 4.2.0-21-ge8916dae
--
-- Platform:
-- Timestamp: 2020-02-04T14:21:02Z
-- Host: Linux 5.3.0-28-generic x86_64
-- CMake: 3.10.2
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: RELEASE
--
-- CPU/HW features:
-- Baseline: SSE SSE2 SSE3
-- requested: SSE3
-- Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
-- requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
-- SSE4_1 (15 files): + SSSE3 SSE4_1
-- SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2
-- FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
-- AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
-- AVX2 (29 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
-- AVX512_SKX (6 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
-- C/C++:
-- Built as dynamic libs?: YES
-- C++ Compiler: /usr/bin/c++ (ver 7.4.0)
-- C++ flags (Release): -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
-- C Compiler: /usr/bin/cc
-- C flags (Release): -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release): -Wl,--gc-sections -Wl,--as-needed
-- Linker flags (Debug): -Wl,--gc-sections -Wl,--as-needed
-- ccache: NO
-- Precompiled headers: NO
-- Extra dependencies: m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu
-- 3rdparty dependencies:
--
-- OpenCV modules:
-- To be built: aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: cnn_3dobj cvv gapi hdf java js matlab ovis python2 sfm viz xfeatures2d
-- Applications: tests perf_tests apps
-- Documentation: NO
-- Non-free algorithms: NO
--
-- GUI:
-- GTK+: YES (ver 2.24.32)
-- GThread : YES (ver 2.56.4)
-- GtkGlExt: NO
-- OpenGL support: NO
-- VTK support: NO
--
-- Media I/O:
-- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
-- JPEG: libjpeg-turbo (ver 2.0.2-62)
-- WEBP: build (ver encoder: 0x020e)
-- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.34)
-- TIFF: build (ver 42 - 4.0.10)
-- JPEG 2000: build (ver 1.900.1)
-- OpenEXR: build (ver 2.3.0)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- DC1394: NO
-- FFMPEG: YES
-- avcodec: YES (57.107.100)
-- avformat: YES (57.83.100)
-- avutil: YES (55.78.100)
-- swscale: YES (4.8.100)
-- avresample: YES (3.7.0)
-- GStreamer: NO
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: pthreads
--
-- Trace: YES (with Intel ITT)
--
-- Other third-party libraries:
-- Lapack: YES (/usr/lib/x86_64-linux-gnu/liblapack.so /usr/lib/x86_64-linux-gnu/libcblas.so /usr/lib/x86_64-linux-gnu/libatlas.so)
-- Eigen: NO
-- Custom HAL: NO
-- Protobuf: build (3.5.1)
--
-- NVIDIA CUDA: YES (ver 10.1, CUFFT CUBLAS FAST_MATH)
-- NVIDIA GPU arch: 30 35 37 50 52 60 61 70 75
-- NVIDIA PTX archs:
--
-- cuDNN: YES (ver 7.6.5)
--
-- OpenCL: YES (no extra features)
-- Include path: /home/microfat/Git/opencv/3rdparty/include/opencl/1.2
-- Link libraries: Dynamic load
--
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.6.9)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.6m.so (ver 3.6.9)
-- numpy: /home/microfat/.local/lib/python3.6/site-packages/numpy/core/include (ver 1.18.1)
-- install path: lib/python3.6/dist-packages/cv2/python-3.6
--
-- Python (for build): /usr/bin/python3
--
-- Java:
-- ant: NO
-- JNI: NO
-- Java wrappers: NO
-- Java tests: NO
--
-- Install to: /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/microfat/Git/opencv/build
# 确认相关文件是否下载成功
>>> cd opencv/.cache
.cache
│
└───xfeatures2d
├───boostdesc
│ 0ae0675534aa318d9668f2a179c2a052-boostdesc_lbgm.i
│ 0ea90e7a8f3f7876d450e4149c97c74f-boostdesc_bgm.i
│ 202e1b3e9fec871b04da31f7f016679f-boostdesc_binboost_064.i
│ 232c966b13651bd0e46a1497b0852191-boostdesc_bgm_bi.i
│ 324426a24fa56ad9c5b8e3e0b3e5303e-boostdesc_bgm_hd.i
│ 98ea99d399965c03d555cef3ea502a0b-boostdesc_binboost_128.i
│ e6dcfa9f647779eb1ce446a8d759b6ea-boostdesc_binboost_256.i
│
└───vgg
151805e03568c9f490a5e3a872777b75-vgg_generated_120.i
7126a5d9a8884ebca5aea5d63d677225-vgg_generated_64.i
7cd47228edec52b6d82f46511af325c5-vgg_generated_80.i
e8d0dcd54d1bcfdc29203d011a797179-vgg_generated_48.i
>>> make -j8 # 开启8线程,默认单线程
>>> sudo make install
参考:
https://github.com/opencv/opencv_contrib/issues/1301#issuecomment-318639639
https://blog.csdn.net/Felaim/article/details/103971397
>>> git clone https://github.com/AlexeyAB/darknet.git
>>> cd darknet
>>> vim Makefile
GPU=1
CUDNN=1
CUDNN_HALF=0
OPENCV=1
AVX=1
OPENMP=1
LIBSO=1
ZED_CAMERA=0
# 从OpenCV4开始,opencv.pc文件改名为opencv4.pc,而darknet默认找opencv.pc文件,因而会报错
>>> make
chmod +x *.sh
g++ -std=c++11 -Iinclude/ -I3rdparty/stb/include -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC -ffp-contract=fast -mavx -mavx2 -msse3 -msse4.1 -msse4.2 -msse4a -Ofast -DOPENCV -fopenmp -DGPU -DCUDNN -I/usr/local/cudnn/include -fPIC -c ./src/image_opencv.cpp -o obj/image_opencv.o
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
./src/image_opencv.cpp:15:10: fatal error: opencv2/core/version.hpp: No such file or directory
#include
^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:159: recipe for target ' obj/image_opencv.o' failed
make: *** [obj/image_opencv.o] Error 1
# 需要将其进行重命名
>>> cd /usr/local/lib/pkgconfig
>>> cp opencv4.pc opencv.pc
测试:
# 下载测试图片、weights
>>> mkdir test
>>> mkdir weights
>>> cd test
>>> wget https://github.com/pjreddie/darknet/blob/master/data/dog.jpg
>>> cd ..
>>> cd weights
>>> wget https://pjreddie.com/media/files/yolov3.weights
>>> cd ..
>>> ./darknet detector test ./cfg/coco.data ./cfg/yolov3.cfg ./weights/yolov3.weights
...
Total BFLOPS 100.606
avg_outputs = 1126963
Allocate additional workspace_size = 52.43 MB
Loading weights from ./weights/csresnext50-panet-spp-original-optimal_final.weights...
seen 64, trained: 32032 K-images (500 Kilo-batches_64)
Done! Loaded 138 layers from weights-file
Enter Image Path: ./test/dog.jpg