首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >巨蟒的负荷-流场模型

巨蟒的负荷-流场模型
EN

Stack Overflow用户
提问于 2021-06-25 14:11:40
回答 1查看 3K关注 0票数 2

我正在使用Tensorflow Lite进行一个TinyML项目,该项目包括量化模型和浮点模型。在我的管道中,我使用tf.keras API训练我的模型,然后将模型转换成TFLite模型。最后,将TFLite模型量化为int8模型。

我可以使用API model.savetf.keras.model.load_model保存和加载“正常”的tensorflow模型

对转换后的TFLite模型也可以这样做吗?每次都要经历量化过程,这是相当耗时的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-25 14:33:13

您可以使用tflite解释器直接在笔记本中从TFLite模型中获得推断。

这是一个图像分类模型的例子。假设我们有一个tflite模型:

代码语言:javascript
复制
tflite_model_file = 'converted_model.tflite'

然后我们可以像这样加载和测试它:

代码语言:javascript
复制
# Load TFLite model and allocate tensors.
with open(tflite_model_file, 'rb') as fid:
    tflite_model = fid.read()
    
interpreter = tf.lite.Interpreter(model_content=tflite_model)
interpreter.allocate_tensors()

input_index = interpreter.get_input_details()[0]["index"]
output_index = interpreter.get_output_details()[0]["index"]

# Gather results for the randomly sampled test images
predictions = []

test_labels, test_imgs = [], []
for img, label in tqdm(test_batches.take(10)):
    interpreter.set_tensor(input_index, img)
    interpreter.invoke()
    predictions.append(interpreter.get_tensor(output_index))
    
    test_labels.append(label.numpy()[0])
    test_imgs.append(img)

请注意,您只需从tflite模型推断。您无法在体系结构和层中进行更改,比如重新加载Keras模型。如果您想要更改架构,您应该保存Keras模型,并对其进行测试,直到得到满意的结果,然后将其转换为tflite。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68132431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档