SlideShare a Scribd company logo
Who’s afraid of
Machine Learning?
Britt Barak
Britt Barak
Google Developer Expert - Android
Women Techmakers Israel
Britt Barak @brittBarak
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
In a machine...
Who's afraid of ML -V2- Hello MLKit
Strawberry
Not
Strawberry
Input
Red
Seeds
pattern
Top
leaves
0.64
0.75
0.4
Input
Red
Seeds
pattern
Top
leaves
0.64
0.75
0.4
Input
Red
Seeds
pattern
Top
leaves
0.64
0.75
0.4
Input
Red
Seeds
pattern
Top
leaves
0.64
0.75
0.4
Input
Red
Seeds
pattern
Top
leaves
0.5
0.8
0.3
0.64
0.75
0.4
Input
Red
Seeds
pattern
Top
leaves
0.5
0.8
0.3
0.5 * 0.64
+ 0.8 * 0.75
+ 0.3 * 0.4
0.64
0.75
0.4
Input
Red
Seeds
pattern
Top
leaves
0.5
0.8
0.3
0.5 * 0.64
+ 0.8 * 0.75
+ 0.3 * 0.4
___________
1.04
0.64
0.75
0.4
Red
Seeds
pattern
Top
leaves
0.5
0.8
0.3
0.5 * 0.64
+ 0.8 * 0.75
+ 0.3 * 0.4
___________
1.04
+ 0.7
___________
Input
0.64
0.75
0.4
Red
Seeds
pattern
Top
leaves
1.74
0.5
0.8
0.3
0.5 * 0.64
+ 0.8 * 0.75
+ 0.3 * 0.4
___________
1.04
+ 0.7
___________
1.74
Input
0.64
0.75
0.4
Red
Seeds
pattern
Top
leaves
1.74
Input
0.64
0.75
0.4
Red
Seeds
pattern
Top
leaves
1.02
1.74
0.97
Input
0.64
0.75
0.4
Red
Seeds
pattern
Top
leaves
1.02
1.74
0.97
Output
Strawberry
Not
Strawberry
Input
0.64
0.75
0.4
Red
Seeds
pattern
Top
leaves
1.02
1.74
0.97
0.87
0.13
Strawberry
Not
Strawberry
OutputInput
Who's afraid of ML -V2- Hello MLKit
0.7
0.03
0.01
Red
Seeds
pattern
Top
leaves
Strawberry
Not
Strawberry
OutputInput
0.7
0.03
0.01
Red
Seeds
pattern
Top
leaves
3.72
0.89
1.92
Strawberry
Not
Strawberry
OutputInput
0.7
0.03
0.01
Red
Seeds
pattern
Top
leaves
3.72
0.89
1.92
0.2
0.8
Strawberry
Not
Strawberry
OutputInput
Strawberry Not Not
StrawberryNot Not
Strawberry NotNot
0.5 * 0.64
+ 0.8 * 0.75
+ 0.3 * 0.4
___________
1.04
+ 0.7
___________
1.74
Training
0.64
0.75
0.4
Red
Seeds
pattern
Top
leaves
1.02
1.74
0.97
0.89
0.11
Strawberry
Not
Strawberry
OutputInput
Red
Seeds
pattern
Top
leaves
Strawberry
Not
Strawberry
OutputInput Hidden
Who's afraid of ML -V2- Hello MLKit
Data science
TensorFlow
- Open source
- Widely used
- Flexible for scale:
- 1 or more CPUs / GPUs
- desktop, server, mobile device
Strawberry
Strawberry
TensorFlow
Mobile
- Speech Recognition
- Image Recognition
- Object Localization
- Gesture Recognition
- Translation
- Text Classification
- Voice Synthesis
Lightweight Fast Cross platform
MobileNet Inception-V3 SmartReply
Models
Example implementation
Image
Classifier
classifier
.classify(bitmap)
label
1. Add assets
Who's afraid of ML -V2- Hello MLKit
labels.txt
strawberry
orange
lemon
fig
pineapple
banana
jackfruit
custard apple
pomegranate
hay
carbonara
chocolate sauce
dough
meat loaf
pizza
2. Add TensorFlow Lite
repositories {
maven {
url 'https://google.bintray.com/tensorflow'
}
}
dependencies {
// ...
implementation 'org.tensorflow:tensorflow-lite:+'
}
build.gradle
android {
aaptOptions {
noCompress "tflite"
noCompress "lite"
}
}
build.gradle
3. Create
ImageClassifier.java
Image
Classifier
ImageClassifier.java
tflite = new Interpreter();
ImageClassifier.java
model = loadModelFile();
tflite = new Interpreter(model);
MappedByteBuffer loadModelFile() {
AssetFileDescriptor descriptor= getAssets().openFd(MODEL_PATH);
}
MappedByteBuffer loadModelFile() {
AssetFileDescriptor descriptor= getAssets().openFd(MODEL_PATH);
FileInputStream inputStream = new
FileInputStream(descriptor.getFileDescriptor());
FileChannel channel = inputStream.getChannel();
}
MappedByteBuffer loadModelFile() {
AssetFileDescriptor descriptor= getAssets().openFd(MODEL_PATH);
FileInputStream inputStream = new
FileInputStream(descriptor.getFileDescriptor());
FileChannel channel = inputStream.getChannel();
long start = descriptor.getStartOffset();
long length = descriptor.getDeclaredLength();
return
channel.map(FileChannel.MapMode.READ_ONLY, start, length);
}
Image
Classifier
[strawberry, apple, ...]
labels.txt
ImageClassifier.java
model = loadModelFile();
tflite = new Interpreter(model);
labelList = loadLabelList();
labels.txt
strawberry
orange
lemon
fig
pineapple
banana
jackfruit
custard apple
pomegranate
hay
carbonara
chocolate sauce
dough
meat loaf
pizza
List<String> loadLabelList() throws IOException {
` InputStreamReader inputStream =
new InputStreamReader(getAssets().open(LABEL_PATH));
}
List<String> loadLabelList() throws IOException {
` InputStreamReader inputStream =
new InputStreamReader(getAssets().open(LABEL_PATH));
BufferedReader reader = new BufferedReader(inputStream);
}
List<String> loadLabelList() throws IOException {
` InputStreamReader inputStream =
new InputStreamReader(getAssets().open(LABEL_PATH));
BufferedReader reader = new BufferedReader(inputStream);
List<String> labelList = new ArrayList<String>();
String line;
while ((line = reader.readLine()) != null) {
labelList.add(line);
}
}
List<String> loadLabelList() throws IOException {
` InputStreamReader inputStream =
new InputStreamReader(getAssets().open(LABEL_PATH));
BufferedReader reader = new BufferedReader(inputStream);
List<String> labelList = new ArrayList<String>();
String line;
while ((line = reader.readLine()) != null) {
labelList.add(line);
}
reader.close();
return labelList;
}
Image
Classifier
[ [0..6] , [ 0.1 ] , ...]
[strawberry, apple, ...]
probArray
labels.txt
probArray =
{
[0.7],
[0.3],
[0],
[0],
}
labelList =
{
strawberry,
apple,
pineapple,
banana
}
0.3
ImageClassifier.java
model = loadModelFile();
tflite = new Interpreter(model);
labelList = loadLabelList();
probArray = new float[1][labelList.size()];
Image
Classifier
[......] [ [0..6] , [ 0.1 ] , ...]
[strawberry, apple, ...]
ByteBuffer probArray
labels.txt
ImageClassifier.java
model = loadModelFile();
tflite = new Interpreter(model);
labelList = loadLabelList();
probArray = new float[1][labelList.size()];
imgData =
ByteBuffer.allocateDirect(
DIM_IMG_SIZE_X * DIM_IMG_SIZE_Y * DIM_PIXEL_SIZE);
imgData.order(ByteOrder.nativeOrder());
4. Run the model / classify
classifier
.classify(bitmap)
Image
Classifier
[......] [ [0..6] , [ 0.1 ] , ...]
[strawberry, apple, ...]
ByteBuffer probArray
labels.txt
ImageClassifier.java
String classify(Bitmap bitmap) {
convertBitmapToByteBuffer(bitmap);
}
void convertBitmapToByteBuffer(Bitmap bitmap) {
//...
bitmap.getPixels(intValues, 0, bitmap.getWidth(),
0, 0,bitmap.getWidth(), bitmap.getHeight());
}
}
void convertBitmapToByteBuffer(Bitmap bitmap) {
//...
bitmap.getPixels(intValues, 0, bitmap.getWidth(),
0, 0,bitmap.getWidth(), bitmap.getHeight());
int pixel = 0;
for (int i = 0; i < DIM_IMG_SIZE_X; ++i) {
for (int j = 0; j < DIM_IMG_SIZE_Y; ++j) {
final int val = intValues[pixel++];
imgData.put((byte) ((val >> 16) & 0xFF));
imgData.put((byte) ((val >> 8) & 0xFF));
imgData.put((byte) (val & 0xFF));
}
}
}
ImageClassifier.java
String classify(Bitmap bitmap) {
convertBitmapToByteBuffer(bitmap);
tflite.run(imgData, probArray);
ImageClassifier.java
String classify(Bitmap bitmap) {
convertBitmapToByteBuffer(bitmap);
tflite.run(imgData, probArray);
String textToShow = getTopLabels();
return textToShow;
}
private String getTopKLabels() {
for (int i = 0; i < labelList.size(); ++i) {
sortedLabels.add(
new AbstractMap.SimpleEntry<>(labelList.get(i), (labelProbArray[0][i] &
0xff) / 255.0f));
if (sortedLabels.size() > RESULTS_TO_SHOW) {
sortedLabels.poll();
}
}
String textToShow = "";
final int size = sortedLabels.size();
for (int i = 0; i < size; ++i) {
Map.Entry<String, Float> label = sortedLabels.poll();
textToShow = String.format("n%s: %4.2f", label.getKey(), label.getValue())
+ textToShow;
}
return textToShow;
}
Strawberry - 0.87
Apple - 0.13
Tomato - 0.01
Machine
Learning
is a
new world
Links
- Tensorflow
- https://www.tensorflow.org/
- Tensorflow lite
- https://www.tensorflow.org/mobile/tflite/
- Codes labs
- codelabs.developers.google.com/codelabs/tensorflow-for-poets-2-tflite/
- Google’s Machine Learning Crash Course
- developers.google.com/machine-learning/crash-course/
- [Dr. Joe Dispenza]
Thank you!
Keep in touch!
Britt Barak
@brittBarak
BETA
Key capabilities
● Production-ready for common use cases
● On-device or in the cloud
● Deploy custom models
Who's afraid of ML -V2- Hello MLKit
How to implement?
1. Add the sdk
Quickly include the SDK using Gradle or CocoaPods.
2. Prepare input data
For example, if you're using a vision feature, capture an image from the camera
and generate the necessary metadata such as image rotation, or prompt the user
to select a photo from their gallery.
3. Apply the ML model to your data
By applying the ML model to your data, you generate insights such as the
emotional state of detected faces or the objects and concepts that were
recognized in the image, depending on the feature you used. Use these insights to
power features in your app like photo embellishment, automatic metadata
generation, or whatever else you can imagine.
Ready to use models
Ready to use models: 1. Text Recognition
Ready to use models: 2. Face Detection
Ready to use models: 3. Barcode Scanning
Corners
(87,87) (612,87) (612,612) (87,612)
Raw value
WIFI:S:SB1Guest;P:12345;T:WEP;;
WiFi information
Ready to use models: 4. Image Labeling
Who's afraid of ML -V2- Hello MLKit

More Related Content

PPTX
Php forum2015 tomas_final
PPTX
Java 8 Examples
PDF
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
PPTX
Devoxx 2012 hibernate envers
PPTX
Jsoup Tutorial for Beginners - Javatpoint
PDF
Connecting your Python App to OpenERP through OOOP
PPTX
Jsoup tutorial
PPTX
Mongo db basic installation
Php forum2015 tomas_final
Java 8 Examples
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Devoxx 2012 hibernate envers
Jsoup Tutorial for Beginners - Javatpoint
Connecting your Python App to OpenERP through OOOP
Jsoup tutorial
Mongo db basic installation

Similar to Who's afraid of ML -V2- Hello MLKit (20)

PDF
The Ring programming language version 1.5.4 book - Part 10 of 185
PDF
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
PDF
Pebank java handsout
PDF
The Ring programming language version 1.5.3 book - Part 10 of 184
PPT
Groovy Introduction - JAX Germany - 2008
PDF
Python Machine Learning Cookbook Early Release 1st Ed Chris Albon
PDF
What Lies Beneath
PPT
Java Generics for Dummies
PDF
Unafraid of Change: Optimizing ETL, ML, and AI in Fast-Paced Environments wit...
PDF
ES3-2020-06 Test Driven Development (TDD)
PDF
Develop Python Applications with MySQL Connector/Python
ODP
Scala introduction
PDF
Lazy Java
PDF
Lazy Java
PDF
Lazy java
PDF
Mario Fusco - Lazy Java - Codemotion Milan 2018
PPT
SQL -PHP Tutorial
PPT
Micro-ORM Introduction - Don't overcomplicate
PDF
Python Peculiarities
KEY
Workshop quality assurance for php projects tek12
The Ring programming language version 1.5.4 book - Part 10 of 185
Evaluating Your Learning to Rank Model: Dos and Don’ts in Offline/Online Eval...
Pebank java handsout
The Ring programming language version 1.5.3 book - Part 10 of 184
Groovy Introduction - JAX Germany - 2008
Python Machine Learning Cookbook Early Release 1st Ed Chris Albon
What Lies Beneath
Java Generics for Dummies
Unafraid of Change: Optimizing ETL, ML, and AI in Fast-Paced Environments wit...
ES3-2020-06 Test Driven Development (TDD)
Develop Python Applications with MySQL Connector/Python
Scala introduction
Lazy Java
Lazy Java
Lazy java
Mario Fusco - Lazy Java - Codemotion Milan 2018
SQL -PHP Tutorial
Micro-ORM Introduction - Don't overcomplicate
Python Peculiarities
Workshop quality assurance for php projects tek12
Ad

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Programs and apps: productivity, graphics, security and other tools
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Cloud computing and distributed systems.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
Chapter 3 Spatial Domain Image Processing.pdf
sap open course for s4hana steps from ECC to s4
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Programs and apps: productivity, graphics, security and other tools
“AI and Expert System Decision Support & Business Intelligence Systems”
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.
MIND Revenue Release Quarter 2 2025 Press Release
Cloud computing and distributed systems.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Ad

Who's afraid of ML -V2- Hello MLKit