0

I build and run tensoflow app demo from: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/java/demo

I replace model "mobilenet_quant_v1_224.tflite" by my custom model "optimized_graph.tflite" and label "labels.txt" by my custom label "retrained_labels.txt".

App run ok but i receive a error:

uninitialized classifier or invalid context in tensoflow app demo

enter image description here

mducc
  • 743
  • 1
  • 9
  • 32

2 Answers2

1

I had the same error. To be precise my console gave the following error:

E/AndroidRuntime: FATAL EXCEPTION: CameraBackground Process: android.example.com.tflitecamerademo, PID: 5603 java.lang.IllegalArgumentException: Cannot convert between a TensorFlowLite buffer with 196608 bytes and a ByteBuffer with 602112 bytes.

I had trained my model for an image size of 128 and not 224px. Thus when I ran my model in my computer I would have to specify the image height and width as 128. So after I got the error, I figured out that I had to set the image size at 128 in ImageClassifier.java

static final int DIM_IMG_SIZE_X = 128;
static final int DIM_IMG_SIZE_Y = 128;

This worked for me

morgan121
  • 2,213
  • 1
  • 15
  • 33
Rajshree Rai
  • 533
  • 7
  • 14
0

There are a number of related issues on Github (e.g. https://github.com/tensorflow/tensorflow/issues/18658, https://github.com/tensorflow/tensorflow/issues/15751).

You probably need to update https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/java/demo/app/src/main/BUILD to include your custom model and labels files.

Alan Chiao
  • 161
  • 3