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
360
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
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
180
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
160
多様なメトリックとシステムの健全性維持
masaaki_k
0
110
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
270
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
270
watsonx.ai Dojo #5 ファインチューニングとInstructLAB
oniak3ibm
PRO
0
190
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
380
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
Working as a Server-side Engineer at LY Corporation
lycorp_recruit_jp
0
350
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
1.1k
5分でわかるDuckDB
chanyou0311
10
3.3k
Featured
See All Featured
Optimizing for Happiness
mojombo
376
70k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Rails Girls Zürich Keynote
gr2m
94
13k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Automating Front-end Workflow
addyosmani
1366
200k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
1
100
Embracing the Ebb and Flow
colly
84
4.5k
GitHub's CSS Performance
jonrohan
1031
460k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Thoughts on Productivity
jonyablonski
68
4.4k
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