title: Android TensorFlow Lite interpreter: How to fix "DataType error: cannot resolve DataType of java.lang.Float"
body: <p>When running the TFLite interpreter giving as input a ByteBuffer containing floats, the application throws an exception: </p>
  
  <p>"DataType error: cannot resolve DataType of java.lang.Float"</p>
  
  <p>The model itself was trained on Keras, then converted to TF and then to TFLite.</p>
  
  <p>For conversion I have used the TF (version 1.5.0) toco converter.</p>
  
  <p>Input parameters for toco:</p>
  
  <p>toco --input_file=converted.pb --output_file=model.tflite --input_format=TENSORFLOW_GRAPHDEF --input_shape=1,224,224,3 --input_array=main_input --output_array=main_output/Sigmoid --inference_type=FLOAT --output_format=TFLITE --input_type=FLOAT </p>
  
  <p>Instead of the ByteBuffer I also have manually created a float[][][][] array with dimensions expected as input by the model: [1,224,224,3]</p>
  
  <p>Leads to the same error as the ByteBuffer.</p>
  
  <p>Please note that I am dividing the floats by 255 to get the pixel values in the range of [0,1].</p>
  
  <pre><code>import org.tensorflow.lite.Interpreter;
  import java.nio.ByteBuffer;
  
  
  public Interpreter tflite;
  
  tflite = new Interpreter(loadModelFile(Test_TFLite.this,modelFile));
  
  ByteBuffer bytebuffer_float = convertBitmapToByteBuffer_float(image, 1, 
      224, 3);
  
  float out = 0;
  
  tflite.run(bytebuffer_float,out);
  
  
  private ByteBuffer convertBitmapToByteBuffer_float(Bitmap bitmap, int 
      BATCH_SIZE, int inputSize, int PIXEL_SIZE) {
          ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * BATCH_SIZE * 
      inputSize * inputSize * PIXEL_SIZE); //float_size = 4 bytes
          byteBuffer.order(ByteOrder.nativeOrder());
          int[] intValues = new int[inputSize * inputSize];
          bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, 
      bitmap.getWidth(), bitmap.getHeight());
          int pixel = 0;
          for (int i = 0; i &lt; inputSize; ++i) {
              for (int j = 0; j &lt; inputSize; ++j) { 
                  final int val = intValues[pixel++];
  
  
                  byteBuffer.putFloat( ((val &gt;&gt; 16) &amp; 0xFF)* (1.f/255.f)); 
                  byteBuffer.putFloat( ((val &gt;&gt; 8) &amp; 0xFF)* (1.f/255.f)); 
                  byteBuffer.putFloat( (val &amp; 0xFF)* (1.f/255.f)); 
              }
          }
          return byteBuffer;
      }
  </code></pre>
  
  <p>I expect a single float value in range [0,1] as an output. There is no actual output as the interpreter throws an exception. </p>
  
  <p>"DataType error: cannot resolve DataType of java.lang.Float"</p>