aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/lite/java/src
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-06-01 10:41:35 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-06-01 10:44:20 -0700
commit6b76b6453a268f874c189eb4843fbe1deee3ae5b (patch)
tree41edfda1e0bc6734a66c23430bfda0c47f049e2a /tensorflow/contrib/lite/java/src
parentbb94c57a7fe63063e70f7e9984b7ec9507396d5e (diff)
Updates Interpreter to be initialized with a MappedByteBuffer for backward compatibility.
PiperOrigin-RevId: 198893078
Diffstat (limited to 'tensorflow/contrib/lite/java/src')
-rw-r--r--tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java b/tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java
index 644ce4cb3e..fd1f0ffa68 100644
--- a/tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java
+++ b/tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java
@@ -17,6 +17,7 @@ package org.tensorflow.lite;
import java.io.File;
import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -104,6 +105,27 @@ public final class Interpreter implements AutoCloseable {
}
/**
+ * Initializes a {@code Interpreter} with a {@code MappedByteBuffer} to the model file.
+ *
+ * <p>The {@code MappedByteBuffer} should remain unchanged after the construction of a {@code
+ * Interpreter}.
+ */
+ public Interpreter(@NonNull MappedByteBuffer mappedByteBuffer) {
+ wrapper = new NativeInterpreterWrapper(mappedByteBuffer);
+ }
+
+ /**
+ * Initializes a {@code Interpreter} with a {@code MappedByteBuffer} to the model file and
+ * specifies the number of threads used for inference.
+ *
+ * <p>The {@code MappedByteBuffer} should remain unchanged after the construction of a {@code
+ * Interpreter}.
+ */
+ public Interpreter(@NonNull MappedByteBuffer mappedByteBuffer, int numThreads) {
+ wrapper = new NativeInterpreterWrapper(mappedByteBuffer, numThreads);
+ }
+
+ /**
* Runs model inference if the model takes only one input, and provides only one output.
*
* <p>Warning: The API runs much faster if {@link ByteBuffer} is used as input data type. Please
@@ -231,5 +253,14 @@ public final class Interpreter implements AutoCloseable {
wrapper = null;
}
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ close();
+ } finally {
+ super.finalize();
+ }
+ }
+
NativeInterpreterWrapper wrapper;
}