一、安装protobuf

1gitclone https://github.com/google/protobuf

2、自动生成configure配置文件,运行:./autogen.sh

3、配置环境:./configure

4、编译源代码:make

5、安装:sudomake install

6、刷新动态库:sudoldconfig

二、安装ncnn

1mkdircode && cd code

2gitclone https://github.com/Tencent/ncnn

3cdncnn

4mkdirbuild && cd build

5cmake.. (只有安装成功protobuf才能成功)

caffe、tf转ncnn


6make-j

caffe、tf转ncnn

如果遇到这样的错误,geditCmakeLists.txt, 在第一行添加:add_definitions(-std=c++11).

编译成功:

caffe、tf转ncnn

如果要安装tensorflow2ncnn,则需要在code/ncnn/tools/下的CMakeLists.txt中加入add_subdirectory(tensorflow)


7makeinstall

caffe、tf转ncnn


8caffencnn

~/code/ncnn/build/tools$./caffe2ncnndeplpy.prototxt alexnet.caffemodel alexnet.param alexnet.bin

加密:

~/code/ncnn/build/tools$./ncnn2mem alexnet.param alexnet.bin alexnet.id.h alexnet.mem.h

成功会在当前文件夹生成.param.bin文件

加载未加密模型:

ncnn::Netnet;

net.load_param("alexnet.param");

net.load_model("alexnet.bin");

加载加密模型:

ncnn::Netnet;

net.load_param_bin("alexnet.param.bin");

net.load_model("alexnet.bin");

9tensorflowncnn

tensorflow保存的模型分为meta,ckpt,pb等文件,我只试了转pb

先把meta转成pb

importtensorflow as tf

withtf.Session() as sess:

#初始化变量

sess.run(tf.global_variables_initializer())

#获取最新的checkpoint,其实就是解析了checkpoint文件

latest_ckpt= tf.train.latest_checkpoint("./checkpoint")

#加载图

restore_saver= tf.train.import_meta_graph('./checkpoint/Model.meta')

#恢复图,即将weights等参数加入图对应位置中

restore_saver.restore(sess,latest_ckpt)

#将图中的变量转为常量

output_graph_def= tf.graph_util.convert_variables_to_constants(

sess,sess.graph_def , ["node"])

#将新的图保存到"/pretrained/graph.pb"文件中

tf.train.write_graph(output_graph_def,'pretrained', "graph.pb", as_text=False)

最后运行:

~/code/ncnn/build/tools/tensorflow$./tensorflow2ncnn graph.pb

三、安装mxnet

参考:

http://mxnet.incubator.apache.org/install/


相关文章:

  • 2021-04-30
  • 2021-12-30
  • 2021-05-01
  • 2021-05-12
  • 2022-12-23
  • 2021-09-14
  • 2021-04-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-06-05
  • 2021-06-10
  • 2021-08-19
  • 2021-11-07
相关资源
相似解决方案