tensorflow: [tflite][java] has_rank_one_input_condition error when use runForMultipleInputsOutputs()
I obtain an error when use two inputs in runForMultipleInputsOutputs().
System information
-
Custom code
-
Android API 29
-
Android simulator
-
Used libraries: – org.tensorflow:tensorflow-lite:2.1.0 – org.tensorflow:tensorflow-lite-gpu:2.1.0 – org.tensorflow:tensorflow-lite-support:0.0.0-nightly
-
Used model information The model tolite file
[{‘name’: ‘input_1’, ‘index’: 0, ‘shape’: array([ 1, 10], dtype=int32), ‘dtype’: <class ‘numpy.float32’>, ‘quantization’: (0.0, 0)}, {‘name’: ‘input_2’, ‘index’: 1, ‘shape’: array([1, 2], dtype=int32), ‘dtype’: <class ‘numpy.float32’>, ‘quantization’: (0.0, 0)}]
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) [(None, 10)] 0
__________________________________________________________________________________________________
embedding_1 (Embedding) (None, 10, 256) 15616 input_1[0][0]
__________________________________________________________________________________________________
input_2 (InputLayer) [(None, 2)] 0
__________________________________________________________________________________________________
lstm_1 (LSTM) (None, 256) 525312 embedding_1[0][0]
__________________________________________________________________________________________________
concatenate (Concatenate) (None, 258) 0 input_2[0][0]
lstm_1[0][0]
__________________________________________________________________________________________________
dense_1 (Dense) (None, 61) 15799 concatenate[0][0]
==================================================================================================
The error
java.lang.IllegalArgumentException: Internal error: Failed to run on the given Interpreter: tensorflow/lite/kernels/select.cc:80 data->has_rank_one_input_condition was not true.
Node number 23 (SELECT) failed to prepare.
Node number 19 (WHILE) failed to invoke.
The code
MappedByteBuffer tfliteModelCaption = FileUtil.loadMappedFile(activity, "classifier_caption.tflite");
Interpreter.Options options = new Interpreter.Options();
Interpreter tflite = new Interpreter(tfliteModelCaption, options);
float[][] inputString = new float[1][10];
inputString[0][9] = 4;
float[][] inputData = new float[1][2];
inputData[0][0] = 0;
inputData[0][1] = 1;
Object[] inputArray = {inputString, inputData};
Map<Integer, Object> outputMap = new HashMap<>();
outputMap.put(0, new float[1][61]);
tflite.runForMultipleInputsOutputs(inputArray, outputMap);
tflite.close();
float[] result = ((float[][]) outputMap.get(0))[0];
textViewAge.setText("Test: " + Arrays.toString(result));
The error seems to means the shape of the inputs does not fit the model input, but I checked it many time and for me it looks the same. I create a similar model with only one input (no input_2) and I can use it without error.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 43 (21 by maintainers)
Finally, I found how to use
concrete_func
, I put the code below maybe it can help someone.I checked with my full model. All seems to work well now. Thank you.