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

TensorFlow for Mobile Developers

TensorFlow for Mobile Developers

TensorFlow for Mobile Developers @ DroidKaigi

Enrique López Mañas

February 22, 2018
Tweet

More Decks by Enrique López Mañas

Other Decks in Programming

Transcript

  1. TensorFlow for
    Mobile Developers
    Enrique López Mañas
    Google Developer Expert

    View full-size slide

  2. Ego Slide
    • Freelance Dev
    • Google Developer Expert
    • @eenriquelopez

    View full-size slide

  3. Machine Learning / AI

    View full-size slide

  4. Machine Learning / AI

    View full-size slide

  5. Machine Learning / AI

    View full-size slide

  6. 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 full-size slide

  7. Buzzwords classification

    View full-size slide

  8. Neural Network

    View full-size slide

  9. Machine Learning

    View full-size slide

  10. Machine Learning

    View full-size slide

  11. Machine Learning
    12%
    of all
    responses
    on mobile

    View full-size slide

  12. Machine Learning

    View full-size slide

  13. Machine Learning

    View full-size slide

  14. Machine Learning

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  18. TensorFlow
    CIFAR10

    View full-size slide

  19. TensorFlow ecosystem

    View full-size slide

  20. From Training to App (@yufengg)

    View full-size slide

  21. Data Gathering?

    View full-size slide

  22. From Training to App (@yufengg)

    View full-size slide

  23. From Training to App (@yufengg)

    View full-size slide

  24. Convolutional Neural Networks (@yufengg)

    View full-size slide

  25. Convolutional Neural Networks (@yufengg)

    View full-size slide

  26. Convolutional Neural Networks (@yufengg)

    View full-size slide

  27. Convolutional Neural Networks (@yufengg)

    View full-size slide

  28. Convolutional Neural Networks (@yufengg)

    View full-size slide

  29. Convolutional Neural Networks (@yufengg)

    View full-size slide

  30. Convolutional Neural Networks (@yufengg)

    View full-size slide

  31. Convolutional Neural Networks (@yufengg)

    View full-size slide

  32. From Training to App (@yufengg)

    View full-size slide

  33. Optimizing model for Mobile (@yufengg)

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  36. From Training to App (@yufengg)

    View full-size slide

  37. From Training to App (@yufengg)

    View full-size slide

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

    View full-size slide

  39. TensorFlow community

    View full-size slide

  40. 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 full-size slide

  41. 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 full-size slide

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


    (recommend it with Android SDK Manager)

    View full-size slide

  43. Building with Android Studio
    WORKSPACE FILE

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  47. Android Samples
    TF Classify

    TF Detect


    TF Stylize

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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


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

    View full-size slide

  52. 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 full-size slide

  53. iOS Examples: simple

    View full-size slide

  54. iOS Examples: camera

    View full-size slide

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

    View full-size slide

  56. iOS Examples: benchmark

    View full-size slide

  57. Raspberry Pi

    View full-size slide

  58. 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 full-size slide

  59. Shameless self-promotion
    www.kotlinweekly.net

    View full-size slide

  60. Feedback!
    http://bit.ly/droidkaigi

    View full-size slide