Reputation: 13
Im currently making my own model and all works fine with the tensorflow-for-poets-2 demo. I trained multiple pictures in different folders, and the app recognized it.
Now I want to display a bounding box around the object. I found an example here
My problem is that my app is returning following error when I am adding my own tflite model:
E/AndroidRuntime: FATAL EXCEPTION: inference
Process: org.tensorflow.lite.demo, PID: 3495
java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 6] and a Java object with shape [1, 10, 4].
at org.tensorflow.lite.Tensor.throwExceptionIfTypeIsIncompatible(Tensor.java:240)
at org.tensorflow.lite.Tensor.copyTo(Tensor.java:116)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:157)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:229)
at org.tensorflow.demo.TFLiteObjectDetectionAPIModel.recognizeImage(TFLiteObjectDetectionAPIModel.java:194)
at org.tensorflow.demo.DetectorActivity$3.run(DetectorActivity.java:247)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
How I trained them:
python3 scripts/retrain.py \
--bottleneck_dir=bottlenecks \
--how_many_training_steps=500 \
--model_dir=inception \
--output_graph=tf_files/retrained_graph.pb \
--output_labels=tf_files/retrained_labels.txt \
--image_dir=tf_files/ \
--architecture mobilenet_1.0_224
Generating:
toco \
--input_format=TENSORFLOW_GRAPHDEF \
--input_file=tf_files/retrained_graph.pb \
--output_format=TFLITE \
--output_file=tf_files/optimized_graph.lite \
--inference_type=FLOAT \
--inference_input_type=FLOAT \
--input_arrays=input \
--output_arrays=final_result \
--input_shapes=1,224,224,3\
--mean_values=128 \
--std_values=128 \
--default_ranges_min=0 \
--default_ranges_max=6
DetectorActivity.java
// Configuration values for the prepackaged SSD model.
private static final int TF_OD_API_INPUT_SIZE = 224; // 300
private static final boolean TF_OD_API_IS_QUANTIZED = false; // true
private static final String TF_OD_API_MODEL_FILE = "optimized_graph.lite"; //detect.tflite
private static final String TF_OD_API_LABELS_FILE = "file:///android_asset/retrained_labels.txt";
Upvotes: 1
Views: 2803
Reputation: 23
I came to the solution. it's just because of the model you prepare to use
tfLite.run(imgData,outputScores);
private static final int NUM_DETECTIONS = 6;
It works at my side
Upvotes: 1
Reputation: 155
What is your current use case? Is it the same as of Tensorflow Poets. The error is evident that your tensorflow model output shape is not in par with the application. The use case of the application may be different from your use case.
Upvotes: 1