MNN和NCNN安装记录

安装cmake

wget https://github.com/Kitware/CMake/releases/download/v3.15.0-rc1/cmake-3.15.0-rc1.tar.gz

tar -zxvf cmake-3.15.0-rc1.tar.gz
cd cmake-3.15.0-rc1
./bootstrap
make –j 
make install
cmake –version
pkg-config --libs opencv    // 显示lopencv*

wget https://cmake.org/files/v3.9/cmake-3.9.1-Linux-x86_64.tar.gz
tar -zxvf cmake-3.9.1-Linux-x86_64.tar.gz
wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz

安装protobuf

wget https://github.com/google/protobuf/releases/download/v3.4.1/protobuf-cpp-3.4.1.tar.gz

https://github.com/google/protobuf/archive/v3.1.0.zip 这个地方可以得到不同版本的zip

tar -zxvf protobuf-cpp-3.4.1.tar.gz
cd protobuf-3.4.1/
./autogen.sh  ##下载自github的代码需要执行此行来生成configure文件
【安装autoreconf】apt-get install autoconf automake libtool
./configure.sh
make –j
make check
make install
vim /etc/ld.so.conf
【添加】/usr/local/lib
ldconfig
protoc –version   or  which protoc

安装opencv

【opencv-3.2.0需要3.1.0的protobuf,protobuf版本对了才能解析.cache文件,cmake时会发现还需要numpy,即可能需要安装Anaconda2(因为Caffe不太支持python3)】

$   sudo apt-get update
$   sudo apt-get upgrade
$   sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264v4l-utils unzip

vim /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/shiguangji/anaconda3/lib

source /etc/profile

否则,执行opencv例子的时候会出错

安装opencv-3.2.0:

wget https://github.com/opencv/opencv/archive/3.2.0.zip
wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip
【wget https://github.com/opencv/opencv/archive/2.4.13.5.zip -O opencv-2.4.13.5.zip】
unzip 3.2.0.zip
mv 3.2.0.zip.1 3.2.0_contrib.zip
unzip 3.2.0_contrib.zip –d opencv-3.2.0
mv .cache opencv-3.2.0【从其他地方下载下来的cmake需要的东西,以防cmake下载外网东西失败,当然也可以先不用这步,然后试试。https://download.csdn.net/download/u010342901/10173967】
cd opencv3.2.0
mkdir build
cd build

编译选项

cmake -D CMAKE_BUILD_TYPE=RELEASE \
 -D CMAKE_INSTALL_PREFIX=/usr/local \
 -D INSTALL_PYTHON_EXAMPLES=ON \
 -D INSTALL_C_EXAMPLES=ON \
 -D OPENCV_EXTRA_MODULES_PATH=/home/guofu.lgf/opencv-3.2.0/opencv_contrib-3.2.0/modules \
 -D PYTHON_EXECUTABLE=/root/anaconda3/bin/python \
 -D WITH_TBB=ON \
 -D WITH_V4L=ON \
 -D WITH_QT=ON \
 -D WITH_GTK=ON \
 -D WITH_OPENGL=ON \
 -D BUILD_EXAMPLES=ON \
 -D BUILD_TIFF=ON  ..

搭环境

make –j
make install

配置动态链接库:
打开/etc/ld.so.conf.d/opencv.conf  在末尾加入/usr/local/lib    (有可能是个空文件,没关系)

ldconfig

编辑/etc/bash.bashrc

加入PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

pkg-config opencv --cflags --libs 测试安装结果

cmake 时,可添加-D WITH_CUDA=ON \ 以配置CUDA版本的opencv

测试

cd ../samples/cpp/example_cmake
cmake .
make

成功的话,会弹出一个展示”hello opencv”的窗口

例子:

  1. vim helloworld.cpp
#include 
using namespace cv;

#include 

int main( int argc, char** argv )
{
    if( argc != 2 )//判断参数是否是两个
    {
        printf( " No image data \n " );
        return -1;
    }

    char* imageName = argv[1];
    Mat image = imread( imageName, 1 );//读入图片;
    if(  !image.data)//判断是否有数据
    {
        printf( " No image data \n " );
        return -1;
    }

    namedWindow( imageName, CV_WINDOW_AUTOSIZE );
    imshow( imageName, image );//显示图片

    waitKey(0);
    return 0;
}
  1. vim CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(helloworld)
add_executable(helloworld helloworld.cpp)
find_package(OpenCV REQUIRED)
target_link_libraries(helloworld ${OpenCV_LIBS})
mkdir build
cd build
cmake ..
make

./helloworld test.jpg      /*  如果安装成功了,会显示 test 图片    */ 

问题1: fatal error: LAPACKE_H_PATH-NOTFOUND/lapacke.h:
apt-get install liblapacke-dev checkinstall
将第二行中的#include"LAPACKE_H_PATH-NOTFOUND/lapacke.h" 修改为#include"lapacke.h"

问题2:对‘TIFFReadDirectory@LIBTIFF_4.0’未定义的引用
https://blog.csdn.net/u011361393/article/details/83210824
解决思路为:下载对应版本的Tiff,安装

问题3: cannot find -lopencv_dep_cudart
在CMakeLists.txt中的 find_package(OpenCV REQUIRED) 之前加入
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF),之后继续cmake即可;

如果没解决,就链接部分Opencv的库,而不是链接所有库。
即从 target_link_libraries(hello ${OpenCV_LIBRARIES}) 改为target_link_libraries(hello -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_video ) //部分链接

编译ncnn

编译ncnn时,若出现 /usr/bin/cmake: /root/anaconda3/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake), 则检查 cmake的软链接设置,比如:ldd /usr/bin/cmake 【我没安装新的cmake,会看到软链接】libcurl.so.4 =》/root/anaconda3/lib/libcurl.so.4【这表明需要修改为cmake安装目录的那个lib中的libcurl。其实也可以在~/.bashrc中直接添加anaconda3的环境,但安装opencv时会有警告,不知道是否会出现其他连锁问题,所以这里选择修改链接】

解决方案–修改软链接:

rm -rf /usr/local/lib/libcurl.so.4
ln -s /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0 /usr/local/lib/libcurl.so.4 
更新~/.bashrc
vim ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH【在末尾添加】
source ~/.bashrc

安装Caffe

git clone https://github.com/BVLC/caffe.git
cd caffe
cp Makefile.config.example Makefile.config
vim Makefile.config

修改CPU_ONLY或GPU相关的,修改OPENCV版本(如果是3的话,就解开注释),解开python接口:WITH_PYTHON_LAYER := 1
修改hdf5路径:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
修改为:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
make all –j
make test –j
make runtest –j
make pycaffe –j
vim ~/.bahsrc
export PYTHONPATH=/(caffe所在目录)/caffe/python:$PYTHONPATH
source ~/.bashrc

问题1: .build_release/lib/libcaffe.so: undefined reference to `leveldb::Status::ToStringabi:cxx11 const’ 出现这种问题,就将gcc g++还原到以前等级【之前做过gcc降级,导致gcc混乱】
解决方案:cmake -D MNN_BUILD_DEMO=ON -D CUDA_USE_STATIC_CUDA_RUNTIME=OFF …
问题2: Caffe HDF5 header version与HDF5 library不匹配
比如报错:Headers are 1.10.1, library is 1.8.16
解决方案: conda install hdf5=1.8.16

你可能感兴趣的:(深度学习,模型部署)