栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Tensorflow-lite中输入具有动态尺寸的图像

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Tensorflow-lite中输入具有动态尺寸的图像

是的,您 可以 在TF-Lite中 使用动态张量 。您不能直接将形状设置

[None, 128, None,1]
为的原因是因为这样,将来您可以轻松支持更多语言。此外,它充分利用了静态内存分配方案。对于打算用于具有低计算能力的小型设备的框架来说,这是一个明智的设计选择。以下是有关如何动态设置张量大小的步骤:

0.冻结

似乎您正在从冻结的GraphDef(即

*.pb
文件)进行转换。假设冻结的模型具有输入形状
[None, 128, None, 1]

1.转换步骤。

在此步骤中,将输入大小设置为模型可以接受的 任何有效 大小。例如:

tflite_convert   --graph_def_file='model.pb'   --output_file='model.tflite'   --input_shapes=1,128,80,1      # <-- here, you set an #     arbitrary valid shape  --input_arrays='input' --output_arrays='Softmax'

2.推论步骤

诀窍是

interpreter::resize_tensor_input(...)
在推理过程中实时使用TF-Lite
API的功能。我将提供它的python实现。Java和C ++实现应相同(因为它们具有相似的API):

from tensorflow.contrib.lite.python import interpreter# Load the *.tflite model and get input detailsmodel = Interpreter(model_path='model.tflite')input_details = model.get_input_details()# Your network currently has an input shape (1, 128, 80 , 1),# but suppose you need the input size to be (2, 128, 200, 1).model.resize_tensor_input(    input_details[0]['index'], (2, 128, 200, 1))model.allocate_tensors()

而已。现在

(2, 128, 200,1)
,只要您的网络体系结构允许输入这样的形状,就可以将该模型用于具有shape的图像。请注意,
model.allocate_tensors()
每次进行这样的重塑时都必须做,所以效率很低。这是
强烈建议 ,以避免在程序中使用此功能太多。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/662560.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号