title: Cannot copy to a TensorFlowLite tensor (input_1) with 150528 bytes from a Java Buffer with 602112 bytes
body: <p>I'm trying to use my model in the <code>tflitecamerademo</code> example.</p>
  <p>Here is my model
  <a href="https://i.stack.imgur.com/PbWoP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PbWoP.png" alt="enter image description here" /></a></p>
  <p>The demo crashes with the following reason</p>
  <p><code>java.lang.IllegalArgumentException: Cannot copy to a TensorFlowLite tensor (input_1) with 150528 bytes from a Java Buffer with 602112 bytes.</code></p>
  <p>I initialize the byte buffer following google's example</p>
  <pre><code>imgData = ByteBuffer.allocateDirect(4 * DIM_BATCH_SIZE * DIM_IMG_SIZE_X * DIM_IMG_SIZE_Y * DIM_PIXEL_SIZE);
  
  imgData.order(ByteOrder.nativeOrder());
  
  DIM_BATCH_SIZE = 1
  DIM_IMG_SIZE_X = 224
  DIM_IMG_SIZE_Y = 224
  DIM_PIXEL_SIZE = 3
  </code></pre>
  <p>Then I resize the image to the net resolution and convert it to a byte buffer</p>
  <pre><code>Bitmap reshapeBitmap = Bitmap.createScaledBitmap(bitmap, 224, 224, false);
  convertBitmapToByteBuffer(reshapeBitmap);
  
  
  private void convertBitmapToByteBuffer(Bitmap bitmap) {
          if (imgData == null) {
              return;
          }
          imgData.rewind();
          bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
          // Convert the image to floating point.
          int pixel = 0;
          long startTime = SystemClock.uptimeMillis();
          for (int i = 0; i &lt; DIM_IMG_SIZE_X; ++i) {
              for (int j = 0; j &lt; DIM_IMG_SIZE_Y; ++j) {
                  final int val = intValues[pixel++];
                  imgData.putFloat((((val &gt;&gt; 16) &amp; 0xFF)-IMAGE_MEAN)/IMAGE_STD);
                  imgData.putFloat((((val &gt;&gt; 8) &amp; 0xFF)-IMAGE_MEAN)/IMAGE_STD);
                  imgData.putFloat((((val) &amp; 0xFF)-IMAGE_MEAN)/IMAGE_STD);
              }
          }
          long endTime = SystemClock.uptimeMillis();
          //Log.d(&quot;Timecost to put values into ByteBuffer: &quot; + Long.toString(endTime - startTime));
      }
  </code></pre>
  <p>And last, I run the detection</p>
  <pre><code>tflite.run(imgData, labelProbArray);
  </code></pre>
  <p>Here the crash happens due to the input size being different to to buffer size.</p>
  <p>Now, if we multiply by hand 1 * 224 * 224 * 3 * 4 we get 602112, the correct size. Why my code is missing the last multiplication.</p>