Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Who's Afraid Of Machine Learning? & first steps...
Search
Britt Barak
April 23, 2018
Technology
5
870
Who's Afraid Of Machine Learning? & first steps with TensorFlow
Chicago Roboto & Android Makers 2018
Britt Barak
April 23, 2018
Tweet
Share
More Decks by Britt Barak
See All by Britt Barak
[Vonage] Introducing Conversations
brittbarak
1
120
Kids, Play Nice! Kotlin-Java Interop In Mind
brittbarak
2
380
Sharing is Caring- Getting Started with Kotlin Multiplatform
brittbarak
2
2k
Between JOMO and FOMO: You are reshaping communication.
brittbarak
2
1.2k
Build Apps For The Ones You Love
brittbarak
1
110
What an ML-ful World! MLKit for Android dev.
brittbarak
0
130
Make your app dance with MotionLayout
brittbarak
8
1.3k
Who's afraid of ML? V2 : First steps with MlKit
brittbarak
1
450
Oh, the places you'll go! Cracking Navigation on Android
brittbarak
0
460
Other Decks in Technology
See All in Technology
あなたの知らないクラフトビールの世界
miura55
0
130
【NGK2025S】動物園(PINTO_model_zoo)に遊びに行こう
kazuhitotakahashi
0
240
機械学習を「社会実装」するということ 2025年版 / Social Implementation of Machine Learning 2025 Version
moepy_stats
5
1.2k
ゼロからわかる!!AWSの構成図を書いてみようワークショップ 問題&解答解説 #デッカイギ #羽田デッカイギおつ
_mossann_t
0
1.5k
comilioとCloudflare、そして未来へと向けて
oliver_diary
6
450
2025年の挑戦 コーポレートエンジニアの技術広報/techpr5
nishiuma
0
140
Building Scalable Backend Services with Firebase
wisdommatt
0
110
FODにおけるホーム画面編成のレコメンド
watarukudo
PRO
2
280
Oracle Base Database Service:サービス概要のご紹介
oracle4engineer
PRO
1
16k
Azureの開発で辛いところ
re3turn
0
240
WantedlyでのKotlin Multiplatformの導入と課題 / Kotlin Multiplatform Implementation and Challenges at Wantedly
kubode
0
250
30分でわかる「リスクから学ぶKubernetesコンテナセキュリティ」/30min-k8s-container-sec
mochizuki875
3
450
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
98
18k
It's Worth the Effort
3n
183
28k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
The Language of Interfaces
destraynor
155
24k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
960
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
Transcript
Who’s afraid of Machine Learning? Britt Barak
Britt Barak Google Developer Expert - Android Women Techmakers Israel
Britt Barak @brittBarak
None
None
None
None
None
None
None
None
In a machine...
None
Strawberry Not Strawberry
Input Red Seeds pattern Top leaves 0.64 0.75 0.4
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 0.5 0.8 0.3 Red Seeds pattern
Top leaves
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 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.7
0.64 0.75 0.4 1.74 0.5 * 0.64 + 0.8 *
0.75 + 0.3 * 0.4 ___________ 1.04 + 0.7 ___________ 1.74 Input Red Seeds pattern Top leaves 0.5 0.8 0.3
0.64 0.75 0.4 1.02 1.74 Input Red Seeds pattern Top
leaves 0.97
0.64 0.75 0.4 Input Red Seeds pattern Top leaves 1.02
1.74 0.97
0.64 0.75 0.4 Output Strawberry Not Strawberry Input Red Seeds
pattern Top leaves 1.02 1.74 0.97 0.87 0.13
0.64 0.75 0.4 0.87 0.13 Strawberry Not Strawberry Output Input
Red Seeds pattern Top leaves 1.02 1.74 0.97
None
0.7 0.03 0.01 3.72 0.89 1.92 Strawberry Not Strawberry Output
Input Red Seeds pattern Top leaves 0.2 0.8
0.7 0.03 0.01 3.72 0.89 1.92 Strawberry Not Strawberry Output
Input Red Seeds pattern Top leaves 0.2 0.8
0.7 0.03 0.01 3.72 0.89 1.92 0.2 0.8 Strawberry Not
Strawberry Output Input Red Seeds pattern Top leaves
0.5 * 0.64 + 0.8 * 0.75 + 0.3 *
0.4 ___________ 1.04 + 0.7 ___________ 1.74 Strawberry Not Not Strawberry Not Not Strawberry Not Not
Training TRAINING
0.64 0.75 0.4 1.02 1.74 0.97 0.89 0.11 Strawberry Not
Strawberry Output Input Red Seeds pattern Top leaves
Strawberry Not Strawberry Output Input Hidden Red Seeds pattern Top
leaves
None
Data science
We get a trained model !
TensorFlow - Open source - Widely used - Flexible for
scale: - 1 or more CPUs / GPUs - desktop, server, mobile device
Strawberry
Strawberry
Strawberry • Bandwidth • Performance • Latency • Network •
Security • Privacy • …
TensorFlow Mobile - Speech Recognition - Image Recognition - Object
Localization - Gesture Recognition - Translation - Text Classification - Voice Synthesis
Lightweight Fast Cross platform
MobileNet Inception-V3 SmartReply Models
None
Image Classifier classifier .classify(bitmap) label
1. Add Assets
None
labels.txt strawberry orange lemon fig pineapple banana jackfruit custard apple
pomegranate hay carbonara chocolate sauce dough meat loaf
2. Add TensorFlow Lite
repositories { maven { url 'https://google.bintray.com/tensorflow' } } dependencies
{ // ... implementation 'org.tensorflow:tensorflow-lite:+' } build.gradle
android { aaptOptions { noCompress "tflite" } } build.gradle
3. Create ImageClassifier.java
Image Classifier
ImageClassifier.java model = loadModelFile(); 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
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 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 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(imgData, 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)); } } }
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(imgData, bitmap); tflite.run(imgData,
probArray); }
ImageClassifier.java String classify(Bitmap bitmap) { convertBitmapToByteBuffer(imgData, bitmap); tflite.run(imgData,
probArray); String textToShow = getTopLabels(); 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