ncnn 是腾讯开源的神经网络推理框架,既然是一个负责推理的框架,所以不能像TF那样创建网络并且训练,它的最大用处是运行在端侧,解析并执行网络推理,输出推理结果。它可以支持各种类型的框架生成的网络。
官方仓库有详细介绍:
https://github.com/Tencent/ncnn.git
下面在普通PC的ubuntu18.04环境上搭建环境,运行一把。
1.下载代码:
git clone https://github.com/Tencent/ncnn.git
2.配置环境:
首先安装依赖:
sudo apt-get install libprotobuf-dev protobuf-compiler libopencv-dev cmake
cd ncnn
mkdir build
cd build
#cmake -DCMAKE_BUILD_TYPE=relwithdebinfo -DNCNN_OPENMP=OFF -DNCNN_THREADS=OFF -DNCNN_RUNTIME_CPU=OFF -DNCNN_RVV=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON ..
cmake ../
protobuf 为3.0.0版,可以和上面的配置对应。
3.编译
make -j4
(base) caozilong@caozilong-Vostro-3268:~/Workspace/ncnn/ncnn/build$ make -j4
[ 1%] Built target ncnnmerge
[ 1%] Built target ncnn-generate-spirv
[ 1%] Built target mxnet2ncnn
[ 2%] Built target caffe2ncnn
[ 2%] Built target darknet2ncnn
[ 3%] Built target onnx2ncnn
[ 87%] Built target ncnn
[ 87%] Built target rvm
[ 87%] Built target scrfd_crowdhuman
[ 88%] Built target yolov4
[ 88%] Built target benchncnn
[ 88%] Built target simplepose
[ 88%] Built target yolov3
[ 89%] Built target scrfd
[ 90%] Built target nanodet
[ 91%] Built target shufflenetv2
[ 92%] Built target squeezenet
[ 92%] Built target squeezenet_c_api
[ 92%] Built target yolov5
[ 93%] Built target yolox
[ 94%] Built target rfcn
[ 95%] Built target yolov2
[ 96%] Built target mobilenetv2ssdlite
[ 97%] Built target squeezenetssd
[ 97%] Built target mobilenetssd
[ 98%] Built target peleenetssd_seg
[ 99%] Built target fasterrcnn
[ 99%] Built target retinaface
[ 99%] Built target yolact
[100%] Built target ncnn2mem
[100%] Built target ncnnoptimize
[100%] Built target ncnn2int8
[100%] Built target ncnn2table
(base) caozilong@caozilong-Vostro-3268:~/Workspace/ncnn/ncnn/build$
4.下载模型文件.
ncnn只是一个推理框架,需要吃一个训练好的算法模型文件才能正常工作,可以理解NCNN是一个模型的运行环境,所以需要准备好模型文件,NCNN官方维护了一个模型仓库,里面有常见网络算法