ncnn

1.编译本地ncnn

git clone https://github.com/Tencent/ncnn.git 
cd ncnn 
mkdir -p build
cd build
cmake .. 
make -j4

编译后,在目录ncnn/build/tools/caffe下,分别有ncnn2mem和caffe2ncnn两个可执行文件:

  • caffe2ncnn 将caffemodel转换为ncnnmodel
  • ncnn2mem 对模型进行加密操作

//j加载非加密的ncnn模型

ncnn::Net net;
net.load_param("MobileNetSSD_deploy.param");
net.load_model("MobileNetSSD_deploy.bin");

//加载加密的ncnn模型

ncnn::Net net;
net.load_param_bin("MobileNetSSD_deploy.param.bin");
net.load_model("MobileNetSSD_deploy.bin");

cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=“armeabi-v7a” -DANDROID_ARM_NEON=ON -DANDROID_PLATFORM=android-14 …

pytorch转onnx转ncnn

python3 -m onnxsim resnet18.onnx resnet18-sim.onnx

onnx2ncnn resnet18-sim.onnx resnet18.param resnet18.bin

参考:https://github.com/Tencent/ncnn/wiki/practical-pytorch-to-onnx-to-ncnn

你可能感兴趣的:(编程语言)