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 Slide

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

    View Slide

  3. Machine Learning / AI

    View Slide

  4. Machine Learning / AI

    View Slide

  5. Machine Learning / AI

    View 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 Slide

  7. Buzzwords classification

    View Slide

  8. Neural Network

    View Slide

  9. Machine Learning

    View Slide

  10. Machine Learning

    View Slide

  11. Machine Learning
    12%
    of all
    responses
    on mobile

    View Slide

  12. Machine Learning

    View Slide

  13. Machine Learning

    View Slide

  14. Machine Learning

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  18. TensorFlow
    CIFAR10

    View Slide

  19. TensorFlow ecosystem

    View Slide

  20. From Training to App (@yufengg)

    View Slide

  21. Data Gathering?

    View Slide

  22. From Training to App (@yufengg)

    View Slide

  23. From Training to App (@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. Convolutional Neural Networks (@yufengg)

    View Slide

  30. Convolutional Neural Networks (@yufengg)

    View Slide

  31. Convolutional Neural Networks (@yufengg)

    View Slide

  32. From Training to App (@yufengg)

    View Slide

  33. Optimizing model for Mobile (@yufengg)

    View Slide

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

    View Slide

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

    View Slide

  36. From Training to App (@yufengg)

    View Slide

  37. From Training to App (@yufengg)

    View Slide

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

    View Slide

  39. TensorFlow community

    View 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 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 Slide

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


    (recommend it with Android SDK Manager)

    View Slide

  43. Building with Android Studio
    WORKSPACE FILE

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  47. Android Samples
    TF Classify

    TF Detect


    TF Stylize

    View Slide

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

    View Slide

  49. TF Classify

    View Slide

  50. TF Classify

    View Slide

  51. TF Detect

    View Slide

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

    View Slide

  53. TF Style

    View Slide

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

    View Slide

  55. TF Style

    View Slide

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


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

    View Slide

  57. 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

  58. iOS Examples: simple

    View Slide

  59. iOS Examples: camera

    View Slide

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

    View Slide

  61. iOS Examples: benchmark

    View Slide

  62. Raspberry Pi

    View Slide

  63. 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

  64. Shameless self-promotion
    www.kotlinweekly.net

    View Slide

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

    View Slide

  66. View Slide