InterpreterApi

公共接口 InterpreterApi
已知的间接子类

TensorFlow Lite 模型解释器的接口,不包括实验性方法。

InterpreterApi 实例封装了一个预训练的 TensorFlow Lite 模型,其中 以执行模型推断。

例如,如果模型仅接受一个输入并仅返回一个输出:

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

如果模型采用或生成字符串张量:

String[] input = {"foo", "bar"};