Auto-fetch Inception model assets for Android demo, so that manual download/extract step is unnecessary.

Change: 138475677
This commit is contained in:
Andrew Harp 2016-11-07 21:04:11 -08:00 committed by TensorFlower Gardener
parent e1dddfb401
commit a37ca0dc3c
6 changed files with 51 additions and 16 deletions

View File

@ -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"
)

13
models.BUILD Normal file
View File

@ -0,0 +1,13 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0
filegroup(
name = "model_files",
srcs = glob(
[
"**/*.pb",
"**/*.txt",
],
),
)

View File

@ -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",

View File

@ -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

View File

@ -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"],
),
)

View File

@ -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