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

Making Android Apps with Intelligence - Faceboo...

Making Android Apps with Intelligence - Facebook University

Talk at Facebook University Seattle.

Margaret Maynard-Reid

July 06, 2017
Tweet

More Decks by Margaret Maynard-Reid

Other Decks in Technology

Transcript

  1. @margaretmz | #AndroidDev | #MachineLearning About me 2 • Android

    developer, MS AI & Research • AI/ML student @Udacity • Lead organizer, GDG Seattle • Co-organizer, SeaDroid & Eastside Android • Taught Android @UW
  2. @margaretmz | #AndroidDev | #MachineLearning Machine learning everywhere! • Google

    TensorFlow makes music • IBM Watson creates movie trailer • Uber uses Microsoft Cognitive services to selfie check drivers 4
  3. @margaretmz | #AndroidDev | #MachineLearning AI, ML & Deep learning

    5 Artificial intelligence Machine Learning Deep Learning
  4. @margaretmz | #AndroidDev | #MachineLearning What is Machine Learning? •

    A subset of Artificial Intelligence • Study of algorithms • Learn from examples and experience (instead of hard-coded programming rules) Source: ML Recipes #1 by Google Developers - https://www.youtube.com/watch?v=cKxRvEZd3Mw Use model to predict Train a model Collect training data 6
  5. @margaretmz | #AndroidDev | #MachineLearning Goals of this talk •

    Get started with making apps with intelligence • Share ML resources • Understand the importance of ML for app developers • Disclaimer: not a crash course on ML 7
  6. @margaretmz | #AndroidDev | #MachineLearning Make Apps with Intelligence Complexity

    ML Services (via REST APIs) Vision Speech Language Text… (Google, Microsoft, IBM, HP…) ML Services ( train or build your ML models) Microsoft LUIS TensorFlow Google Cloud ML Platform Amazon ML Platform Google Play Services Mobile Vision API 8
  7. @margaretmz | #AndroidDev | #MachineLearning Google Mobile Vision API •

    Part of the Google Play services • Very easy to get started • Can detect: ◦ Face (FaceDetector) | codelab ◦ Barcode (BarcodeDetector) | codelab ◦ Text (TextRecognizer) | codelab • Developer documentation on Mobile Vision API (https://developers.google.com/vision/) • I/O 17 talk - Getting Started with Machine Perception Using the Mobile Vision API (https://youtu.be/KKRbwO06SwQ) 10
  8. @margaretmz | #AndroidDev | #MachineLearning Mobile Vision API - Face

    Detection • Detect one or multiple faces • Facial detection not recognition • Detection from image or live video • Face can be detected from different angles • Detects activities: ◦ winking, blinking and smiling • Detect landmarks on face 11
  9. @margaretmz | #AndroidDev | #MachineLearning Face detector Add this to

    app build.gradle file Create a detector Make sure detector is operational first com.google.android.gms:play-services-vision:9.2.1 FaceDetector faceDetector = new FaceDetector.Builder(getApplicationContext()) .setTrackingEnabled(false) .build(); if(!faceDetector.isOperational()){ // let user know face detector isn’t working // log error etc... } 12
  10. @margaretmz | #AndroidDev | #MachineLearning Face detector Detect the face(s)

    Draw Rectangles on the Faces Refer to Face Detection with Vision API code lab for details... Frame frame = new Frame.Builder().setBitmap(myBitmap).build(); SparseArray<Face> faces = faceDetector.detect(frame); 13
  11. @margaretmz | #AndroidDev | #MachineLearning Slide & video credit: Google

    1. Create a face detector for facial landmarks (e.g., eyes) 3. For each face, draw the eyes FaceDetector detector = new FaceDetector.Builder() .setLandmarkType(FaceDetector.ALL_LANDMARKS) .build(); SparseArray<Face> faces = detector.detect(image); for (int i = 0; i < faces.size(); ++i) { Face face = faces.valueAt(i); for (Landmark landmark : face.getLandmarks()) { // Draw eyes 2. Detect faces in the image 14 Googly Eyes Android App
  12. @margaretmz | #AndroidDev | #MachineLearning Mobile Vision API - Barcode

    Detection • Detects barcodes in real-time, on device, in any orientation. • Detects multiple barcodes at once • Detects and parses barcodes and Qr codes of various formats 15
  13. @margaretmz | #AndroidDev | #MachineLearning Mobile Vision API - Text

    Recognition • Detects text in real-time, on device. • Detects text in Latin based languages (French, German, English, etc.) • Recognizes text in images and video streams 16
  14. @margaretmz | #AndroidDev | #MachineLearning REST API calls ML REST

    APIs Vision Speech Language Text Translate Search…. HTTP response images text HTTP call audio video 18
  15. @margaretmz | #AndroidDev | #MachineLearning Getting started Free trial based

    on time or # of transactions A typical process: • Get an API key • Include key in Android app • Download SDK or include dependency in build.gradle (if sdk available) • Make your REST API calls 19
  16. @margaretmz | #AndroidDev | #MachineLearning Machine learning services Pre-trained models

    No need for much ML knowledge Just REST API calls “Try out the APIs” directly online from the websites • Google Cloud ML APIs • Microsoft Cognitive Services • IBM Watson • HPE Haven OnDemand 20
  17. @margaretmz | #AndroidDev | #MachineLearning Cloud ML services demo •

    Google Cloud vision API - drag and drop an image for analysis • Microsoft emotion API - recognize emotions • HP Haven on demand 21
  18. @margaretmz | #AndroidDev | #MachineLearning Microsoft Vision APIs Vision APIs

    • Computer Vision, Emotion & Face Can detect • Gender • Age • Emotions etc. Demo: SampleVision - image caption 22
  19. @margaretmz | #AndroidDev | #MachineLearning Demo - Mimicker Alarm This

    Android app uses 3 ML APIs: • Computer Vision - find a color • Emotion - facial expression • Speech - tongue twister Source code - https://github.com/Microsoft/ProjectOxford-Apps-MimickerAlarm 23
  20. @margaretmz | #AndroidDev | #MachineLearning ML Services Train a pre-trained

    model, or build your own ML models - • Microsoft LUIS • Google TensorFlow • Google Cloud ML Platform • Amazon ML 25
  21. @margaretmz | #AndroidDev | #MachineLearning Microsoft LUIS Language Understanding Intelligence

    Service - • User friendly web interface • Train a pre-built language understanding model • Deploy model to an http endpoint - interprets human language • Use the model on mobile app - JSON response 26
  22. @margaretmz | #AndroidDev | #MachineLearning LUIS demo - create a

    weather app 1. Go to https://www.luis.ai/ 2. Create an Application - “Weather app demo” 3. Add two Pre-built Entities: geography & datetime 4. Add an Intent • Name = “GetWeather” • Example utterance = “What is the weather like in Seattle today?” • Two parameters “where” (geography) & “when” (datetime) 5. Train with a few New Utterances (at least 5) • What is the weather in San Francisco this Sunday? • What is the weather in New York tomorrow? 6. Publish the http endpoint which can then be used in your app 27
  23. @margaretmz | #AndroidDev | #MachineLearning TensorFlow • The most popular

    Open source Machine Learning library • Especially useful for Deep Learning • For research and production • Apache 2.0 license • 1.0.1 released recently 28
  24. @margaretmz | #AndroidDev | #MachineLearning TensorFlow on mobile • Android

    and iOS • Android sample app with TensorFlow ◦ TF Classify (demo) ◦ TF Detect ◦ TF Stylize (demo) • Checkout all TensorFlow Dev Summit videos ◦ Pete Warden’s talk Mobile and Embedded TensorFlow ◦ TensorFlow on Android by Yufeng Guo 29
  25. @margaretmz | #AndroidDev | #MachineLearning TensorFlow on Android Android app

    for recognizing handwritten digits by Marianne Linhares Source code https://github.com/mari-linhares/mnist-android-tensorflow 30
  26. @margaretmz | #AndroidDev | #MachineLearning Android meets TensorFlow Add TensorFlow

    Android Inference library and Java API to build.gradle dependencies { compile 'org.tensorflow:tensorflow-android:1.2.0-preview' } Link to talk: Android meets TensorFlow 31 +
  27. @margaretmz | #AndroidDev | #MachineLearning Code lab: TensorFlow for Poets

    • Install and run the TensorFlow Docker image • Retrieve the images (flowers: daisy, dandelion, roses, sunflowers, & tulips) • Retrain the final layer of Inception 3 • Use the retrained model to classify an image https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/#0 32
  28. @margaretmz | #AndroidDev | #MachineLearning Amazon Alexa Voice Service Voice

    as the user interface! Train Alexa by building new skills • Create your own echo with Alexa Voice Service on Raspberry Pi, Linux, Mac & Windows. • Access Alexa Voice Service from Android 34
  29. @margaretmz | #AndroidDev | #MachineLearning Pepper the Robot + Android

    Pepper’s Intelligence is powered by IBM Watson 1. Download Android plugin & SDK 2. Create an Android project 3. Enable robot project structure Now you are ready to program robots! https://android.aldebaran.com/doc/introduction.html 35
  30. @margaretmz | #AndroidDev | #MachineLearning Google AI Experiments Fun experiments

    with images, music, game & code https://aiexperiments.withgoogle.com/ 36
  31. @margaretmz | #AndroidDev | #MachineLearning Design considerations • Does your

    app really need the intelligence? • Choose a API/service ◦ ease of use, support, pricing • Get user permissions • Inform user about data privacy • Be mindful with user's data 38
  32. @margaretmz | #AndroidDev | #MachineLearning What is next? •Try out

    machine learning APIs • Try out TensorFlow tutorials and code labs • Check out the AI experiments • Study machine learning basics • Build an app with intelligence 39
  33. @margaretmz | #AndroidDev | #MachineLearning Appendix ML Sessions at Google

    I/O 2016 - • Getting Started with Machine Perception Using the Mobile Vision API • Machine Learning APIs by Example • Effective TensorFlow for Non-Experts • Android Meets TensorFlow: How to Accelerate Your App with AI Google AI Experiments • https://aiexperiments.withgoogle.com/ Udacity blog • The What, How, and Why of Artificial Intelligence, Machine Learning, and Self-Driving Cars 41
  34. @margaretmz | #AndroidDev | #MachineLearning Appendix - AI & ML

    learning resources My blog - Get Started with Machine Learning Udacity • Intro to Machine Learning • Deep Learning Nanodegree (TensorFlow, intermediate) • Deep Learning (TensorFlow, advanced) • AI Engineer Nanodegree • ML Engineer Nanodegree Stanford • Andrew Ng’s ML course on Coursera Google Developers • Machine Learning Recipes (short Youtube videos) 42