öffentliche Schnittstelle
InterpreterApi
Bekannte indirekte Unterklassen |
Schnittstelle zum TensorFlow Lite-Modellinterpreter, ausgenommen experimentelle Methoden.
Eine InterpreterApi
-Instanz kapselt ein vortrainiertes TensorFlow Lite-Modell, in dem
werden für die Modellinferenz ausgeführt.
Wenn ein Modell beispielsweise nur eine Eingabe annimmt und nur eine Ausgabe zurückgibt:
try (InterpreterApi interpreter =
new InterpreterApi.create(file_of_a_tensorflowlite_model)) {
interpreter.run(input, output);
}
Wenn ein Modell mehrere Eingaben oder Ausgaben annimmt:
Object[] inputs = {input0, input1, ...};
Map<Integer, Object> map_of_indices_to_outputs = new HashMap<>();
FloatBuffer ith_output = FloatBuffer.allocateDirect(3 * 2 * 4); // Float tensor, shape 3x2x4.
ith_output.order(ByteOrder.nativeOrder());
map_of_indices_to_outputs.put(i, ith_output);
try (InterpreterApi interpreter =
new InterpreterApi.create(file_of_a_tensorflowlite_model)) {
interpreter.runForMultipleInputsOutputs(inputs, map_of_indices_to_outputs);
}
Wenn ein Modell Stringtensoren annimmt oder erzeugt:
String[] input = {"foo", "bar"}; // Input tensor shape is [2].
String[][] output = new String[3][2]; // Output tensor shape is [3, 2].
try (InterpreterApi interpreter =
new InterpreterApi.create(file_of_a_tensorflowlite_model)) {
interpreter.runForMultipleInputsOutputs(input