Auto-fetch Inception model assets for Android demo, so that manual download/extract step is unnecessary.
Change: 138475677
This commit is contained in:
parent
e1dddfb401
commit
a37ca0dc3c
@ -463,3 +463,10 @@ http_file(
|
|||||||
name = "weblas_weblas_js",
|
name = "weblas_weblas_js",
|
||||||
url = "https://raw.githubusercontent.com/waylonflinn/weblas/v0.9.0/dist/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
13
models.BUILD
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
|
licenses(["notice"]) # Apache 2.0
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "model_files",
|
||||||
|
srcs = glob(
|
||||||
|
[
|
||||||
|
"**/*.pb",
|
||||||
|
"**/*.txt",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
@ -58,8 +58,13 @@ android_binary(
|
|||||||
]) + [
|
]) + [
|
||||||
"//tensorflow/contrib/android:android_tensorflow_inference_java_srcs",
|
"//tensorflow/contrib/android:android_tensorflow_inference_java_srcs",
|
||||||
],
|
],
|
||||||
assets = glob(["assets/**"]),
|
# Package assets from assets dir as well as all model targets. Remove undesired models
|
||||||
assets_dir = "assets",
|
# (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",
|
custom_package = "org.tensorflow.demo",
|
||||||
inline_constants = 1,
|
inline_constants = 1,
|
||||||
manifest = "AndroidManifest.xml",
|
manifest = "AndroidManifest.xml",
|
||||||
|
@ -26,8 +26,13 @@ installed the NDK and SDK. Otherwise an error such as:
|
|||||||
be reported.
|
be reported.
|
||||||
|
|
||||||
The TensorFlow `GraphDef` that contains the model definition and weights
|
The TensorFlow `GraphDef` that contains the model definition and weights
|
||||||
is not packaged in the repo because of its size. Instead, you must
|
is not packaged in the repo because of its size. It will be downloaded
|
||||||
first download the file to the `assets` directory in the source tree:
|
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
|
```bash
|
||||||
$ curl -L https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip -o /tmp/inception5h.zip
|
$ 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
|
The labels file describing the possible classification will also be in the
|
||||||
assets directory.
|
assets directory.
|
||||||
|
|
||||||
Then, after editing your WORKSPACE file, you must build the APK. Run this from
|
After editing your WORKSPACE file to update the SDK/NDK configuration,
|
||||||
your workspace root:
|
you may build the APK. Run this from your workspace root:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ bazel build //tensorflow/examples/android:tensorflow_demo
|
$ bazel build //tensorflow/examples/android:tensorflow_demo
|
||||||
|
15
tensorflow/examples/android/assets/BUILD
Normal file
15
tensorflow/examples/android/assets/BUILD
Normal 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"],
|
||||||
|
),
|
||||||
|
)
|
@ -16,16 +16,6 @@
|
|||||||
|
|
||||||
set -e
|
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.
|
# Modify the WORKSPACE file.
|
||||||
# Note: This is workaround. This should be done by bazel.
|
# Note: This is workaround. This should be done by bazel.
|
||||||
if grep -q '^android_sdk_repository' WORKSPACE && grep -q '^android_ndk_repository' WORKSPACE; then
|
if grep -q '^android_sdk_repository' WORKSPACE && grep -q '^android_ndk_repository' WORKSPACE; then
|
||||||
|
Loading…
Reference in New Issue
Block a user