将retrained_graph.pb转换为tflite模型

我无法将通过重新训练获得的retrained_graph.pb文件(Inception-V3模型)转换为用于Android应用的.tflite模型。

写入retrained_graph.pb文件的代码如下:

    output_graph_def = graph_util.convert_variables_to_constants(sess, graph.as_graph_def(), [FINAL_TENSOR_NAME])    with gfile.FastGFile(graph_file_name, 'wb') as f:        f.write(output_graph_def.SerializeToString())

在转换为tflite时,我遇到了以下错误:RuntimeError: 在SavedModel中无法找到与标签 {‘serve’} 关联的MetaGraphDef。

代码如下:

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

所以请有人帮助我解决这个问题,以便我能轻松地将.pb文件转换为.tflite文件。


回答:

我能够使用以下命令将通过迁移学习方法获得的retrained_graph.pb模型文件转换为tflite文件:

toco –graph_def_file=/saved_model.pb –output_file=C:/Users/sunil.gc/tf-python/src/saved_model.tflite –input_format=TENSORFLOW_GRAPHDEF –output_format=TFLITE –input_shape=1,299,299,3 –input_array=Mul –output_array=final_result –inference_type=FLOAT –input_type=FLOAT

详细教程见链接

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注