Tensorflow lite model request a buffer bigger than the neccesary

和自甴很熟 提交于 2021-01-28 05:22:19

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/54920921/tensorflow-lite-model-request-a-buffer-bigger-than-the-neccesary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!