diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2018-09-27 15:07:12 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-09-27 15:11:54 -0700 |
commit | 8276ef6088ecedd4a5f62a8eacd35a075a43746c (patch) | |
tree | 62a052e911f2d8921d8beabe011833f03da0102d /tensorflow/contrib | |
parent | d0397c3314600da0c9cdc300ae87483331d54298 (diff) |
Updates Interpreter to be initialized with a MappedByteBuffer for backward compatibility.
PiperOrigin-RevId: 214843130
Diffstat (limited to 'tensorflow/contrib')
-rw-r--r-- | tensorflow/contrib/lite/java/src/main/java/org/tensorflow/lite/Interpreter.java | 15 | ||||
-rw-r--r-- | tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java | 4 |
2 files changed, 17 insertions, 2 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 eacfa0c827..5cc6e754f3 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; @@ -149,6 +150,20 @@ 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}. + * + * @deprecated Prefer using the {@link #Interpreter(ByteBuffer,Options)} constructor. This method + * will be removed in a future release. + */ + @Deprecated + public Interpreter(@NonNull MappedByteBuffer mappedByteBuffer) { + this(mappedByteBuffer, /* options= */ null); + } + + /** * Initializes a {@code Interpreter} with a {@code ByteBuffer} of a model file and a set of custom * {@link #Options}. * diff --git a/tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java b/tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java index fdd5063156..a98fca0132 100644 --- a/tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java +++ b/tensorflow/contrib/lite/java/src/test/java/org/tensorflow/lite/InterpreterTest.java @@ -71,7 +71,7 @@ public final class InterpreterTest { Path path = MODEL_FILE.toPath(); FileChannel fileChannel = (FileChannel) Files.newByteChannel(path, EnumSet.of(StandardOpenOption.READ)); - MappedByteBuffer mappedByteBuffer = + ByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size()); Interpreter interpreter = new Interpreter(mappedByteBuffer); float[] oneD = {1.23f, 6.54f, 7.81f}; @@ -118,7 +118,7 @@ public final class InterpreterTest { byteBuffer.order(ByteOrder.nativeOrder()); fileChannel.read(byteBuffer); try { - Interpreter interpreter = new Interpreter(byteBuffer); + new Interpreter(byteBuffer); fail(); } catch (IllegalArgumentException e) { assertThat(e) |