lezione finale pubblica
Interprete
Classe driver per guidare l'inferenza del modello con TensorFlow Lite.
Nota. Se non hai bisogno di accedere a nessun elemento "sperimentale" le funzionalità API riportate di seguito, preferiamo utilizzare InterpreterApi e Interpreterfabbrica anziché utilizzare direttamente lo strumento Interpreter.
Un Interpreter
incapsula un modello TensorFlow Lite preaddestrato, in cui le operazioni
vengono eseguite per l'inferenza del modello.
Ad esempio, se un modello accetta un solo input e restituisce solo un output:
try (Interpreter interpreter = new Interpreter(file_of_a_tensorflowlite_model)) {
interpreter.run(input, output);
}
Se un modello accetta più input o output:
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 (Interpreter interpreter = new Interpreter(file_of_a_tensorflowlite_model)) {
interpreter.runForMultipleIn