Skip to content

Commit a37ca0d

Browse files
andrewharptensorflower-gardener
authored andcommitted
Auto-fetch Inception model assets for Android demo, so that manual download/extract step is unnecessary.
Change: 138475677
1 parent e1dddfb commit a37ca0d

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

WORKSPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,10 @@ http_file(
463463
name = "weblas_weblas_js",
464464
url = "https://raw.githubusercontent.com/waylonflinn/weblas/v0.9.0/dist/weblas.js",
465465
)
466+
467+
new_http_archive(
468+
name = "inception5h",
469+
build_file = "models.BUILD",
470+
url = "https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip",
471+
sha256 = "d13569f6a98159de37e92e9c8ec4dae8f674fbf475f69fe6199b514f756d4364"
472+
)

models.BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
licenses(["notice"]) # Apache 2.0
4+
5+
filegroup(
6+
name = "model_files",
7+
srcs = glob(
8+
[
9+
"**/*.pb",
10+
"**/*.txt",
11+
],
12+
),
13+
)

tensorflow/examples/android/BUILD

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ android_binary(
5858
]) + [
5959
"//tensorflow/contrib/android:android_tensorflow_inference_java_srcs",
6060
],
61-
assets = glob(["assets/**"]),
62-
assets_dir = "assets",
61+
# Package assets from assets dir as well as all model targets. Remove undesired models
62+
# (and corresponding Activities in source) to reduce APK size.
63+
assets = [
64+
"//tensorflow/examples/android/assets:asset_files",
65+
"@inception5h//:model_files",
66+
],
67+
assets_dir = "",
6368
custom_package = "org.tensorflow.demo",
6469
inline_constants = 1,
6570
manifest = "AndroidManifest.xml",

tensorflow/examples/android/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ installed the NDK and SDK. Otherwise an error such as:
2626
be reported.
2727

2828
The TensorFlow `GraphDef` that contains the model definition and weights
29-
is not packaged in the repo because of its size. Instead, you must
30-
first download the file to the `assets` directory in the source tree:
29+
is not packaged in the repo because of its size. It will be downloaded
30+
automatically via a new_http_archive defined in WORKSPACE.
31+
32+
**Optional**: If you wish to place the model in your assets manually (E.g. for
33+
non-Bazel builds), remove the
34+
`inception_5` entry in `BUILD` and download the archive yourself to the
35+
`assets` directory in the source tree:
3136

3237
```bash
3338
$ 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/
3843
The labels file describing the possible classification will also be in the
3944
assets directory.
4045

41-
Then, after editing your WORKSPACE file, you must build the APK. Run this from
42-
your workspace root:
46+
After editing your WORKSPACE file to update the SDK/NDK configuration,
47+
you may build the APK. Run this from your workspace root:
4348

4449
```bash
4550
$ bazel build //tensorflow/examples/android:tensorflow_demo
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
licenses(["notice"]) # Apache 2.0
4+
5+
# It is necessary to use this filegroup rather than globbing the files in this
6+
# folder directly the examples/android:tensorflow_demo target due to the fact
7+
# that assets_dir is necessarily set to "" there (to allow using other
8+
# arbitrary targets as assets).
9+
filegroup(
10+
name = "asset_files",
11+
srcs = glob(
12+
["**/*"],
13+
exclude = ["BUILD"],
14+
),
15+
)

tensorflow/tools/ci_build/builds/android.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@
1616

1717
set -e
1818

19-
# Download model file.
20-
# Note: This is workaround. This should be done by bazel.
21-
model_file_name="inception5h.zip"
22-
tmp_model_file_name="${HOME}/.cache/tensorflow_models/${model_file_name}"
23-
mkdir -p $(dirname ${tmp_model_file_name})
24-
[ -e "${tmp_model_file_name}" ] || wget -c "https://storage.googleapis.com/download.tensorflow.org/models/${model_file_name}" -O "${tmp_model_file_name}"
25-
# We clean up after ourselves, but not if we exit with an error, so make sure we start clean
26-
rm -rf tensorflow/examples/android/assets/
27-
unzip -o "${tmp_model_file_name}" -d tensorflow/examples/android/assets/
28-
2919
# Modify the WORKSPACE file.
3020
# Note: This is workaround. This should be done by bazel.
3121
if grep -q '^android_sdk_repository' WORKSPACE && grep -q '^android_ndk_repository' WORKSPACE; then

0 commit comments

Comments
 (0)