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
ML Kit Introduction (for Android)
Search
Elvis Lin
July 18, 2018
Programming
0
290
ML Kit Introduction (for Android)
Introduce the basic concept of ML Kit and how to use it in Android development
Elvis Lin
July 18, 2018
Tweet
Share
More Decks by Elvis Lin
See All by Elvis Lin
Protect Users' Privacy in iOS 14
elvismetaphor
0
46
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
48
Strategies of Facebook LightSpeed project
elvismetaphor
0
62
Background Execution And WorkManager
elvismetaphor
2
480
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
480
Dependency Injection for testability of iOS app
elvismetaphor
1
1.4k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
270
MotionLayout Brief Introduction
elvismetaphor
1
320
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
38
Other Decks in Programming
See All in Programming
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Better Code Design in PHP
afilina
PRO
0
130
Jakarta EE meets AI
ivargrimstad
0
100
Quine, Polyglot, 良いコード
qnighy
4
640
C++でシェーダを書く
fadis
6
4.1k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
880
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Featured
See All Featured
How GitHub (no longer) Works
holman
310
140k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Writing Fast Ruby
sferik
627
61k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Building an army of robots
kneath
302
43k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Transcript
ML Kit 使⽤用簡介 Elvis Lin @Android Taipei 2018-07-18
關於我 • Elvis Lin • Android 與 iOS 永遠的初學者 •
Twitter: @elvismetaphor • Blog: https://blog.elvismetaphor.me
不是業配 https://youtu.be/Z-dqGRSsaBs
⼤大綱 • 什什麼是(我理理解的)機器學習 • 移動裝置上實作機器學習應⽤用的限制 • TensorFlow Lite 與 ML
Kit • 範例例
機器學習的應⽤用
機器學習 • 從資料中歸納出有⽤用的規則 • 訓練模型 • 使⽤用模型 • Mobile Application
Engineer 參參與開發主要是在「使⽤用模型」 這個範圍
Data Result (Trained) Model
移動裝置上 實作機器學習應⽤用的限制 • 記憶體有限與儲存空間有限 • 計算能⼒力力不如⼤大型伺服器 • 電池容量量有限
移動裝置上 實作機器學習應⽤用的改良⽅方向 • 記憶體有限與儲存空間有限 —> 減少模型(Model)的體積 • 計算能⼒力力不如⼤大型伺服器 —> 降低演算法的複雜度
• 電池容量量有限 —> 降低演算法的複雜度
Google 推出的解決⽅方案 • TensorFlow Lite • ML Kit
https://www.tensorflow.org/mobile/tflite/
Neural Networks API Metal
ML Kit • Cloud Vision API / Mobile Vision API
• Tensorflow Lite • 整合 Firebase,託管「客製化的模型」
ML Kit Base APIs • Image labeling • Text recognition
(OCR) • Face detection • Barcode scanning • Landmark detection • others……
使⽤用 ML Kit
建立⼀一個 Firebase 專案
建立⼀一個 Android app 下載設定檔 設定好 Package Name 下載 google-service.json
<root>/build.gradle dependencies { classpath 'com.android.tools.build:gradle:3.1.3' classpath 'com.google.gms:google-services:4.0.2' }
<root>/app/build.gradle dependencies { // ... implementation 'com.google.firebase:firebase-ml-vision:16.0.0' }
掃描 barcode (local) FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(image); FirebaseVisionBarcodeDetectorOptions options =
new FirebaseVisionBarcodeDetectorOptions.Builder() .setBarcodeFormats( FirebaseVisionBarcode.FORMAT_QR_CODE, FirebaseVisionBarcode.FORMAT_AZTEC ) .build(); FirebaseVisionBarcodeDetector detector = FirebaseVision.getInstance() .getVisionBarcodeDetector(options); detector.detectInImage(image) .addOnSuccessListener( new OnSuccessListener<List<FirebaseVisionBarcode>>() { @Override public void onSuccess(List<FirebaseVisionBarcode> barcodes) {} }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) {} });
初始化 Detector FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(image); FirebaseVisionBarcodeDetectorOptions options = new
FirebaseVisionBarcodeDetectorOptions.Builder() .setBarcodeFormats( FirebaseVisionBarcode.FORMAT_QR_CODE, FirebaseVisionBarcode.FORMAT_AZTEC ) .build(); FirebaseVisionBarcodeDetector detector = FirebaseVision .getInstance() .getVisionBarcodeDetector(options);
取得結果 detector.detectInImage(image) .addOnSuccessListener( new OnSuccessListener<List<FirebaseVisionBarcode>>() { @Override public void onSuccess(List<FirebaseVisionBarcode>
barcodes) {} }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) {} });
⽀支援的 barcode 格式 • Code 128 (FORMAT_CODE_128) • Code 39
(FORMAT_CODE_39) • Code 93 (FORMAT_CODE_93) • Codabar (FORMAT_CODABAR) • EAN-13 (FORMAT_EAN_13) • EAN-8 (FORMAT_EAN_8) • ITF (FORMAT_ITF) • UPC-A (FORMAT_UPC_A) • UPC-E (FORMAT_UPC_E) •QR Code (FORMAT_QR_CODE) • PDF417 (FORMAT_PDF417) • Aztec (FORMAT_AZTEC) • Data Matrix (FORMAT_DATA_MATRIX)
辨識⽂文字 (local) FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(selectedImage); FirebaseVisionTextDetector detector = FirebaseVision.getInstance().getVisionTextDetector();
detector.detectInImage(image) .addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() { @Override public void onSuccess(FirebaseVisionText text) {} }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) {} });
辨識⽂文字 (cloud) FirebaseVisionCloudDetectorOptions options = new FirebaseVisionCloudDetectorOptions.Builder() .setModelType(FirebaseVisionCloudDetectorOptions.LATEST_MODEL) .setMaxResults(15) .build();
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(selectedImage); FirebaseVisionCloudDocumentTextDetector detector = FirebaseVision.getInstance() .getVisionCloudDocumentTextDetector(options); detector.detectInImage(image) .addOnSuccessListener(new OnSuccessListener<FirebaseVisionCloudText>() { @Override public void onSuccess(FirebaseVisionCloudText text) {} }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) {} });
補充資料 • ML Kit 簡介 (for Android) https://blog.elvismetaphor.me/ml-kit-fundamentals-for- android-6444e2db0fdb •
ML Kit 簡介 (for iOS) https://blog.elvismetaphor.me/ml-kit-fundamentals-for- ios-cb705044e69b
參參考資料 • https://youtu.be/Z-dqGRSsaBs • https://codelabs.developers.google.com/codelabs/mlkit- android/ • https://github.com/firebase/quickstart-android/tree/ master/mlkit
None