SlideShare a Scribd company logo
Creating Smarter
Applications
Maoz Tamir
<droidcon Tel Aviv>
Seeing the Whole Picture
<droidcon Tel Aviv>
In the beginning .. Classic image
processing
 If … if …
Specific solution for a specific problem
 Rule Engine– By clusters.
More of the same
 Classic ML – Define features
 Deep Neural Networks
Generic solution for a specific problem
<droidcon Tel Aviv>
Add ML to your App
 Adding
personalization into
your App.
 Gather information
and providing
immediate feedback.
 Provides an efficient
searching experience.
 Detect And Control
<droidcon Tel Aviv>
Cloud ML
 Microsoft Cognitive Services
 Amazon Machine Learning Services
 IBM Watson
 Firebase ML Kit
 Alibaba Cloud services
<droidcon Tel Aviv>
Firebase ML KIT
 Face Detection
 Barcode Scanning
 Landscape Detection
 Image Labeling
 Text Recognition
 Custom TensorFlow Model
<droidcon Tel Aviv>
Firebase ML KIT
 Almost any application uses it .
 Build in ML Models.
 Both Cloud and on Device.
 Scalable.
<droidcon Tel Aviv>
Live Demo
<droidcon Tel Aviv>
Coding time – Vision label detection
FirebaseVisionLabelDetector detector = FirebaseVision.getInstance)(
. getVisionLabelDetector )(;
//Or, to Use the cloud
//FirebaseVisionCloudLabelDetector detector = FirebaseVision.getInstance)(
//. getVisionCloudLabelDetector)options( ;
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap)bitmap( ;
Task<List<FirebaseVisionLabel>> result=
detector.detectInImage)image(
. addOnSuccessListener(
new OnSuccessListener<List<FirebaseVisionLabel <<)({
@Override
public void onSuccess)List<FirebaseVisionLabel> labels({
// Task completed successfully
}
})
. addOnFailureListener(
new OnFailureListener )({
@Override
public void onFailure)@NonNull Exception e){
// Task failed with an exception
}
});
Creating something
different
oRecognize Something specific
oRun Offline
oResponse time
oCost
<droidcon Tel Aviv>
ML Frameworks
 TensorFlow
 Scikit-learn
 Caffe
 Torch
 Spark
 Mahout
 CNTK 2 (Microsoft Cognitive Toolkit)
<droidcon Tel Aviv>
Retrain an Image Classifier for New
Categories
COLLECT AND
PREPARE DATA
RETRAIN
OPTIMIZE TO
MOBILE
RUN ON DEVICE
Fatkun
retraining Inception V3 for custom
image classification
Available models
<droidcon Tel Aviv>
Retrain
 Set your input images
[any_path]/my_own_classifier/data/dalek
[any_path]/my_own_classifier/data/cyberman
[any_path]/my_own_classifier/data/doctor
 Run the retrain
python -m scripts.retrain 
--bottleneck_dir=tf_files/bottlenecks 
--how_many_training_steps=500 
--model_dir=tf_files/models/ 
--summaries_dir=tf_files/training_summaries/"${ARCHITECTURE}" 
--output_graph=tf_files/retrained_graph.pb 
--output_labels=tf_files/retrained_labels.txt 
--image_dir=tf_files/data
<droidcon Tel Aviv>
Tensorboard
<droidcon Tel Aviv>
Optimize to Mobile – TF-Mobile or TF Lite
 TF lite
 Using TensorFlow Lite Converter
 TF for mobile
 Optimize for inference
 python -m tensorflow.python.tools.optimize_for_inference
 Remove or not needed nodes and handling unsupported operations
 Quantize the network weights
 python -m scripts.quantize_graph
 reduce neural network weights the graph size from 32bit to 8bit .
<droidcon Tel Aviv>
Quantize the network weights
<droidcon Tel Aviv>
Back to Android
private static final String MODEL_FILE = "file:///android_asset/graph.pb";
private static final String LABEL_FILE = "file:///android_asset/labels.txt";
// load the model into a TensorFlowInferenceInterface.
c.inferenceInterface = new TensorFlowInferenceInterface(
assetManager, MODEL_FILE );
// This model can be retrained with different numbers of output classes output array must be in
the same size
// Get the tensorflow node
final Operation operation = c.inferenceInterface.graphOperation(outputName);
// Inspect its shape
final int numClasses = (int) operation.output(0).shape().size(1);
// Build the output array with the correct size.
c.outputs = new float[numClasses];
<droidcon Tel Aviv>
Back to Android
// Copy the input data into TensorFlow.
inferenceInterface.feed(
inputName, // The name of the node to feed.
floatValues, // The array to feed
1, inputSize, inputSize, 3 ); // The shape of the array
inferenceInterface.run(
outputNames, // Names of all the nodes to calculate.
logStats); // Bool, enable stat logging.
inferenceInterface.fetch(
outputName, // Fetch this output.
outputs); // Into the prepared array.
<droidcon Tel Aviv>
Live Demo
<droidcon Tel Aviv>
Lesson learned
 Handle your data with care.
 Use the framework that fits you (TensorFlow , Torch, Caffe , Spark ….)
 Don’t be afraid to play with parameters.
 Learn to use Tensorboard.
 Use Linux or Linux based OS.
 Keep up with the research.
<droidcon Tel Aviv>
Questions ?
<droidcon Tel Aviv>
Thanks
Maoz Tamir
maoz.tamir@gmail.com
053-3134223
Mobilefactory.co.il
<droidcon Tel Aviv>

More Related Content

PDF
Who needs MVVM? Architecture components & MVP - Timor Surkis, Colu
PDF
Introduction to React Native - Lev Vidrak, Wix
PDF
Constraint-ly motion - making your app dance - John Hoford, Google
ODP
Eclipse based products
PDF
EclipseCon 08 - Agile RCP
PDF
How to deploy machine learning models in the Cloud
PDF
SPRING BOOT DANS UN CONTAINER OUTILS ET PRATIQUES
PDF
A Graphical Way of Thinking About React Designs
Who needs MVVM? Architecture components & MVP - Timor Surkis, Colu
Introduction to React Native - Lev Vidrak, Wix
Constraint-ly motion - making your app dance - John Hoford, Google
Eclipse based products
EclipseCon 08 - Agile RCP
How to deploy machine learning models in the Cloud
SPRING BOOT DANS UN CONTAINER OUTILS ET PRATIQUES
A Graphical Way of Thinking About React Designs

What's hot (20)

PDF
Cloud-native Patterns (July 4th, 2019)
PDF
server side Swift
PDF
Boost your API with GraphQL
PDF
Smokey and the Multi-Armed Bandit Featuring BERT Reynolds Updated
PDF
ServiceWorkerとES6 Modules時代のTypescript開発考察
PDF
Facilitez votre transition DevOps grâce à l'automatisation de votre infras...
PDF
TechEvent Graal(VM) Performance Interoperability
PPTX
ReactWeek 2019 Conditional Modules & Dynamic Bundling: A Netflix Original
ODP
Boost your App with Gatling
PPTX
From training to explainability via git ops
PDF
"Production Driven Development", Serhii Kalinets
PDF
GraphQL in Symfony
PPTX
Highload JavaScript Framework without Inheritance
PPTX
Android Test Pyramid - Ágiles 2013
PDF
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
PDF
"Performance measurements with Java Microbenchmark Harness (JMH)" at Eclipse ...
PDF
Agile Development with OSGi
PPT
Adobe Session on Flash Online Conference #12
PDF
50 common web developer interview questions [2020 updated] [www.full stack....
PDF
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...
Cloud-native Patterns (July 4th, 2019)
server side Swift
Boost your API with GraphQL
Smokey and the Multi-Armed Bandit Featuring BERT Reynolds Updated
ServiceWorkerとES6 Modules時代のTypescript開発考察
Facilitez votre transition DevOps grâce à l'automatisation de votre infras...
TechEvent Graal(VM) Performance Interoperability
ReactWeek 2019 Conditional Modules & Dynamic Bundling: A Netflix Original
Boost your App with Gatling
From training to explainability via git ops
"Production Driven Development", Serhii Kalinets
GraphQL in Symfony
Highload JavaScript Framework without Inheritance
Android Test Pyramid - Ágiles 2013
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
"Performance measurements with Java Microbenchmark Harness (JMH)" at Eclipse ...
Agile Development with OSGi
Adobe Session on Flash Online Conference #12
50 common web developer interview questions [2020 updated] [www.full stack....
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...
Ad

Similar to Educating your app – adding ML edge to your apps - Maoz Tamir (20)

PPTX
Build 2019 Recap
PDF
TensorFlow for Mobile Platforms. UA Mobile 2017
PPT
PDF
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
PDF
Android on IA devices and Intel Tools
PPTX
Mobile Fest 2018. Enrique López Mañas. TensorFlow for Mobile Poets
PDF
Supercharge Your AI Development with Local LLMs
PDF
Dot Net Fundamentals
PPTX
Shape12 6
PDF
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
PDF
Extension and Evolution
PDF
Deep learning and streaming in Apache Spark 2.2 by Matei Zaharia
PDF
Smart Face Recognition System Analysis
PDF
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
PDF
Samantha Wang [InfluxData] | Data Collection Overview | InfluxDays 2022
PDF
Oopp Lab Work
PPTX
Architecture As Language
PPTX
DotNet Conf Madrid 2019 - Whats New in ML.NET
PDF
Getting Native with NDK
PPTX
Training course lect1
Build 2019 Recap
TensorFlow for Mobile Platforms. UA Mobile 2017
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
Android on IA devices and Intel Tools
Mobile Fest 2018. Enrique López Mañas. TensorFlow for Mobile Poets
Supercharge Your AI Development with Local LLMs
Dot Net Fundamentals
Shape12 6
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
Extension and Evolution
Deep learning and streaming in Apache Spark 2.2 by Matei Zaharia
Smart Face Recognition System Analysis
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
Samantha Wang [InfluxData] | Data Collection Overview | InfluxDays 2022
Oopp Lab Work
Architecture As Language
DotNet Conf Madrid 2019 - Whats New in ML.NET
Getting Native with NDK
Training course lect1
Ad

More from DroidConTLV (20)

PDF
Mobile Development in the Information Age - Yossi Elkrief, Nike
PDF
Doing work in the background - Darryn Campbell, Zebra Technologies
PDF
No more video loss - Alex Rivkin, Motorola Solutions
PDF
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
PDF
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
PDF
MVVM In real life - Lea Cohen Tannoudji, Lightricks
PDF
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
PDF
Building Apps with Flutter - Hillel Coren, Invoice Ninja
PDF
New Android Project: The Most Important Decisions - Vasiliy Zukanov
PDF
Designing a Design System - Shai Mishali, Gett
PDF
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
PDF
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
PDF
Flutter State Management - Moti Bartov, Tikal
PDF
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
PDF
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
PDF
DroidconTLV 2019
PDF
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
PDF
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
PDF
Reverse reverse engineering engineering 101 - Royi Benyossef, Samsung NEXT
PDF
The Redux State of the Art - Shem Magnezi+Limor Mekaiten, WeWork
Mobile Development in the Information Age - Yossi Elkrief, Nike
Doing work in the background - Darryn Campbell, Zebra Technologies
No more video loss - Alex Rivkin, Motorola Solutions
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
MVVM In real life - Lea Cohen Tannoudji, Lightricks
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Building Apps with Flutter - Hillel Coren, Invoice Ninja
New Android Project: The Most Important Decisions - Vasiliy Zukanov
Designing a Design System - Shai Mishali, Gett
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Flutter State Management - Moti Bartov, Tikal
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
DroidconTLV 2019
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Reverse reverse engineering engineering 101 - Royi Benyossef, Samsung NEXT
The Redux State of the Art - Shem Magnezi+Limor Mekaiten, WeWork

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
Teaching material agriculture food technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
KodekX | Application Modernization Development
Electronic commerce courselecture one. Pdf
Spectral efficient network and resource selection model in 5G networks
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Network Security Unit 5.pdf for BCA BBA.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools
Chapter 3 Spatial Domain Image Processing.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectroscopy.pptx food analysis technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Teaching material agriculture food technology
Advanced methodologies resolving dimensionality complications for autism neur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KodekX | Application Modernization Development

Educating your app – adding ML edge to your apps - Maoz Tamir

  • 2. Seeing the Whole Picture <droidcon Tel Aviv>
  • 3. In the beginning .. Classic image processing  If … if … Specific solution for a specific problem  Rule Engine– By clusters. More of the same  Classic ML – Define features  Deep Neural Networks Generic solution for a specific problem <droidcon Tel Aviv>
  • 4. Add ML to your App  Adding personalization into your App.  Gather information and providing immediate feedback.  Provides an efficient searching experience.  Detect And Control <droidcon Tel Aviv>
  • 5. Cloud ML  Microsoft Cognitive Services  Amazon Machine Learning Services  IBM Watson  Firebase ML Kit  Alibaba Cloud services <droidcon Tel Aviv>
  • 6. Firebase ML KIT  Face Detection  Barcode Scanning  Landscape Detection  Image Labeling  Text Recognition  Custom TensorFlow Model <droidcon Tel Aviv>
  • 7. Firebase ML KIT  Almost any application uses it .  Build in ML Models.  Both Cloud and on Device.  Scalable. <droidcon Tel Aviv>
  • 9. Coding time – Vision label detection FirebaseVisionLabelDetector detector = FirebaseVision.getInstance)( . getVisionLabelDetector )(; //Or, to Use the cloud //FirebaseVisionCloudLabelDetector detector = FirebaseVision.getInstance)( //. getVisionCloudLabelDetector)options( ; FirebaseVisionImage image = FirebaseVisionImage.fromBitmap)bitmap( ; Task<List<FirebaseVisionLabel>> result= detector.detectInImage)image( . addOnSuccessListener( new OnSuccessListener<List<FirebaseVisionLabel <<)({ @Override public void onSuccess)List<FirebaseVisionLabel> labels({ // Task completed successfully } }) . addOnFailureListener( new OnFailureListener )({ @Override public void onFailure)@NonNull Exception e){ // Task failed with an exception } });
  • 10. Creating something different oRecognize Something specific oRun Offline oResponse time oCost <droidcon Tel Aviv>
  • 11. ML Frameworks  TensorFlow  Scikit-learn  Caffe  Torch  Spark  Mahout  CNTK 2 (Microsoft Cognitive Toolkit) <droidcon Tel Aviv>
  • 12. Retrain an Image Classifier for New Categories COLLECT AND PREPARE DATA RETRAIN OPTIMIZE TO MOBILE RUN ON DEVICE Fatkun
  • 13. retraining Inception V3 for custom image classification Available models <droidcon Tel Aviv>
  • 14. Retrain  Set your input images [any_path]/my_own_classifier/data/dalek [any_path]/my_own_classifier/data/cyberman [any_path]/my_own_classifier/data/doctor  Run the retrain python -m scripts.retrain --bottleneck_dir=tf_files/bottlenecks --how_many_training_steps=500 --model_dir=tf_files/models/ --summaries_dir=tf_files/training_summaries/"${ARCHITECTURE}" --output_graph=tf_files/retrained_graph.pb --output_labels=tf_files/retrained_labels.txt --image_dir=tf_files/data <droidcon Tel Aviv>
  • 16. Optimize to Mobile – TF-Mobile or TF Lite  TF lite  Using TensorFlow Lite Converter  TF for mobile  Optimize for inference  python -m tensorflow.python.tools.optimize_for_inference  Remove or not needed nodes and handling unsupported operations  Quantize the network weights  python -m scripts.quantize_graph  reduce neural network weights the graph size from 32bit to 8bit . <droidcon Tel Aviv>
  • 17. Quantize the network weights <droidcon Tel Aviv>
  • 18. Back to Android private static final String MODEL_FILE = "file:///android_asset/graph.pb"; private static final String LABEL_FILE = "file:///android_asset/labels.txt"; // load the model into a TensorFlowInferenceInterface. c.inferenceInterface = new TensorFlowInferenceInterface( assetManager, MODEL_FILE ); // This model can be retrained with different numbers of output classes output array must be in the same size // Get the tensorflow node final Operation operation = c.inferenceInterface.graphOperation(outputName); // Inspect its shape final int numClasses = (int) operation.output(0).shape().size(1); // Build the output array with the correct size. c.outputs = new float[numClasses]; <droidcon Tel Aviv>
  • 19. Back to Android // Copy the input data into TensorFlow. inferenceInterface.feed( inputName, // The name of the node to feed. floatValues, // The array to feed 1, inputSize, inputSize, 3 ); // The shape of the array inferenceInterface.run( outputNames, // Names of all the nodes to calculate. logStats); // Bool, enable stat logging. inferenceInterface.fetch( outputName, // Fetch this output. outputs); // Into the prepared array. <droidcon Tel Aviv>
  • 21. Lesson learned  Handle your data with care.  Use the framework that fits you (TensorFlow , Torch, Caffe , Spark ….)  Don’t be afraid to play with parameters.  Learn to use Tensorboard.  Use Linux or Linux based OS.  Keep up with the research. <droidcon Tel Aviv>