Permalink
Browse files

Move TensorFlow's Android sample into the gradle project

  • Loading branch information...
Nilhcem committed Mar 11, 2017
1 parent d6bdb0b commit d608cadfb00b708c4a60b0685dff6c6b099948be
Showing with 54 additions and 9,200 deletions.
  1. +0 −64 android/AndroidManifest.xml
  2. +0 −132 android/BUILD
  3. +0 −174 android/README.md
  4. 0 android/__init__.py
  5. +0 −15 android/assets/BUILD
  6. +0 −64 android/bin/AndroidManifest.xml
  7. +0 −162 android/build.gradle
  8. 0 android/jni/__init__.py
  9. +0 −163 android/jni/imageutils_jni.cc
  10. +0 −300 android/jni/object_tracking/config.h
  11. +0 −306 android/jni/object_tracking/flow_cache.h
  12. +0 −308 android/jni/object_tracking/frame_pair.cc
  13. +0 −103 android/jni/object_tracking/frame_pair.h
  14. +0 −319 android/jni/object_tracking/geom.h
  15. +0 −55 android/jni/object_tracking/gl_utils.h
  16. +0 −644 android/jni/object_tracking/image-inl.h
  17. +0 −341 android/jni/object_tracking/image.h
  18. +0 −264 android/jni/object_tracking/image_data.h
  19. +0 −269 android/jni/object_tracking/image_neon.cc
  20. +0 −298 android/jni/object_tracking/image_utils.h
  21. +0 −187 android/jni/object_tracking/integral_image.h
  22. +0 −63 android/jni/object_tracking/jni_utils.h
  23. +0 −48 android/jni/object_tracking/keypoint.h
  24. +0 −548 android/jni/object_tracking/keypoint_detector.cc
  25. +0 −128 android/jni/object_tracking/keypoint_detector.h
  26. +0 −140 android/jni/object_tracking/logging.cc
  27. +0 −121 android/jni/object_tracking/logging.h
  28. +0 −27 android/jni/object_tracking/object_detector.cc
  29. +0 −230 android/jni/object_tracking/object_detector.h
  30. +0 −102 android/jni/object_tracking/object_model.h
  31. +0 −682 android/jni/object_tracking/object_tracker.cc
  32. +0 −270 android/jni/object_tracking/object_tracker.h
  33. +0 −459 android/jni/object_tracking/object_tracker_jni.cc
  34. +0 −482 android/jni/object_tracking/optical_flow.cc
  35. +0 −100 android/jni/object_tracking/optical_flow.h
  36. +0 −202 android/jni/object_tracking/sprite.h
  37. +0 −25 android/jni/object_tracking/time_log.cc
  38. +0 −137 android/jni/object_tracking/time_log.h
  39. +0 −162 android/jni/object_tracking/tracked_object.cc
  40. +0 −186 android/jni/object_tracking/tracked_object.h
  41. +0 −381 android/jni/object_tracking/utils.h
  42. +0 −151 android/jni/object_tracking/utils_neon.cc
  43. +0 −99 android/jni/rgb2yuv.cc
  44. +0 −35 android/jni/rgb2yuv.h
  45. +0 −191 android/jni/yuv2rgb.cc
  46. +0 −57 android/jni/yuv2rgb.h
  47. BIN android/sample_images/classify1.jpg
  48. BIN android/sample_images/detect1.jpg
  49. BIN android/sample_images/stylize1.jpg
  50. +54 −6 app/src/main/AndroidManifest.xml
  51. 0 {android/src → app/src/main/java}/org/tensorflow/demo/AutoFitTextureView.java
  52. 0 {android/src → app/src/main/java}/org/tensorflow/demo/CameraActivity.java
  53. 0 {android/src → app/src/main/java}/org/tensorflow/demo/CameraConnectionFragment.java
  54. 0 {android/src → app/src/main/java}/org/tensorflow/demo/Classifier.java
  55. 0 {android/src → app/src/main/java}/org/tensorflow/demo/ClassifierActivity.java
  56. 0 {android/src → app/src/main/java}/org/tensorflow/demo/DetectorActivity.java
  57. 0 {android/src → app/src/main/java}/org/tensorflow/demo/OverlayView.java
  58. 0 {android/src → app/src/main/java}/org/tensorflow/demo/RecognitionScoreView.java
  59. 0 {android/src → app/src/main/java}/org/tensorflow/demo/ResultsView.java
  60. 0 {android/src → app/src/main/java}/org/tensorflow/demo/StylizeActivity.java
  61. 0 {android/src → app/src/main/java}/org/tensorflow/demo/TensorFlowImageClassifier.java
  62. 0 {android/src → app/src/main/java}/org/tensorflow/demo/TensorFlowMultiBoxDetector.java
  63. 0 {android/src → app/src/main/java}/org/tensorflow/demo/TensorFlowYoloDetector.java
  64. 0 {android/src → app/src/main/java}/org/tensorflow/demo/env/BorderedText.java
  65. 0 {android/src → app/src/main/java}/org/tensorflow/demo/env/ImageUtils.java
  66. 0 {android/src → app/src/main/java}/org/tensorflow/demo/env/Logger.java
  67. 0 {android/src → app/src/main/java}/org/tensorflow/demo/env/Size.java
  68. 0 {android/src → app/src/main/java}/org/tensorflow/demo/env/SplitTimer.java
  69. 0 {android/src → app/src/main/java}/org/tensorflow/demo/tracking/MultiBoxTracker.java
  70. 0 {android/src → app/src/main/java}/org/tensorflow/demo/tracking/ObjectTracker.java
  71. BIN {android → app/src/main}/res/drawable-hdpi/ic_action_info.png
  72. BIN {android → app/src/main}/res/drawable-hdpi/ic_launcher.png
  73. BIN {android → app/src/main}/res/drawable-hdpi/tile.9.png
  74. BIN {android → app/src/main}/res/drawable-mdpi/ic_action_info.png
  75. BIN {android → app/src/main}/res/drawable-mdpi/ic_launcher.png
  76. BIN {android → app/src/main}/res/drawable-xhdpi/ic_action_info.png
  77. BIN {android → app/src/main}/res/drawable-xhdpi/ic_launcher.png
  78. BIN {android → app/src/main}/res/drawable-xxhdpi/ic_action_info.png
  79. BIN {android → app/src/main}/res/drawable-xxhdpi/ic_launcher.png
  80. 0 {android → app/src/main}/res/layout/activity_camera.xml
  81. 0 {android → app/src/main}/res/layout/camera_connection_fragment.xml
  82. 0 {android → app/src/main}/res/layout/camera_connection_fragment_stylize.xml
  83. 0 {android → app/src/main}/res/layout/camera_connection_fragment_tracking.xml
  84. 0 {android → app/src/main}/res/values-sw600dp/template-dimens.xml
  85. 0 {android → app/src/main}/res/values-sw600dp/template-styles.xml
  86. 0 {android → app/src/main}/res/values-v11/styles.xml
  87. 0 {android → app/src/main}/res/values-v11/template-styles.xml
  88. 0 {android → app/src/main}/res/values-v14/styles.xml
  89. 0 {android → app/src/main}/res/values-v21/base-colors.xml
  90. 0 {android → app/src/main}/res/values-v21/base-template-styles.xml
  91. 0 {android → app/src/main}/res/values/attrs.xml
  92. 0 {android → app/src/main}/res/values/base-strings.xml
  93. 0 {android → app/src/main}/res/values/colors.xml
  94. 0 {android → app/src/main}/res/values/strings.xml
  95. 0 {android → app/src/main}/res/values/styles.xml
  96. 0 {android → app/src/main}/res/values/template-dimens.xml
  97. 0 {android → app/src/main}/res/values/template-styles.xml
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright 2016 The TensorFlow Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.tensorflow.demo">
-
- <uses-permission android:name="android.permission.CAMERA" />
- <uses-feature android:name="android.hardware.camera" />
- <uses-feature android:name="android.hardware.camera.autofocus" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
-
- <uses-sdk
- android:minSdkVersion="21"
- android:targetSdkVersion="23" />
-
- <application android:allowBackup="true"
- android:debuggable="true"
- android:label="@string/app_name"
- android:icon="@drawable/ic_launcher"
- android:theme="@style/MaterialTheme">
-
- <activity android:name="org.tensorflow.demo.ClassifierActivity"
- android:screenOrientation="portrait"
- android:label="@string/activity_name_classification">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
-
- <activity android:name="org.tensorflow.demo.DetectorActivity"
- android:screenOrientation="portrait"
- android:label="@string/activity_name_detection">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
-
- <activity android:name="org.tensorflow.demo.StylizeActivity"
- android:screenOrientation="portrait"
- android:label="@string/activity_name_stylize">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-
-</manifest>
View
@@ -1,132 +0,0 @@
-# Description:
-# TensorFlow camera demo app for Android.
-
-package(default_visibility = ["//visibility:public"])
-
-licenses(["notice"]) # Apache 2.0
-
-load(
- "//tensorflow:tensorflow.bzl",
- "tf_copts",
- "tf_opts_nortti_if_android",
-)
-
-exports_files(["LICENSE"])
-
-LINKER_SCRIPT = "//tensorflow/contrib/android:jni/version_script.lds"
-
-# libtensorflow_demo.so contains the native code for image colorspace conversion
-# and object tracking used by the demo. It does not require TF as a dependency
-# to build if STANDALONE_DEMO_LIB is defined.
-# TF support for the demo is provided separately by libtensorflow_inference.so.
-cc_binary(
- name = "libtensorflow_demo.so",
- srcs = glob([
- "jni/**/*.cc",
- "jni/**/*.h",
- ]),
- copts = tf_copts(),
- defines = ["STANDALONE_DEMO_LIB"],
- linkopts = [
- "-landroid",
- "-ljnigraphics",
- "-llog",
- "-lm",
- "-z defs",
- "-s",
- "-Wl,--version-script", # This line must be directly followed by LINKER_SCRIPT.
- LINKER_SCRIPT,
- ],
- linkshared = 1,
- linkstatic = 1,
- tags = [
- "manual",
- "notap",
- ],
- deps = [
- LINKER_SCRIPT,
- ],
-)
-
-cc_library(
- name = "tensorflow_native_libs",
- srcs = [
- ":libtensorflow_demo.so",
- "//tensorflow/contrib/android:libtensorflow_inference.so",
- ],
- tags = [
- "manual",
- "notap",
- ],
-)
-
-android_binary(
- name = "tensorflow_demo",
- srcs = glob([
- "src/**/*.java",
- ]),
- # 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",
- ":external_assets",
- ],
- assets_dir = "",
- custom_package = "org.tensorflow.demo",
- inline_constants = 1,
- manifest = "AndroidManifest.xml",
- resource_files = glob(["res/**"]),
- tags = [
- "manual",
- "notap",
- ],
- deps = [
- ":tensorflow_native_libs",
- "//tensorflow/contrib/android:android_tensorflow_inference_java",
- ],
-)
-
-filegroup(
- name = "external_assets",
- srcs = [
- "@inception5h//:model_files",
- "@mobile_multibox//:model_files",
- "@stylize//:model_files",
- ],
-)
-
-filegroup(
- name = "all_files",
- srcs = glob(
- ["**/*"],
- exclude = [
- "**/METADATA",
- "**/OWNERS",
- "bin/**",
- "gen/**",
- "gradleBuild/**",
- "libs/**",
- ],
- ),
- visibility = ["//tensorflow:__subpackages__"],
-)
-
-filegroup(
- name = "java_files",
- srcs = glob(["src/**/*.java"]),
-)
-
-filegroup(
- name = "jni_files",
- srcs = glob([
- "jni/**/*.cc",
- "jni/**/*.h",
- ]),
-)
-
-filegroup(
- name = "resource_files",
- srcs = glob(["res/**"]),
-)
-
-exports_files(["AndroidManifest.xml"])
View
@@ -1,174 +0,0 @@
-# TensorFlow Android Camera Demo
-
-This folder contains an example application utilizing TensorFlow for Android
-devices.
-
-## Description
-
-The demos in this folder are designed to give straightforward samples of using
-TensorFlow in mobile applications.
-
-Inference is done using the [TensorFlow Android Inference Interface](../../../tensorflow/contrib/android),
-which may be built separately if you want a standalone library to drop into your
-existing application. Object tracking and YUV -> RGB conversion is handled by
-libtensorflow_demo.so.
-
-A device running Android 5.0 (API 21) or higher is required to run the demo due
-to the use of the camera2 API, although the native libraries themselves can run
-on API >= 14 devices.
-
-## Current samples:
-
-1. [TF Classify](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/ClassifierActivity.java):
- Uses the [Google Inception](https://arxiv.org/abs/1409.4842)
- model to classify camera frames in real-time, displaying the top results
- in an overlay on the camera image.
-2. [TF Detect](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/DetectorActivity.java):
- Demonstrates a model based on [Scalable Object Detection
- using Deep Neural Networks](https://arxiv.org/abs/1312.2249) to
- localize and track people in the camera preview in real-time.
-3. [TF Stylize](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/StylizeActivity.java):
- Uses a model based on [A Learned Representation For Artistic Style]
- (https://arxiv.org/abs/1610.07629) to restyle the camera preview image
- to that of a number of different artists.
-
-<img src="sample_images/classify1.jpg" width="30%">
-<img src="sample_images/stylize1.jpg" width="30%">
-<img src="sample_images/detect1.jpg" width="30%">
-
-## Prebuilt APK:
-
-If you just want the fastest path to trying the demo, you may download the
-nightly build
-[here](https://ci.tensorflow.org/view/Nightly/job/nightly-android/). Expand the
-"View" and then the "out" folders under "Last Successful Artifacts" to find
-tensorflow_demo.apk. Also available are precompiled native libraries that you
-may drop into your own applications. See
-[tensorflow/contrib/android/README.md](../../../tensorflow/contrib/android/README.md)
-for more details.
-
-## Running the Demo
-
-Once the app is installed it can be started via the "TF Classify", "TF Detect"
-and "TF Stylize" icons, which have the orange TensorFlow logo as their icon.
-
-While running the activities, pressing the volume keys on your device will
-toggle debug visualizations on/off, rendering additional info to the screen
-that may be useful for development purposes.
-
-## Building the Demo from Source
-
-Pick your preferred approach below. At the moment, we have full support for
-Bazel, and partial support for gradle, cmake, make, and Android Studio.
-
-As a first step for all build types, clone the TensorFlow repo with:
-
-```
-git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
-```
-
-Note that `--recurse-submodules` is necessary to prevent some issues with
-protobuf compilation.
-
-### Bazel
-
-NOTE: Bazel does not currently support building for Android on Windows. Full
-support for gradle/cmake builds is coming soon, but in the meantime we suggest
-that Windows users download the
-[prebuilt binaries](https://ci.tensorflow.org/view/Nightly/job/nightly-android/)
-instead.
-
-##### Install Bazel and Android Prerequisites
-
-Bazel is the primary build system for TensorFlow. To build with Bazel,
-it and the Android NDK and SDK must be installed on your system.
-
-1. Get the recommended Bazel version listed in [os_setup.html](https://www.tensorflow.org/versions/master/get_started/os_setup.html#source)
-2. The Android NDK is required to build the native (C/C++) TensorFlow code.
- The current recommended version is 12b, which may be found
- [here](https://developer.android.com/ndk/downloads/older_releases.html#ndk-12b-downloads).
-3. The Android SDK and build tools may be obtained
- [here](https://developer.android.com/tools/revisions/build-tools.html),
- or alternatively as part of
- [Android Studio](https://developer.android.com/studio/index.html). Build
- tools API >= 23 is required to build the TF Android demo (though it will
- run on API >= 21 devices).
-
-##### Edit WORKSPACE
-
-The Android entries in [`<workspace_root>/WORKSPACE`](../../../WORKSPACE#L2-L13)
-must be uncommented with the paths filled in appropriately depending on where
-you installed the NDK and SDK. Otherwise an error such as:
-"The external label '//external:android/sdk' is not bound to anything" will
-be reported.
-
-Also edit the API levels for the SDK in WORKSPACE to the highest level you
-have installed in your SDK. This must be >= 23 (this is completely independent
-of the API level of the demo, which is defined in AndroidManifest.xml).
-The NDK API level may remain at 14.
-
-##### Install Model Files (optional)
-
-The TensorFlow `GraphDef`s that contain the model definitions and weights
-are not packaged in the repo because of their size. They are downloaded
-automatically and packaged with the APK by Bazel via a new_http_archive defined
-in `WORKSPACE` during the build process.
-
-**Optional**: If you wish to place the models in your assets manually (E.g. for
-non-Bazel builds), remove all of the `model_files` entries from the `assets`
-list in `tensorflow_demo` found in the `[BUILD](BUILD)` file. Then download
-and extract the archives yourself to the `assets` directory in the source tree:
-
-```bash
-BASE_URL=https://storage.googleapis.com/download.tensorflow.org/models
-for MODEL_ZIP in inception5h.zip mobile_multibox_v1a.zip stylize_v1.zip
-do
- curl -L ${BASE_URL}/${MODEL_ZIP} -o /tmp/${MODEL_ZIP}
- unzip /tmp/${MODEL_ZIP} -d tensorflow/examples/android/assets/
-done
-```
-
-This will extract the models and their associated metadata files to the local
-assets/ directory.
-
-##### Build
-
-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 -c opt //tensorflow/examples/android:tensorflow_demo
-```
-
-If you get build errors about protocol buffers, run
-`git submodule update --init` and make sure that you've modified your WORKSPACE
-file as instructed, then try building again.
-
-##### Install
-
-Make sure that adb debugging is enabled on your Android 5.0 (API 21) or
-later device, then after building use the following command from your workspace
-root to install the APK:
-
-```bash
-adb install -r bazel-bin/tensorflow/examples/android/tensorflow_demo.apk
-```
-
-### Android Studio
-
-Android Studio may be used to build the demo in conjunction with Bazel. First,
-make sure that you can build with Bazel following the above directions. Then,
-look at [build.gradle](build.gradle) and make sure that the path to Bazel
-matches that of your system.
-
-At this point you can add the tensorflow/examples/android directory as a new
-Android Studio project. Click through installing all the Gradle extensions it
-requests, and you should be able to have Android Studio build the demo like any
-other application (it will call out to Bazel to build the native code with the
-NDK).
-
-### CMake
-
-Full CMake support for the demo is coming soon, but for now it is possible to
-build the TensorFlow Android Inference library using
-[tensorflow/contrib/android/cmake](../../../tensorflow/contrib/android/cmake).
View
No changes.
View
@@ -1,15 +0,0 @@
-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"],
- ),
-)
Oops, something went wrong.

0 comments on commit d608cad

Please sign in to comment.