【问题标题】:Set batch size of trained keras model to 1将训练好的 keras 模型的批量大小设置为 1
【发布时间】:2021-11-10 21:01:55
【问题描述】:

我在自己的数据集上训练了一个 keras 模型。然而,在加载权重后,摘要显示 None 作为第一个维度(批量大小)。

我想知道将形状修复为批量大小 1 的过程,因为我必须修复它,以便我可以将模型转换为支持 GPU 的 tflite。

【问题讨论】:

  • 不要使用input_shape 来提供模型和训练,而是使用batch_input_shape 并选择所需的batch_size。欲了解更多信息,您可以参考this。谢谢!

标签: tensorflow keras deep-learning


【解决方案1】:

对我有用的是为输入层指定批量大小,如下所示:

input = layers.Input(shape=input_shape, batch_size=1, dtype='float32', name='images')

然后通过其余的层进行。

坏消息是,尽管有这个“修复”,tfl 运行时仍然抱怨动态张量。当它运行时,我在 logcat 中得到这些非致命错误:

E/tflite: third_party/tensorflow/lite/core/subgraph.cc:801 tensor.data.raw != nullptr was not true.
E/tflite: Attempting to use a delegate that only supports static-sized tensors with a graph that has dynamic-sized tensors (tensor#26 is a dynamic-sized tensor).
E/tflite: Ignoring failed application of the default TensorFlow Lite delegate indexed at 0.

好消息是,尽管有这些错误,但根据性能测试,它似乎仍然在使用 GPU。

我正在使用:

tensorflow-lite-support:0.2.0'    
tensorflow-lite-metadata:0.2.1'    
tensorflow-lite:2.6.0'    
tensorflow:tensorflow-lite-gpu:2.3.0'

希望他们会修复运行时问题,因此批处理大小是否为“无”并不重要。做推理应该没关系。

【讨论】:

    猜你喜欢
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 2018-12-06
    • 2022-12-04
    • 2023-03-13
    • 1970-01-01
    相关资源
    最近更新 更多