Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TensorFlow for Mobile Developers

TensorFlow for Mobile Developers

Enrique López Mañas

October 25, 2017
Tweet

More Decks by Enrique López Mañas

Other Decks in Technology

Transcript

  1. TensorFlow for
    Mobile Developers

    View Slide

  2. Machine Learning / AI

    View Slide

  3. Buzzwords classification
    Artificial intelligence
    Machine Learning
    The science of making machines smarts
    Building machines that can learn
    Neural Networks
    One of the many different algorithms in Machine Learning

    View Slide

  4. Buzzwords classification

    View Slide

  5. Neural Network

    View Slide

  6. Machine Learning

    View Slide

  7. Machine Learning

    View Slide

  8. Machine Learning
    12%
    of all
    responses
    on mobile

    View Slide

  9. Machine Learning

    View Slide

  10. Machine Learning

    View Slide

  11. Machine Learning

    View Slide

  12. Cloud vs. Mobile
    Less Traffic & Faster Response
    Motion Sensors

    View Slide

  13. TensorFlow
    OpenSource library for Machine Learning
    tensorflow.org
    Today most popular ML framework

    View Slide

  14. TensorFlow
    You can train:
    - Mac / Windows
    - GPU Server
    - GPU/TPU on Cloud
    Prediction:
    - Android
    - iOS
    - Raspberry

    View Slide

  15. TensorFlow
    CIFAR10

    View Slide

  16. TensorFlow ecosystem

    View Slide

  17. From Training to App (@yufengg)

    View Slide

  18. Data Gathering?

    View Slide

  19. From Training to App (@yufengg)

    View Slide

  20. From Training to App (@yufengg)

    View Slide

  21. Convolutional Neural Networks (@yufengg)

    View Slide

  22. Convolutional Neural Networks (@yufengg)

    View Slide

  23. Convolutional Neural Networks (@yufengg)

    View Slide

  24. Convolutional Neural Networks (@yufengg)

    View Slide

  25. Convolutional Neural Networks (@yufengg)

    View Slide

  26. Convolutional Neural Networks (@yufengg)

    View Slide

  27. Convolutional Neural Networks (@yufengg)

    View Slide

  28. Convolutional Neural Networks (@yufengg)

    View Slide

  29. From Training to App (@yufengg)

    View Slide

  30. Optimizing model for Mobile (@yufengg)

    View Slide

  31. From Training to App (@yufengg)
    Other inception versions
    (inception v1 quantised is 7 MB)

    View Slide

  32. From Training to App (@yufengg)
    TensorFlow increases APK in 12 MB

    View Slide

  33. From Training to App (@yufengg)

    View Slide

  34. From Training to App (@yufengg)

    View Slide

  35. TensorFlow community
    1000+ contributors
    22.000+ commits
    18.000+ repositories with name “TensorFlow”

    View Slide

  36. TensorFlow community

    View Slide

  37. Building with Android Studio
    Uses Bazel to build
    Set Bazel binary location in /tensorflow/examples/
    android/build.gradle
    Add project in tensorflor/examples/android folder
    to Android Studio

    View Slide

  38. Building with Android Studio
    Installing Bazel first:
    Download from https://github.com/bazelbuild/bazel/releases
    Install instructions in https://docs.bazel.build/versions/master/install.html

    View Slide

  39. Building with Android Studio
    Download Android SDK (23)
    Download Android NDK (12b)


    (recommend it with Android SDK Manager)

    View Slide

  40. Building with Android Studio
    WORKSPACE FILE

    View Slide

  41. Building with Android Studio
    Run Bazel
    bazel build -c opt //tensorflow/examples/
    android:tensorflow_demo

    View Slide

  42. Building with Android Studio
    Install APK
    adb install -r bazel-bin/tensorflow/examples/android/
    tensorflow_demo.apk

    View Slide

  43. Building with Android Studio
    OR…
    TensorFlow AAR from JCenter
    YUV -> RGB less efficient
    Object tracking not available

    View Slide

  44. Android Samples
    TF Classify

    TF Detect


    TF Stylize

    View Slide

  45. TF Classify
    Uses Google Inception (v3) to label images
    Model easy to swap
    No “person label”
    Volume button up for statistics

    View Slide

  46. TF Classify

    View Slide

  47. TF Classify

    View Slide

  48. TF Detect

    View Slide

  49. TF Detect
    - Draw bounding boxes around people
    - Useful to count objects
    - No training yet

    View Slide

  50. TF Style

    View Slide

  51. TF Style
    - Real time style transfer algorithm
    - Pick/mix different styles
    - Can train Magenta models

    View Slide

  52. TF Style

    View Slide

  53. TensorFlow
    Written in C++
    Android uses Kotlin/Java?


    HowTo?
    Android inference Library
    https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/android

    View Slide

  54. Building for iOS
    Install requirements:
    - Xcode 8
    - Command line tools (xcode-select install)
    - brew install automake
    - brew install lib tool
    - tensorflow/contrib/makefile_build_all_ios.sh (takes 20 minutes)

    View Slide

  55. iOS Examples: simple

    View Slide

  56. iOS Examples: camera

    View Slide

  57. iOS Examples: camera
    - Run inception each frame
    - Models can be replaced

    View Slide

  58. iOS Examples: benchmark

    View Slide

  59. Raspberry Pi

    View Slide

  60. Resources
    TensorFlow: https://www.tensorflow.org/
    Magenta: https://magenta.tensorflow.org/welcome-to-magenta
    TensorFlow for Poets: https://codelabs.developers.google.com/codelabs/
    tensorflow-for-poets/index.html#0

    View Slide