File tree Expand file tree Collapse file tree 6 files changed +51
-16
lines changed Expand file tree Collapse file tree 6 files changed +51
-16
lines changed Original file line number Diff line number Diff line change @@ -463,3 +463,10 @@ http_file(
463
463
name = "weblas_weblas_js" ,
464
464
url = "https://raw.githubusercontent.com/waylonflinn/weblas/v0.9.0/dist/weblas.js" ,
465
465
)
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
+ )
Original file line number Diff line number Diff line change
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
+ )
Original file line number Diff line number Diff line change @@ -58,8 +58,13 @@ android_binary(
58
58
]) + [
59
59
"//tensorflow/contrib/android:android_tensorflow_inference_java_srcs" ,
60
60
],
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 = "" ,
63
68
custom_package = "org.tensorflow.demo" ,
64
69
inline_constants = 1 ,
65
70
manifest = "AndroidManifest.xml" ,
Original file line number Diff line number Diff line change @@ -26,8 +26,13 @@ installed the NDK and SDK. Otherwise an error such as:
26
26
be reported.
27
27
28
28
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:
31
36
32
37
``` bash
33
38
$ 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/
38
43
The labels file describing the possible classification will also be in the
39
44
assets directory.
40
45
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:
43
48
44
49
``` bash
45
50
$ bazel build //tensorflow/examples/android:tensorflow_demo
Original file line number Diff line number Diff line change
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
+ )
Original file line number Diff line number Diff line change 16
16
17
17
set -e
18
18
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
-
29
19
# Modify the WORKSPACE file.
30
20
# Note: This is workaround. This should be done by bazel.
31
21
if grep -q ' ^android_sdk_repository' WORKSPACE && grep -q ' ^android_ndk_repository' WORKSPACE; then
You can’t perform that action at this time.
0 commit comments