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
非機能品質を作り込むための実践アーキテクチャ
knih
3
700
Wantedly での Datadog 活用事例
bgpat
1
410
ハイテク休憩
sat
PRO
2
120
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
320
WACATE2024冬セッション資料(ユーザビリティ)
scarletplover
0
190
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
260
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
510
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
150
20241220_S3 tablesの使い方を検証してみた
handy
3
220
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
160
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
160
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
51
7.3k
Faster Mobile Websites
deanohume
305
30k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Navigating Team Friction
lara
183
15k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Practical Orchestrator
shlominoach
186
10k
A better future with KSS
kneath
238
17k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Building Your Own Lightsaber
phodgson
103
6.1k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
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