aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--WORKSPACE7
-rw-r--r--models.BUILD13
-rw-r--r--tensorflow/examples/android/BUILD9
-rw-r--r--tensorflow/examples/android/README.md13
-rw-r--r--tensorflow/examples/android/assets/BUILD15
-rwxr-xr-xtensorflow/tools/ci_build/builds/android.sh10
6 files changed, 51 insertions, 16 deletions
diff --git a/WORKSPACE b/WORKSPACE
index f96dbef86e..0634cd54b3 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -463,3 +463,10 @@ http_file(
name = "weblas_weblas_js",
url = "https://raw.githubusercontent.com/waylonflinn/weblas/v0.9.0/dist/weblas.js",
)
+
+new_http_archive(
+ name = "inception5h",
+ build_file = "models.BUILD",
+ url = "https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip",
+ sha256 = "d13569f6a98159de37e92e9c8ec4dae8f674fbf475f69fe6199b514f756d4364"
+)
diff --git a/models.BUILD b/models.BUILD
new file mode 100644
index 0000000000..7c3e5a0efe
--- /dev/null
+++ b/models.BUILD
@@ -0,0 +1,13 @@
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"]) # Apache 2.0
+
+filegroup(
+ name = "model_files",
+ srcs = glob(
+ [
+ "**/*.pb",
+ "**/*.txt",
+ ],
+ ),
+)
diff --git a/tensorflow/examples/android/BUILD b/tensorflow/examples/android/BUILD
index 3e444877c5..4fd4365c01 100644
--- a/tensorflow/examples/android/BUILD
+++ b/tensorflow/examples/android/BUILD
@@ -58,8 +58,13 @@ android_binary(
]) + [
"//tensorflow/contrib/android:android_tensorflow_inference_java_srcs",
],
- assets = glob(["assets/**"]),
- assets_dir = "assets",
+ # Package assets from assets dir as well as all model targets. Remove undesired models
+ # (and corresponding Activities in source) to reduce APK size.
+ assets = [
+ "//tensorflow/examples/android/assets:asset_files",
+ "@inception5h//:model_files",
+ ],
+ assets_dir = "",
custom_package = "org.tensorflow.demo",
inline_constants = 1,
manifest = "AndroidManifest.xml",
diff --git a/tensorflow/examples/android/README.md b/tensorflow/examples/android/README.md
index 50a6351aab..b0465f7faa 100644
--- a/tensorflow/examples/android/README.md
+++ b/tensorflow/examples/android/README.md
@@ -26,8 +26,13 @@ installed the NDK and SDK. Otherwise an error such as:
be reported.
The TensorFlow `GraphDef` that contains the model definition and weights
-is not packaged in the repo because of its size. Instead, you must
-first download the file to the `assets` directory in the source tree:
+is not packaged in the repo because of its size. It will be downloaded
+automatically via a new_http_archive defined in WORKSPACE.
+
+**Optional**: If you wish to place the model in your assets manually (E.g. for
+non-Bazel builds), remove the
+`inception_5` entry in `BUILD` and download the archive yourself to the
+`assets` directory in the source tree:
```bash
$ curl -L https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip -o /tmp/inception5h.zip
@@ -38,8 +43,8 @@ $ unzip /tmp/inception5h.zip -d tensorflow/examples/android/assets/
The labels file describing the possible classification will also be in the
assets directory.
-Then, after editing your WORKSPACE file, you must build the APK. Run this from
-your workspace root:
+After editing your WORKSPACE file to update the SDK/NDK configuration,
+you may build the APK. Run this from your workspace root:
```bash
$ bazel build //tensorflow/examples/android:tensorflow_demo
diff --git a/tensorflow/examples/android/assets/BUILD b/tensorflow/examples/android/assets/BUILD
new file mode 100644
index 0000000000..c827de7be1
--- /dev/null
+++ b/tensorflow/examples/android/assets/BUILD
@@ -0,0 +1,15 @@
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"]) # Apache 2.0
+
+# It is necessary to use this filegroup rather than globbing the files in this
+# folder directly the examples/android:tensorflow_demo target due to the fact
+# that assets_dir is necessarily set to "" there (to allow using other
+# arbitrary targets as assets).
+filegroup(
+ name = "asset_files",
+ srcs = glob(
+ ["**/*"],
+ exclude = ["BUILD"],
+ ),
+)
diff --git a/tensorflow/tools/ci_build/builds/android.sh b/tensorflow/tools/ci_build/builds/android.sh
index bb90d097e7..2e40e70061 100755
--- a/tensorflow/tools/ci_build/builds/android.sh
+++ b/tensorflow/tools/ci_build/builds/android.sh
@@ -16,16 +16,6 @@
set -e
-# Download model file.
-# Note: This is workaround. This should be done by bazel.
-model_file_name="inception5h.zip"
-tmp_model_file_name="${HOME}/.cache/tensorflow_models/${model_file_name}"
-mkdir -p $(dirname ${tmp_model_file_name})
-[ -e "${tmp_model_file_name}" ] || wget -c "https://storage.googleapis.com/download.tensorflow.org/models/${model_file_name}" -O "${tmp_model_file_name}"
-# We clean up after ourselves, but not if we exit with an error, so make sure we start clean
-rm -rf tensorflow/examples/android/assets/
-unzip -o "${tmp_model_file_name}" -d tensorflow/examples/android/assets/
-
# Modify the WORKSPACE file.
# Note: This is workaround. This should be done by bazel.
if grep -q '^android_sdk_repository' WORKSPACE && grep -q '^android_ndk_repository' WORKSPACE; then