gpt4 book ai didi

tensorflow - 将 .tflite 转换为 .pb

转载 作者:行者123 更新时间:2023-12-04 01:15:55 25 4
gpt4 key购买 nike

问题 : 我如何转换 .tflite (序列化的 FlatBuffers )到 .pb (冷冻模型)? documentation只讲一种方式转换。

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

最佳答案

我找到了答案 here

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

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 .

关于tensorflow - 将 .tflite 转换为 .pb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53664279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com