Tensorflow lite 模型请求的缓冲区大于必要的缓冲区 [英] Tensorflow lite model request a buffer bigger than the neccesary
问题描述
我在 tensorflow 中使用 keras 创建了一个自定义模型.我使用的版本是 tensorflow nightly 1.13.1.我使用官方工具构建tensorflow lite模型(方法tf.lite.TFLiteConverter.from_keras_model_file).
创建模型后,我查看了输入形状,似乎没有任何问题.
tensorflow lite 模型中的输入和输出形状为:
<前>[{'name': 'input_1', 'index': 59, 'shape': array([ 1, 240, 240, 3], dtype=int32), 'dtype': , 'quantization': (0.0, 0)}][{'name': 'dense/Softmax', 'index': 57, 'shape': array([1, 6], dtype=int32), 'dtype': , 'quantization': (0.0, 0)}]您可以注意到输入形状为 1 * 240 * 240 * 3,因此我预计缓冲区的大小为 172800 个单位.
但是,当我尝试在 android 设备中运行模型时,我收到了下一个错误:
<前>E/AndroidRuntime:致命异常:主要进程:com.megacode,PID:15067java.lang.RuntimeException:无法创建应用程序 com.megacode.base.ApplicationBase:java.lang.IllegalArgumentException:无法在 691200 字节的 TensorFlowLite 缓冲区和 172800 字节的 ByteBuffer 之间进行转换.在 android.app.ActivityThread.handleBindApplication(ActivityThread.java:5771)在 android.app.ActivityThread.-wrap2(ActivityThread.java)在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1648)我不明白为什么模型要求输入形状为 691200 个单位.
如果有人有建议,我将不胜感激
你说得对,输入的形状包含 1 * 240 * 240 * 3 元素.
然而,每个元素都是 int32 类型,每个元素占用 4 个字节.
因此,ByteBuffer 的总大小应该是 1 * 240 * 240 * 3 * 4 = 691200.
I created a custom model using keras in tensorflow. The version that I used was tensorflow nightly 1.13.1. I used the official tool to build the tensorflow lite model (the method tf.lite.TFLiteConverter.from_keras_model_file ).
After I created the model I reviewed the input shape and nothing seems is bad.
The input and output shapes in tensorflow lite model are:
[{'name': 'input_1', 'index': 59, 'shape': array([ 1, 240, 240, 3], dtype=int32), 'dtype': , 'quantization': (0.0, 0)}] [{'name': 'dense/Softmax', 'index': 57, 'shape': array([1, 6], dtype=int32), 'dtype': , 'quantization': (0.0, 0)}]
you can note that input shape is 1 * 240 * 240 * 3 so I expected that the buffer would have a size of 172800 units.
However, when I try to run the model in an android device I received the next error:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.megacode, PID: 15067 java.lang.RuntimeException: Unable to create application com.megacode.base.ApplicationBase: java.lang.IllegalArgumentException: Cannot convert between a TensorFlowLite buffer with 691200 bytes and a ByteBuffer with 172800 bytes. at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5771) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1648)
I don't understand the reason why the model request an input shape of 691200 units.
If someone has a suggestion I would appreciate it
You are correct, the input shape contains 1 * 240 * 240 * 3 elements.
However, each element is of type int32, which occupies 4 bytes each.
Therefore, the total size of the ByteBuffer should be 1 * 240 * 240 * 3 * 4 = 691200.
这篇关于Tensorflow lite 模型请求的缓冲区大于必要的缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!