首页 > 移动平台 > 详细

深度学习模型在移动端部署方法

时间:2020-02-06 13:22:01      阅读:305      评论:0      收藏:0      [点我收藏+]

1. Keras 转 tflite

def keras2tflite(keras_model, tflitefile)
	converter = tf.lite.TFLiteConverter.from_keras_model(model_2)
	# Indicate that we want to perform the default optimizations,
	converter.optimizations = [tf.lite.Optimize.DEFAULT]
	tflite_model = converter.convert()
	open(tflitefile, "wb").write(tflite_model)

  模型转化之后,就可以在移动端通过tflite相应的工具进行调用了。比如,如果需要通过c语言的调用的话,则可以将得到的模型转化为c语言的代码。

apt-get -qq install xxd
xxd -i model.tflite > model.cc
cat model.cc  #查看生成的模型文件

2. Pytorch to Onnx

def pytorch2onnx(model, onnxfile,cpu = True):
    device = torch.device("cpu" if cpu else "cuda")
    net = model.to(device)
    inputs = torch.randn(1, 3, WIDTH, HEIGHT).to(device)
    torch_out = torch.onnx._export(net, inputs, output_onnx, export_params=True, verbose=False)

  

 

深度学习模型在移动端部署方法

原文:https://www.cnblogs.com/xueliangliu/p/12268037.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!