1. Install NCNN
Official website: NCNN Official Documentation
On Debian, Ubuntu or Raspberry Pi OS, you can install all required dependencies using:
First install the dependencies of NCNN, and install the following dependencies according to the official website.
sudo apt install build-essential git cmake libprotobuf-dev protobuf-compiler libvulkan-dev vulkan-utils libopencv-dev
Then start installing NCNN and download the ncnn package from github:
git clone --depth=1 https://github.com/Tencent/ncnn.git
cd to the location of the downloaded ncnn package, such as (cd /home/user-linux/ncnn), create a build folder and enter this folder.
cd ncnn
mkdir build
cd build
If you don’t compile vulkan, set DNCNN_VULKAN=OFF. Generally speaking, you don’t need to. If you want to compile vulkan, you also need to download libvulkan-dev vulkan-utils (although the official website directly includes all of them). If your hardware device supports GPU, you can consider downloading vulka, otherwise Just set DNCNN_VULKAN=OFF.
cmake -DNCNN_VULKAN=OFF ..
Start compiling and installing.
make -j8
make install
The files of ncnn are all installed in the install under build. If you need to copy to /usr/local to execute the following command, generally manual installation will do such an operation, which is convenient for subsequent calls. (easy to find location)
sudo mkdir /usr/local/lib/ncnn
sudo cp -r install/include/ncnn /usr/local/include/ncnn
sudo cp -r install/lib/libncnn.a /usr/local/lib/ncnn/libncnn.a
At this point, the installation of ncnn has been completed. Test whether NCNN is available:
cd ../examples
../build/examples/squeezenet ../images/256-ncnn.png
# 得到输出
532 = 0.165951
920 = 0.094098
716 = 0.062193
cd ../benchmark
../build/benchmark/benchncnn 10 $(nproc) 0 0
# 输出
loop_count = 10
num_threads = 8
powersave = 0
gpu_device = 0
cooling_down = 1
squeezenet min = 2.89 max = 3.19 avg = 2.98
squeezenet_int8 min = 5.37 max = 8.72 avg = 5.93
mobilenet min = 3.75 max = 4.26 avg = 3.91
mobilenet_int8 min = 5.91 max = 6.08 avg = 5.98
mobilenet_v2 min = 3.51 max = 4.31 avg = 3.83
mobilenet_v3 min = 3.09 max = 3.70 avg = 3.22
shufflenet min = 3.03 max = 3.26 avg = 3.10
shufflenet_v2 min = 2.51 max = 2.81 avg = 2.59
mnasnet min = 3.42 max = 3.90 avg = 3.66
proxylessnasnet min = 3.73 max = 4.26 avg = 3.88
efficientnet_b0 min = 5.86 max = 10.86 avg = 6.76
efficientnetv2_b0 min = 6.66 max = 7.58 avg = 7.00
regnety_400m min = 7.83 max = 12.75 avg = 8.52
blazeface min = 0.89 max = 0.96 avg = 0.91
googlenet min = 10.47 max = 11.00 avg = 10.85
googlenet_int8 min = 19.94 max = 20.60 avg = 20.11
resnet18 min = 8.22 max = 28.34 avg = 10.50
resnet18_int8 min = 18.58 max = 53.93 avg = 22.29
alexnet min = 8.48 max = 41.33 avg = 14.13
vgg16 min = 46.46 max = 54.78 avg = 49.38
vgg16_int8 min = 48.13 max = 61.21 avg = 50.25
resnet50 min = 19.17 max = 20.06 avg = 19.43
...
2. Install your own Opencv from source
When installing NCNN, installing dependencies will install Opencv, but the version is relatively low. You can use the following command to view the current opencv version.
pkg-config --modversion opencv
Here I want to install an Opencv version above Opencv 3.x from source. First go to the Opencv official website to download the corresponding version of Releases - OpenCV , for example, I downloaded version 3.4.3. Unzip it after downloading.
Enter the opencv-3.4.3 folder, create a build folder, and enter the build folder.
cd /home/maser-linux/Downloads/opencv-3.4.3
mkdir build
cd build
Do cmake, compile and install. About 5-10 minutes.
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make -j8
sudo make install
After installing opencv, you need to configure the environment. Open with nano /etc/ld.so.conf,
and add a line to the file /usr/loacal/lib,
, which /user/loacal
is the opencv installation path, which is the installation path specified in the makefile. That is, CMAKE_INSTALL_PREFIX=/usr/local above .
Run the following statement to refresh the library link configuration.
sudo ldconfig
Then modify the bash.bashrc file and update it.
sudo gedit /etc/bash.bashrc
# 输入
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
source /etc/bash.bashrc
Enter the following command on the command line: It means that the installation of Opencv3.4.3 is complete.
pkg-config opencv --modversion
By the way, if it is installed opencv4, the view version should be:
pkg-config --modversion opencv4