Interpreter

パブリック ファイナル クラス インタープリタ

TensorFlow Lite を使用してモデル推論を駆動するドライバクラス。

注: 「試験運用版」の使用する API 機能は以下のとおりです。 InterpreterApi と InterpreterFactory の使用を促進します。

Interpreter は、事前トレーニング済みの TensorFlow Lite モデルをカプセル化します。このモデルでは、 モデルの推論のために実行されます

たとえば、モデルが 1 つの入力のみを受け取り、1 つの出力のみを返すとします。

try (Interpreter interpreter = new Interpreter(file_of_a_tensorflowlite_model)) {
   interpreter.run(input, 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.runForMultipleInputsOutputs(inputs, map_of_indices_to_outputs);
 }
 

モデルが文字列テンソルを取得または生成する場合:

String[] input = {"foo", "bar"};  // Input tensor shape is [2].
 String[][] output = new String[3][2];  // Output tensor shape is [3, 2].
 try (