Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ML Kit Introduction (for iOS)

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

More Decks by Elvis Lin

Other Decks in Programming

Transcript

  1. 關於我 • Elvis Lin • iOS 與 Android 永遠的初學者 •

    Twitter: @elvismetaphor • Blog: https://blog.elvismetaphor.me
  2. 轉換 Tensorflow 檔案的⼯工具 • Tensorflow converter • 轉成 Tensorflow Lite

    格式
 • Tensorflow-CoreML converter • 轉成 CoreML 格式 • https://github.com/tf-coreml/tf-coreml
  3. ML Kit • Cloud Vision API / Mobile Vision API

    • Tensorflow Lite • 整合 Firebase,託管「客製化的模型」
  4. ML Kit Base APIs • Image labeling • Text recognition

    (OCR) • Face detection • Barcode scanning • Landmark detection • others……
  5. 安裝 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'
  6. 掃描 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 } }
  7. 第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 } }
  8. ⽀支援的 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)
  9. 辨識⽂文字 (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) } }
  10. 辨識⽂文字 (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) } }
  11. 補充資料 • 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