parent
9490e03a98
commit
a4e610db48
@ -16,7 +16,6 @@ limitations under the License.
|
||||
package org.tensorflow.lite.nnapi;
|
||||
|
||||
import org.tensorflow.lite.Delegate;
|
||||
import org.tensorflow.lite.TensorFlowLite;
|
||||
|
||||
/** {@link Delegate} for NNAPI inference. */
|
||||
public class NnApiDelegate implements Delegate, AutoCloseable {
|
||||
@ -45,10 +44,4 @@ public class NnApiDelegate implements Delegate, AutoCloseable {
|
||||
}
|
||||
|
||||
private static native long createDelegate();
|
||||
|
||||
static {
|
||||
// Ensure the native TensorFlow Lite libraries are available. Note that we don't use
|
||||
// `TensorFlowLite.init()`, as that would require making the method public.
|
||||
TensorFlowLite.runtimeVersion();
|
||||
}
|
||||
}
|
||||
|
@ -195,27 +195,6 @@ java_test(
|
||||
],
|
||||
)
|
||||
|
||||
java_test(
|
||||
name = "NnApiDelegateTest",
|
||||
size = "small",
|
||||
srcs = [
|
||||
"src/test/java/org/tensorflow/lite/TestUtils.java",
|
||||
"src/test/java/org/tensorflow/lite/nnapi/NnApiDelegateTest.java",
|
||||
],
|
||||
data = [
|
||||
"src/testdata/add.bin",
|
||||
],
|
||||
javacopts = JAVACOPTS,
|
||||
tags = ["no_mac"],
|
||||
test_class = "org.tensorflow.lite.nnapi.NnApiDelegateTest",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
":tensorflowlitelib",
|
||||
"@com_google_truth",
|
||||
"@junit",
|
||||
],
|
||||
)
|
||||
|
||||
java_test(
|
||||
name = "InterpreterFlexTest",
|
||||
size = "small",
|
||||
@ -265,7 +244,6 @@ filegroup(
|
||||
srcs = [
|
||||
"src/test/java/org/tensorflow/lite/InterpreterMobileNetTest.java",
|
||||
"src/test/java/org/tensorflow/lite/InterpreterTest.java",
|
||||
"src/test/java/org/tensorflow/lite/nnapi/NnApiDelegateTest.java",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
@ -21,8 +21,6 @@ public final class TensorFlowLite {
|
||||
private static final String PRIMARY_LIBNAME = "tensorflowlite_jni";
|
||||
private static final String FALLBACK_LIBNAME = "tensorflowlite_flex_jni";
|
||||
|
||||
private static final boolean INIT_SUCCESSFUL;
|
||||
|
||||
private TensorFlowLite() {}
|
||||
|
||||
/**
|
||||
@ -48,15 +46,9 @@ public final class TensorFlowLite {
|
||||
static native void initTensorFlow();
|
||||
|
||||
/**
|
||||
* Ensure the TensorFlowLite native library has been loaded.
|
||||
*
|
||||
* @hide
|
||||
* Load the TensorFlowLite runtime C library.
|
||||
*/
|
||||
public static boolean init() {
|
||||
return INIT_SUCCESSFUL;
|
||||
}
|
||||
|
||||
private static boolean tryInit() {
|
||||
static boolean init() {
|
||||
Throwable primaryLibException;
|
||||
try {
|
||||
System.loadLibrary(PRIMARY_LIBNAME);
|
||||
@ -78,6 +70,6 @@ public final class TensorFlowLite {
|
||||
}
|
||||
|
||||
static {
|
||||
INIT_SUCCESSFUL = tryInit();
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
package org.tensorflow.lite.nnapi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.tensorflow.lite.Interpreter;
|
||||
import org.tensorflow.lite.TestUtils;
|
||||
|
||||
/** Unit tests for {@link org.tensorflow.lite.nnapi.NnApiDelegate}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public final class NnApiDelegateTest {
|
||||
|
||||
private static final String MODEL_PATH = "tensorflow/lite/java/src/testdata/add.bin";
|
||||
private static final ByteBuffer MODEL_BUFFER = TestUtils.getTestFileAsBuffer(MODEL_PATH);
|
||||
|
||||
@Test
|
||||
public void testBasic() throws Exception {
|
||||
try (NnApiDelegate delegate = new NnApiDelegate()) {
|
||||
assertThat(delegate.getNativeHandle()).isNotEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterpreterWithNnApi() throws Exception {
|
||||
Interpreter.Options options = new Interpreter.Options();
|
||||
try (NnApiDelegate delegate = new NnApiDelegate();
|
||||
Interpreter interpreter = new Interpreter(MODEL_BUFFER, options.addDelegate(delegate))) {
|
||||
float[] oneD = {1.23f, 6.54f, 7.81f};
|
||||
float[][] twoD = {oneD, oneD, oneD, oneD, oneD, oneD, oneD, oneD};
|
||||
float[][][] threeD = {twoD, twoD, twoD, twoD, twoD, twoD, twoD, twoD};
|
||||
float[][][][] fourD = {threeD, threeD};
|
||||
float[][][][] parsedOutputs = new float[2][8][8][3];
|
||||
interpreter.run(fourD, parsedOutputs);
|
||||
float[] outputOneD = parsedOutputs[0][0][0];
|
||||
float[] expected = {3.69f, 19.62f, 23.43f};
|
||||
assertThat(outputOneD).usingTolerance(0.1f).containsExactly(expected).inOrder();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user