Deprecate the modifyGraphWithDelegate method in Java binding. The Options.addDelegate(...) is preferred to provide delegates at creation time.

PiperOrigin-RevId: 340586749
Change-Id: Ib7af63469165253206e906379c47a56f46445190
This commit is contained in:
Chao Mei 2020-11-03 22:19:10 -08:00 committed by TensorFlower Gardener
parent f65f285b44
commit d77d8b3f4a
2 changed files with 14 additions and 14 deletions

View File

@ -369,6 +369,7 @@ public final class Interpreter implements AutoCloseable {
* <p>Note: This call is *purely optional*. Tensor allocation will occur automatically during
* execution if any input tensors have been resized. This call is most useful in determining the
* shapes for any output tensors before executing the graph, e.g.,
*
* <pre>{@code
* interpreter.resizeInput(0, new int[]{1, 4, 4, 3}));
* interpreter.allocateTensors();
@ -500,14 +501,11 @@ public final class Interpreter implements AutoCloseable {
/**
* Advanced: Modifies the graph with the provided {@link Delegate}.
*
* <p>Note: The typical path for providing delegates is via {@link Options#addDelegate}, at
* creation time. This path should only be used when a delegate might require coordinated
* interaction between Interpeter creation and delegate application.
*
* <p>WARNING: This is an experimental API and subject to change.
*
* @throws IllegalArgumentException if error occurs when modifying graph with {@code delegate}.
* @deprecated Prefer using {@link Options#addDelegate} to provide delegates at creation time.
* This method will be removed in a future release.
*/
@Deprecated
public void modifyGraphWithDelegate(Delegate delegate) {
checkNotClosed();
wrapper.modifyGraphWithDelegate(delegate);
@ -539,7 +537,6 @@ public final class Interpreter implements AutoCloseable {
* resume.
* @throws IllegalStateException if the interpreter is not initialized with the cancellable
* option, which is by default off.
*
* @see {@link Interpreter.Options#setCancellable(boolean)}.
*/
public void setCancelled(boolean cancelled) {

View File

@ -534,6 +534,8 @@ public final class InterpreterTest {
}
@Test
// modifyGraphWithDelegate(...) is deprecated, suppress the warning to allow testing.
@SuppressWarnings("deprecation")
public void testModifyGraphWithDelegate() throws Exception {
System.loadLibrary("tensorflowlite_test_jni");
Delegate delegate =
@ -543,7 +545,8 @@ public final class InterpreterTest {
return getNativeHandleForDelegate();
}
};
Interpreter interpreter = new Interpreter(MODEL_BUFFER);
Interpreter interpreter =
new Interpreter(MODEL_BUFFER, new Interpreter.Options().setUseXNNPACK(false));
interpreter.modifyGraphWithDelegate(delegate);
// The native delegate stubs out the graph with a single op that produces the scalar value 7.
@ -640,8 +643,8 @@ public final class InterpreterTest {
public void testCancelInference() throws Exception {
float[][][][] inputs = new float[2][8][8][3];
float[][][][] parsedOutputs = new float[2][8][8][3];
Interpreter interpreter = new Interpreter(
MODEL_BUFFER, new Interpreter.Options().setCancellable(true));
Interpreter interpreter =
new Interpreter(MODEL_BUFFER, new Interpreter.Options().setCancellable(true));
// Part 1: Should be interrupted when flag is set to true.
try {