前言
ncnn是腾讯开源的用于手机端部署深度学习模型的框架,目前也支持在树莓派上使用。ncnn提供C++的借口,支持caffe等框架的模型进行转换。
目前ncnn已经开源,代码放[github](https://github.com/Tencent/ncnn "github")上,但是原版的代码对tensorflow支持不是很好,因此有大神搞了个支持tensorflow的ncnn,也在github上开源[ncnn-tensorflow](https://github.com/jiangxiluning/ncnn-tensorflow)。
另外,还有一些tensorflow转ncnn的工程:
1、https://github.com/hanzy88/tensorflow2ncnn
2、https://github.com/hanzy88/ckpt2ncnn
由于ncnn和ncnn-tensorflow的编译方法是一样的,因此,这里就对ncnn-tensorflow进行记录,ncnn的编译基本一样。
安装依赖
sudo apt-get install git cmake
安装其他依赖
sudo apt-get install -y gfortran
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev libatlas-base-dev
下载NCNN或者ncnn-tensorflow
解压后,在工程根目录建议一个build目录,进到build中执行以下指令编译:
cd ncnn
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_VULKAN=ON -DNCNN_SYSTEM_GLSLANG=ON -DNCNN_BUILD_EXAMPLES=ON ..
make -j$(nproc)
报错解决
g++: error: unrecognized command line option ‘-mfpu=neon’
g++: error: unrecognized command line option ‘-mfpu=neon’
g++: error: unrecognized command line option ‘-mfloat-abi=hard’
在../src/CMakeLists.txt
的306-309
行做一些修改:
if(PI3) # ↓后面注释掉
target_compile_options(ncnn PRIVATE -march=native) #-mfpu=neon -mfloat-abi=hard)
target_compile_definitions(ncnn PRIVATE __ARM_NEON __ANDROID__)
endif()
原因很简单,因为当前安装的是64位的系统,默认就是neon和硬浮点,官方安装文档貌似是32位系统为前提。