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 iOS)
Search
Elvis Lin
July 19, 2018
Programming
0
140
ML Kit Introduction (for iOS)
Introduce the basic concept of ML Kit and how to use it in iOS development
Elvis Lin
July 19, 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
63
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
Zoneless Testing
rainerhahnekamp
0
120
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
命名をリントする
chiroruxx
1
410
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
130
Symfony Mapper Component
soyuka
2
730
return文におけるstd::moveについて
onihusube
1
1.1k
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
360
php-conference-japan-2024
tasuku43
0
270
Beyond ORM
77web
5
660
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Faster Mobile Websites
deanohume
305
30k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Bash Introduction
62gerente
608
210k
Building Your Own Lightsaber
phodgson
103
6.1k
Six Lessons from altMBA
skipperchong
27
3.5k
The Cost Of JavaScript in 2023
addyosmani
45
7k
It's Worth the Effort
3n
183
28k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Transcript
ML Kit 使⽤用簡介 (iOS) Elvis Lin @Cocoahead Taipei 2018-07-19
關於我 • Elvis Lin • iOS 與 Android 永遠的初學者 •
Twitter: @elvismetaphor • Blog: https://blog.elvismetaphor.me
⼤大綱 • 什什麼是(我理理解的)機器學習 • 移動裝置上實作機器學習應⽤用的限制 • TensorFlow Lite 與 ML
Kit • 範例例
機器學習的應⽤用
機器學習 • 從資料中歸納出有⽤用的規則 • 訓練模型 • 使⽤用模型 • Mobile Application
Engineer 參參 與開發主要是在「使⽤用模型」 這個範圍
Data Result (Trained) Model
移動裝置上 實作機器學習應⽤用的限制 • 記憶體有限與儲存空間有限 • 計算能⼒力力不如⼤大型伺服器 • 電池容量量有限
移動裝置上 實作機器學習應⽤用的改良⽅方向 • 記憶體有限與儲存空間有限 —> 減少模型(Model)的體積 • 計算能⼒力力不如⼤大型伺服器 —> 降低演算法的複雜度
• 電池容量量有限 —> 降低演算法的複雜度
Google 推出的解決⽅方案 • TensorFlow Lite • ML Kit
Tensorflow Lite https://youtu.be/ByJnpbDd-zc
https://www.tensorflow.org/mobile/tflite/
轉換 Tensorflow 檔案的⼯工具 • Tensorflow converter • 轉成 Tensorflow Lite
格式 • Tensorflow-CoreML converter • 轉成 CoreML 格式 • https://github.com/tf-coreml/tf-coreml
ML Kit https://youtu.be/Z-dqGRSsaBs
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……
託管客製化的模型 ⽬目前只⽀支援 Tensorflow Lite 格式
使⽤用 ML Kit
建立⼀一個 Firebase 專案
建立⼀一個 iOS app 然後下載設定檔 設定好 Bundle ID 下載 GoogleService-info.plist
新增 plist 檔案到專案 • 將 GoogleService-Info.plist 放到 <root>/<application_folder>/ 下
安裝 Firebase 函式庫 • 修改 Podfile,新增以下的內容 • cd <root> pod
install • 打改 <project_name>.xcworkspace pod 'Firebase/Core' pod 'Firebase/MLVision' pod 'Firebase/MLVisionTextModel' pod 'Firebase/MLVisionFaceModel' pod 'Firebase/MLVisionBarcodeModel' pod 'Firebase/MLVision' pod 'Firebase/MLVisionLabelModel'
掃描 Barcode (Local) let barcodeDetector: VisionBarcodeDetector = Vision.vision().barcodeDetector(options: options)
let visionImage = VisionImage(image: pickedImage) barcodeDetector.detect(in: visionImage) { (barcodes, error) in guard error == nil, let barcodes = barcodes, !barcodes.isEmpty else { self.dismiss(animated: true, completion: nil) self.resultView.text = "No Barcode Detected" return } for barcode in barcodes { // handle the detected barcode } }
第1步:初始化 Detector let barcodeDetector: VisionBarcodeDetector = Vision.vision().barcodeDetector(options: options) let
visionImage = VisionImage(image: pickedImage)
第2步:取得結果 barcodeDetector.detect(in: visionImage) { (barcodes, error) in guard error ==
nil, let barcodes = barcodes, !barcodes.isEmpty else { self.dismiss(animated: true, completion: nil) self.resultView.text = "No Barcode Detected" return } for barcode in barcodes { // handle the detected barcode } }
⽀支援的 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) lazy var textDetector: VisionTextDetector = Vision.vision().textDetector() func
runTextRecognition(with image: UIImage) { let visionImage = VisionImage(image: image) textDetector.detect(in: visionImage) { (features, error) in if let error = error { print("Received error: \(error)") } self.processResult(from: features, error: error) } }
辨識⽂文字 (Cloud) Lazy var cloudTextDetector: VisionCloudTextDetector = Vision.vision().cloudTextDetector() func
runCloudTextRecognition(with image: UIImage) { let visionImage = VisionImage(image: image) cloudTextDetector.detect(in: visionImage) { (features, error) in if let error = error { print("Received error: \(error)") } self.processCloudResult(from: features, error: error) } }
補充資料 • 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-ios/ • https://github.com/firebase/quickstart-ios/tree/master/ mlvision • https://www.appcoda.com.tw/ml-kit/
None