将 .tflite 转换为 .pb [英] Converting .tflite to .pb

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

问题描述

问题:如何将 .tflite(序列化平面缓冲区)转换为 .pb(冻结模型)?文档 只谈了一种方式转换.

Problem: How can i convert a .tflite (serialised flat buffer) to .pb (frozen model)? The documentation only talks about one way conversion.

用例是:我有一个经过训练的模型转换为 .tflite 但不幸的是,我没有模型的详细信息,我想检查图表,我该怎么做?

Use-case is: I have a model that is trained on converted to .tflite but unfortunately, i do not have details of the model and i would like to inspect the graph, how can i do that?

推荐答案

我找到了答案 这里

我们可以使用 Interpreter 来分析模型,同样的代码如下所示:

We can use Interpreter to analysis the model and the same code looks like following:

import numpy as np
import tensorflow as tf

# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="converted_model.tflite")
interpreter.allocate_tensors()

# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Test model on random input data.
input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)

interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)

Netron 是我发现的最好的分析/可视化工具,它可以理解很多格式,包括 .tflite.

Netron is the best analysis/visualising tool i found, it can understand lot of formats including .tflite.

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

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