Ошибка Java TFLITE при выделении памяти для runForMultipleInputsOutputs - PullRequest
0 голосов
/ 23 сентября 2019

Ошибка при подготовке выходных данных для интерпретатора TFLITE для Android Java.Модель имеет 1 вход и 4 выхода.

interpreter.runForMultipleInputsOutputs(input, map_of_indices_to_outputs);

E/Run multiple: Internal error: Unexpected failure when preparing tensor allocations: tensorflow/lite/kernels/tile.cc:53 num_dimensions != num_multipliers (1 != 2)Node number 4 (TILE) failed to prepare.

Выходные требования представляют собой список из 4 массивов с плавающей запятой:

[ [1x1],[1x2], [1x2], [1x2] ]

Выходные данные для прогноза в python:

In [56] output = model.predict(new_observation_scaled)

Out[56]: 
[array([[0.]], dtype=float32),
 array([[137.66626, 335.7148 ]], dtype=float32),
 array([[0.16666616, 0.40643442]], dtype=float32),
 array([[9.9915421e-01, 8.4577635e-04]], dtype=float32)]

Итак, я подготовилa Список объектов в JAVA:

float [][] output0 = new float [1][1];
float [][] output1 = new float [1][2];
float [][] output2 = new float [1][2];
float [][] output3 = new float [1][2];
Object[] outputs = {output0,output1,output2,output3};

Map<Integer, Object> map_of_indices_to_outputs = new HashMap<>();
map_of_indices_to_outputs.put(0, output0);
map_of_indices_to_outputs.put(1, output1);
map_of_indices_to_outputs.put(2, output2);
map_of_indices_to_outputs.put(3, output3);

Можете ли вы помочь мне найти ошибку?

РЕДАКТИРОВАТЬ: Это детали интерпретатора, считанные из файла tflite, созданного с помощью tf 2.0-rc1:

f='.\\models\\pdb_20190923-163632.tflite'

interpreter = tf.lite.Interpreter(model_path=f)

interpreter
Out[16]: <tensorflow.lite.python.interpreter.Interpreter at 0x20684c69608>

interpreter.get_input_details()
Out[17]: 
[{'name': 'RSSI',
  'index': 4,
  'shape': array([ 1, 15]),
  'dtype': numpy.float32,
  'quantization': (0.0, 0)}]

interpreter.get_output_details()
Out[18]: 
[{'name': 'Identity',
  'index': 0,
  'shape': array([1, 1]),
  'dtype': numpy.float32,
  'quantization': (0.0, 0)},
 {'name': 'Identity_1',
  'index': 1,
  'shape': array([1, 2]),
  'dtype': numpy.float32,
  'quantization': (0.0, 0)},
 {'name': 'Identity_2',
  'index': 2,
  'shape': array([1, 2]),
  'dtype': numpy.float32,
  'quantization': (0.0, 0)},
 {'name': 'Identity_3',
  'index': 3,
  'shape': array([1, 2]),
  'dtype': numpy.float32,
  'quantization': (0.0, 0)}]

1 Ответ

0 голосов
/ 23 сентября 2019

Я получил решение вопроса:

Точно так же для выходов требуется список, также как и для входов:

Object[] outputs = {output0,output1,output2,output3};
Object[] inputs = {input};
interpreter.runForMultipleInputsOutputs(inputs, map_of_indices_to_outputs);
...