2

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

rockbass2560
  • 159
  • 3
  • 12

1 Answers1

4

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.

Sachin Joglekar
  • 686
  • 4
  • 5
  • I discovered that answer this morning. I used the method "put" from a bytebuffer object, but when I used the method "putFloat" everything worked well (incresing the size of the bytebuffer first). Your answer confirms my supposition. Thanks. – rockbass2560 Mar 01 '19 at 07:16