forked from tensorflow/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tensorflow#4503 from martinwicke/branch_133795652
Branch 133795652
- Loading branch information
Showing
104 changed files
with
3,503 additions
and
1,300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Description: | ||
# JNI-based Java inference interface for TensorFlow. | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
exports_files(["LICENSE"]) | ||
|
||
load( | ||
"//tensorflow:tensorflow.bzl", | ||
"tf_copts", | ||
"if_android", | ||
) | ||
|
||
# TODO(andrewharp): Make this an android_library or java_library. | ||
filegroup( | ||
name = "android_tensorflow_inference_java_srcs", | ||
srcs = glob(["java/**/*.java"]), | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
exports_files([ | ||
"jni/version_script.lds", | ||
]) | ||
|
||
filegroup( | ||
name = "android_tensorflow_inference_jni_srcs", | ||
srcs = glob([ | ||
"jni/**/*.cc", | ||
"jni/**/*.h", | ||
]), | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "android_tensorflow_inference_jni", | ||
srcs = if_android([":android_tensorflow_inference_jni_srcs"]), | ||
copts = tf_copts(), | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//tensorflow/core:android_tensorflow_lib_lite", | ||
], | ||
alwayslink = 1, | ||
) | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob( | ||
["**/*"], | ||
exclude = [ | ||
"**/METADATA", | ||
"**/OWNERS", | ||
"bin/**", | ||
"gen/**", | ||
], | ||
), | ||
visibility = ["//tensorflow:__subpackages__"], | ||
) |
75 changes: 75 additions & 0 deletions
75
...low/contrib/android/java/org/tensorflow/contrib/android/TensorFlowInferenceInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* Copyright 2016 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.contrib.android; | ||
|
||
import android.content.res.AssetManager; | ||
|
||
import java.util.Random; | ||
|
||
/** | ||
* JNI wrapper class for the Tensorflow native code. | ||
* | ||
* See tensorflow/examples/android/src/org/tensorflow/demo/TensorFlowImageClassifier.java | ||
* for an example usage. | ||
* */ | ||
public class TensorFlowInferenceInterface { | ||
/** | ||
* A unique identifier used to associate the Java TensorFlowInferenceInterface | ||
* with its associated native variables. | ||
* It is accessed via native reflection so any refactoring must also be accompanied | ||
* by a change to tensorflow_inference_jni.cc. | ||
*/ | ||
private final long id; | ||
|
||
public TensorFlowInferenceInterface() { | ||
id = new Random().nextLong(); | ||
} | ||
|
||
/** | ||
* Creates a native TensorFlow session for the given model. | ||
* | ||
* @param assetManager The AssetManager to use to load the model file. | ||
* @param model The filepath to the GraphDef proto representing the model. | ||
* @return The native status returned by TensorFlow. 0 indicates success. | ||
*/ | ||
public native int initializeTensorFlow(AssetManager assetManager, String model); | ||
|
||
/** | ||
* Runs inference between the previously registered input nodes (via fillNode*) | ||
* and the requested output nodes. Output nodes can then be queried with the | ||
* readNode* methods. | ||
* | ||
* @param outputNames A list of output nodes which should be filled by the inference pass. | ||
* @return The native status returned by TensorFlow. 0 indicates success. | ||
*/ | ||
public native int runInference(String[] outputNames); | ||
|
||
/** | ||
* Cleans up the native variables associated with this Object. initializeTensorFlow() can then | ||
* be called again to initialize a new session. | ||
* | ||
*/ | ||
public native void close(); | ||
|
||
// Methods for creating a native Tensor and filling it with values. | ||
public native void fillNodeFloat(String inputName, int x, int y, int z, int d, float[] values); | ||
public native void fillNodeInt(String inputName, int x, int y, int z, int d, int[] values); | ||
public native void fillNodeDouble(String inputName, int x, int y, int z, int d, double[] values); | ||
|
||
public native void readNodeFloat(String outputName, float[] values); | ||
public native void readNodeInt(String outputName, int[] values); | ||
public native void readNodeDouble(String outputName, double[] values); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.