Interpreter

lớp cuối cùng công khai Phiên dịch

Lớp trình điều khiển để thúc đẩy dự đoán mô hình bằng TensorFlow Lite.

Lưu ý: Nếu bạn không cần truy cập vào bất kỳ tính năng "thử nghiệm" nào Các tính năng API dưới đây, ưu tiên sử dụng Phiên dịch thay vì sử dụng Trình thông dịch trực tiếp.

Interpreter đóng gói mô hình TensorFlow Lite được huấn luyện trước, trong đó có các hoạt động được thực thi để suy luận mô hình.

Ví dụ: nếu một mô hình chỉ nhận một dữ liệu đầu vào và chỉ trả về một dữ liệu đầu ra:

try (Interpreter interpreter = new Interpreter(file_of_a_tensorflowlite_model)) {
   interpreter.run(input, output);
 }
 

Nếu một mô hình có nhiều dữ liệu đầu vào hoặc đầu ra:

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);
 }
 

Nếu một mô hình sử dụng hoặc tạo ra các tensor chuỗi:

String[] input =</