public final class
Interprète
Classe pilote permettant de piloter l'inférence de modèle avec TensorFlow Lite.
Remarque: Si vous n'avez besoin d'accéder à aucune des fonctionnalités fonctionnalités de l'API ci-dessous, utilisez plutôt InterpreterApi et InterpreterFactory au lieu d'utiliser directement Interpreter.
Un Interpreter
encapsule un modèle TensorFlow Lite pré-entraîné, dans lequel les opérations
sont exécutés pour l'inférence de modèle.
Par exemple, si un modèle n'accepte qu'une seule entrée et ne renvoie qu'une seule sortie:
try (Interpreter interpreter = new Interpreter(file_of_a_tensorflowlite_model)) {
interpreter.run(input, output);
}
Si un modèle accepte plusieurs entrées ou sorties:
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.runForMultipleInputsOutputs(inputs, map_of_indices_to_outputs);
}
Si un modèle accepte ou produit des Tensors de chaîne:
String[] input = {"foo", "bar"}; // Input tensor shape is [2].
String[][] output = new String[3][2]; // Output tensor shape is [3, 2].
try (Interpreter interpreter = new Interpreter(file_of_a_tensorflowlite_model)) {
interpreter.runForMultipleInputsOutputs(inpu