怎么把.pb转换成.tflite? [英] How to convert from .pb to .tflite?

查看:747
本文介绍了怎么把.pb转换成.tflite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Pytorch 创建了一个对象检测模型,然后从 .pth 转换为 .onnx ,然后是 .pb ,但现在我需要将其转换为 .tflite 对于Android应用程序!怎么做?这是我的第一次。

I have created a object detection model using Pytorch and then converted from .pth to .onnx and then .pb, but now I need to convert it into .tflite for android app! How to do it? It's my first time.

input_arrays  = [64, 3, 224, 224] 

output_arrays = ? 

用于二进制分类。

我有是从pytorch完成的,但我发现要查看的所有内容都是来自keras或Tensorflow ...

I have done it from pytorch but everything I find to look at was from keras or Tensorflow...

这是我用来将其从 .pb 到 .tflie

converter = lite.TFLiteConverter.from_frozen_graph(
  model/model.pb , input_arrays, output arrays )
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)



!tflite_convert \
   --output_file= model/model.tflite \
   --graph_def_file= model/model.pb \
   --input_arrays= input_arrays \
   -- output_arrays= output_arrays

我认为这与输入数组有关和输出数组,但不确定。 graph_def_file 应该存储 model.pb 吗?

I think it has something to do with input arrays and output arrays, but not sure about it. Is graph_def_file supposed to store model.pb ?

推荐答案

使用以下代码时,无需指定输入和输出数组:

No need to specify input and output array, when using the following code:

import tensorflow as tf

converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

尝试

这篇关于怎么把.pb转换成.tflite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆