title: How do I convert bitmap image to TensorImage on Android?
body: <p>It's my first time to post question. I've been building a object classification program using tensorflow lite for Android device(Java). I already made the same function program by using Python and Keras so I converted the model to tflite form and I used it on android. But the result is quite different than I got in Python. I suspect the image processing method before inference was incorrect.</p>
  
  <p>In Python, the image process before inference is below:</p>
  
  <pre><code>img = cv2.imread(image_dir)/255.  
  img = cv2.resize(img, (64,64), interpolation = cv2.INTER_AREA)
  img_list.append(img)
  img_list = np.array(img_list).astype(np.float32)
  
  model.predict(img_list, batch_size=512, verbose=0)
  </code></pre>
  
  <p>In Android(Java), the image process before the inference is below:</p>
  
  <pre><code>Mat img = new Mat();
  Utils.bitmapToMat(bitmap, img, true);
  
  Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2GRAY); //to grayscale
  
  Size size = new Size(64,64);
  Imgproc.resize(img, img, size, Imgproc.INTER_AREA); //resize
  
  Bitmap dst = Bitmap.createBitmap(img.width(), img.height(), Bitmap.Config.ARGB_8888);
  
  Utils.matToBitmap(img, dst); //convert to bitmap
  
  int imageTensorIndex = 0;
  DataType imageDataType = tensorFlowLiteModel.getInputTensor(imageTensorIndex).dataType(); //tensorFlowLiteModel is interpreter which also inferences (loaded from XXXX.tflite)
  
  TensorImage tfImage = new TensorImage(imageDataType);
  tfImage.load(dst);
  
  int probabilityTensorIndex = 0;
  int[] probabilityShape =
                  tensorFlowLiteModel.getOutputTensor(probabilityTensorIndex).shape();
  DataType probabilityDataType = tensorFlowLiteModel.getOutputTensor(probabilityTensorIndex).dataType();
  outputProbabilityBuffer = TensorBuffer.createFixedSize(probabilityShape, probabilityDataType);
  
  tensorFlowLiteModel.run(tfImage.getBuffer(),  outputProbabilityBuffer.getBuffer().rewind())
  </code></pre>
  
  <p>It actually worked and showed result but the result is different from Python(Keras).
  I guess the image process before inference was wrong.
  I also know image process using ByteBuffer but it was didn't work because of OOM(Out of memory) so I want to use TensorImage class.
  If you know how to deal with this problem, please let me know.</p>