Skip to content

Commit

Permalink
Merge pull request tensorflow#6746 from drpngx/branch_143989623
Browse files Browse the repository at this point in the history
Branch 143989623
  • Loading branch information
drpngx authored Jan 9, 2017
2 parents 86fa8b6 + 9815d69 commit a3e636c
Show file tree
Hide file tree
Showing 70 changed files with 2,522 additions and 958 deletions.
68 changes: 68 additions & 0 deletions tensorflow/contrib/android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Android TensorFlow support

This directory contains components geared towards supporting TensorFlow on
Android.

## Android Java Inference Interface for TensorFlow

This library contains a Java API capable of loading TensorFlow graphs and
performing inference on Android. See [TensorFlowImageClassifier.java](../../examples/android/src/org/tensorflow/demo/TensorFlowImageClassifier.java)
in the [TensorFlow Android Camera Demo](../../examples/android) for an example.

With both the native .so library and the Java JAR (or AAR which combines both),
you will have everything you need to use TensorFlow for inference in your
Android app. Note that training is not supported through this interface; for
that you will have to use one of the other APIs.

For prebuilt libraries, see the
[nightly Android build artifacts](https://ci.tensorflow.org/view/Nightly/job/nightly-matrix-android/TF_BUILD_CONTAINER_TYPE=ANDROID,TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=NO_PIP,TF_BUILD_PYTHON_VERSION=PYTHON2,label=android-slave/)
page for a recent build.

To build the inference libraries yourself (if, for example, you want to support
custom TensorFlow operators), pick your preferred approach below:

### Bazel

First follow the Bazel setup instructions described in
[tensorflow/examples/android/README.md](../../examples/android/README.md)

Then, to build the native TF library:

```
bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=armeabi-v7a
```

Replacing `armeabi-v7a` with your desired target architecture.

The library will be located at:

```
bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so
```

To build the Java counterpart:

```
bazel build //tensorflow/contrib/android:android_tensorflow_inference_java
```

You will find the JAR file at:

```
bazel-bin/tensorflow/contrib/android/libandroid_tensorflow_inference_java.jar
```

### CMake

For documentation on building a self-contained AAR file with cmake, see
[tensorflow/contrib/android/cmake](cmake).


## AssetManagerFileSystem:

A TensorFlow filesystem supporting the Android asset manager. This may be
useful when writing native (C/C++) code that is tightly coupled with TensorFlow
(for typical usage the Inference Interface library above will be sufficient).
2 changes: 1 addition & 1 deletion tensorflow/contrib/cmake/tf_core_kernels.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ if(tensorflow_BUILD_CONTRIB_KERNELS)
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/count_extremely_random_stats_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/finished_nodes_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/grow_tree_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/reinterpret_string_to_float_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/sample_inputs_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/scatter_add_ndim_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/topn_ops.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/tree_predictions_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/tree_utils.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/core/ops/update_fertile_slots_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/data/reinterpret_string_to_float_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/hybrid/core/ops/hard_routing_function_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/hybrid/core/ops/k_feature_gradient_op.cc"
"${tensorflow_source_dir}/tensorflow/contrib/tensor_forest/hybrid/core/ops/k_feature_routing_function_op.cc"
Expand Down
19 changes: 0 additions & 19 deletions tensorflow/contrib/learn/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ py_library(
"//tensorflow/contrib/rnn:rnn_py",
"//tensorflow/contrib/session_bundle:exporter",
"//tensorflow/contrib/session_bundle:gc",
"//tensorflow/contrib/tensor_forest:client_lib",
"//tensorflow/contrib/tensor_forest:data_ops_py",
"//tensorflow/contrib/tensor_forest:eval_metrics",
"//tensorflow/contrib/tensor_forest:tensor_forest_py",
"//tensorflow/contrib/training:training_py",
"//tensorflow/core:protos_all_py",
"//tensorflow/python:array_ops",
Expand Down Expand Up @@ -674,21 +670,6 @@ py_test(
],
)

py_test(
name = "random_forest_test",
size = "medium",
srcs = ["python/learn/estimators/random_forest_test.py"],
srcs_version = "PY2AND3",
deps = [
":learn",
"//tensorflow/contrib/learn/python/learn/datasets",
"//tensorflow/contrib/tensor_forest:tensor_forest_py",
"//tensorflow/python:client_testlib",
"//tensorflow/python:framework_test_lib",
"//third_party/py/numpy",
],
)

py_test(
name = "dynamic_rnn_estimator_test",
size = "medium",
Expand Down
2 changes: 0 additions & 2 deletions tensorflow/contrib/learn/python/learn/estimators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ def model_fn(features, targets, mode, params):
from tensorflow.contrib.learn.python.learn.estimators.metric_key import MetricKey
from tensorflow.contrib.learn.python.learn.estimators.model_fn import ModeKeys
from tensorflow.contrib.learn.python.learn.estimators.prediction_key import PredictionKey
from tensorflow.contrib.learn.python.learn.estimators.random_forest import TensorForestEstimator
from tensorflow.contrib.learn.python.learn.estimators.random_forest import TensorForestLossHook
from tensorflow.contrib.learn.python.learn.estimators.run_config import ClusterConfig
from tensorflow.contrib.learn.python.learn.estimators.run_config import Environment
from tensorflow.contrib.learn.python.learn.estimators.run_config import RunConfig
Expand Down
44 changes: 37 additions & 7 deletions tensorflow/contrib/tensor_forest/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ filegroup(
srcs = glob(
[
"core/ops/*.cc",
"data/*.cc",
"ops/*.cc",
],
exclude = [
"core/ops/*_test.cc",
"data/*_test.cc",
],
),
)
Expand Down Expand Up @@ -70,11 +68,10 @@ py_library(
py_library(
name = "data_ops_py",
srcs = [
"data/data_ops.py",
"python/ops/data_ops.py",
],
srcs_version = "PY2AND3",
deps = [
":constants",
":tensor_forest_ops_py",
"//tensorflow/python:array_ops",
"//tensorflow/python:framework",
Expand All @@ -101,12 +98,12 @@ tf_custom_op_library(
"core/ops/count_extremely_random_stats_op.cc",
"core/ops/finished_nodes_op.cc",
"core/ops/grow_tree_op.cc",
"core/ops/reinterpret_string_to_float_op.cc",
"core/ops/sample_inputs_op.cc",
"core/ops/scatter_add_ndim_op.cc",
"core/ops/topn_ops.cc",
"core/ops/tree_predictions_op.cc",
"core/ops/update_fertile_slots_op.cc",
"data/reinterpret_string_to_float_op.cc",
"ops/tensor_forest_ops.cc",
],
deps = [":tree_utils"],
Expand All @@ -117,14 +114,14 @@ py_library(
srcs = [
"__init__.py",
"client/__init__.py",
"data/__init__.py",
"python/__init__.py",
],
srcs_version = "PY2AND3",
deps = [
":constants",
":data_ops_py",
":eval_metrics",
":random_forest",
":tensor_forest_ops_py",
":tensor_forest_py",
],
Expand Down Expand Up @@ -190,6 +187,7 @@ cc_library(
name = "tree_utils",
srcs = ["core/ops/tree_utils.cc"],
hdrs = [
"core/ops/data_spec.h",
"core/ops/tree_utils.h",
],
deps = [
Expand Down Expand Up @@ -218,7 +216,7 @@ py_test(
srcs = ["python/kernel_tests/count_extremely_random_stats_op_test.py"],
srcs_version = "PY2AND3",
deps = [
":constants",
":data_ops_py",
":tensor_forest_ops_py",
"//tensorflow/core:protos_all_py",
"//tensorflow/python:framework_test_lib",
Expand Down Expand Up @@ -259,6 +257,7 @@ py_test(
srcs = ["python/kernel_tests/sample_inputs_op_test.py"],
srcs_version = "PY2AND3",
deps = [
":data_ops_py",
":tensor_forest_ops_py",
"//tensorflow/python:framework_test_lib",
"//tensorflow/python:platform_test",
Expand Down Expand Up @@ -397,3 +396,34 @@ py_test(
"//tensorflow/python:variables",
],
)

py_library(
name = "random_forest",
srcs = ["client/random_forest.py"],
srcs_version = "PY2AND3",
deps = [
":client_lib",
":data_ops_py",
"//tensorflow/contrib/framework:framework_py",
"//tensorflow/contrib/learn",
"//tensorflow/python:control_flow_ops",
"//tensorflow/python:framework_for_generated_wrappers",
"//tensorflow/python:math_ops",
"//tensorflow/python:state_ops",
],
)

py_test(
name = "random_forest_test",
size = "medium",
srcs = ["client/random_forest_test.py"],
srcs_version = "PY2AND3",
deps = [
":random_forest",
":tensor_forest_py",
"//tensorflow/contrib/learn/python/learn/datasets",
"//tensorflow/python:client_testlib",
"//tensorflow/python:framework_test_lib",
"//third_party/py/numpy",
],
)
1 change: 0 additions & 1 deletion tensorflow/contrib/tensor_forest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@

# pylint: disable=unused-import,wildcard-import
from tensorflow.contrib.tensor_forest.client import *
from tensorflow.contrib.tensor_forest.data import *
from tensorflow.contrib.tensor_forest.python import *
# pylint: enable=unused-import,wildcard-import
1 change: 1 addition & 0 deletions tensorflow/contrib/tensor_forest/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

# pylint: disable=unused-import
from tensorflow.contrib.tensor_forest.client import eval_metrics
from tensorflow.contrib.tensor_forest.client import random_forest
# pylint: enable=unused-import
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from __future__ import print_function

from tensorflow.contrib import framework as contrib_framework
from tensorflow.contrib.framework import deprecated_arg_values
from tensorflow.contrib.framework.python.framework import experimental
from tensorflow.contrib.learn.python.learn import evaluable
from tensorflow.contrib.learn.python.learn import trainable
Expand All @@ -27,7 +26,6 @@
from tensorflow.contrib.learn.python.learn.utils import export

from tensorflow.contrib.tensor_forest.client import eval_metrics
from tensorflow.contrib.tensor_forest.data import data_ops
from tensorflow.contrib.tensor_forest.python import tensor_forest

from tensorflow.python.framework import dtypes
Expand Down Expand Up @@ -110,16 +108,12 @@ def _model_fn(features, labels):
weights = features.pop(weights_name)
if keys_name and keys_name in features:
keys = features.pop(keys_name)
processed_features, spec = data_ops.ParseDataTensorOrDict(features)
_assert_float32(processed_features)
if labels is not None:
labels = data_ops.ParseLabelTensorOrDict(labels)
_assert_float32(labels)

graph_builder = graph_builder_class(params, device_assigner=device_assigner)
inference = {eval_metrics.INFERENCE_PROB_NAME:
graph_builder.inference_graph(processed_features,
data_spec=spec)}
inference = {
eval_metrics.INFERENCE_PROB_NAME:
graph_builder.inference_graph(features)
}
if not params.regression:
inference[eval_metrics.INFERENCE_PRED_NAME] = math_ops.argmax(
inference[eval_metrics.INFERENCE_PROB_NAME], 1)
Expand All @@ -131,13 +125,11 @@ def _model_fn(features, labels):
training_loss = None
training_graph = None
if labels is not None:
training_loss = graph_builder.training_loss(processed_features, labels,
data_spec=spec,
name=LOSS_NAME)
training_loss = graph_builder.training_loss(
features, labels, name=LOSS_NAME)
training_graph = control_flow_ops.group(
graph_builder.training_graph(
processed_features, labels, data_spec=spec,
input_weights=weights),
features, labels, input_weights=weights),
state_ops.assign_add(contrib_framework.get_global_step(), 1))
# Put weights back in
if weights is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import numpy as np

from tensorflow.contrib.learn.python.learn.datasets import base
from tensorflow.contrib.learn.python.learn.estimators import random_forest
from tensorflow.contrib.tensor_forest.client import random_forest
from tensorflow.contrib.tensor_forest.python import tensor_forest
from tensorflow.python.platform import test

Expand Down
Loading

0 comments on commit a3e636c

Please sign in to comment.