Slide 1

Slide 1 text

Pragmatic Machine Learning for iOS apps

Slide 2

Slide 2 text

About • Khoa • iOS developer, at Shortcut • https:/ /onmyway133.github.io

Slide 3

Slide 3 text

Agenda • Deep Learning • Layer in Neural Network • Activation Functions • Training in Neural Network • Loss, Learning Rate • Train, Test & Validation Sets • Predicting • Overfitting

Slide 4

Slide 4 text

Agenda (cont) • Convolutional Neural networks & visualizing • Zero padding, max pooling • Explain back propagation • Vanishing & Exploding Gradient • Weight Initialization & Bias • Learnable parameters • Regularizationm, batch size, fine tuning and batch normalization

Slide 5

Slide 5 text

Pragmatic

Slide 6

Slide 6 text

My Sentosa

Slide 7

Slide 7 text

Pragmatic

Slide 8

Slide 8 text

Pragmatic

Slide 9

Slide 9 text

Pragmatic How I replicated an $86 million project in 57 lines of code

Slide 10

Slide 10 text

Farming

Slide 11

Slide 11 text

CoreML

Slide 12

Slide 12 text

CoreML • Computer Vision: image classification • Natural Language: language idenification, tokenization • Speech: speech recognition

Slide 13

Slide 13 text

Image classification Preprocess photos using the Vision framework and classify them with a Core ML model. iOS app Avengers https:/ /github.com/onmyway133/avengers

Slide 14

Slide 14 text

Avengers • SwiftUI • CoreML • Vision

Slide 15

Slide 15 text

Tools • IBM Watson • Azure Custom Vision • Google AutoML • Firebase Vision Edge • CreateML • Turi Create

Slide 16

Slide 16 text

Data set • Google images download https:/ /github.com/hardikvasa/google- images-download • Data augmentation

Slide 17

Slide 17 text

IBM Watson Visual Recognition • https:/ /www.ibm.com/watson/services/visual-recognition/ • https:/ /cloud.ibm.com/developer/watson/services • https:/ /www.ibm.com/cloud/watson-studio • https:/ /dataplatform.cloud.ibm.com/home

Slide 18

Slide 18 text

IBM Watson Visual Recognition - Service

Slide 19

Slide 19 text

IBM Watson Visual Recognition - Assets

Slide 20

Slide 20 text

IBM Watson Visual Recognition - Train

Slide 21

Slide 21 text

IBM Watson Visual Recognition - Watson SDK let classifierID = "your-classifier-id" let failure = { (error: Error) in print(error) } visualRecognition.updateLocalModel(classifierID: classifierID, failure: failure) { print("model updated") }

Slide 22

Slide 22 text

Vision

Slide 23

Slide 23 text

Vision

Slide 24

Slide 24 text

CoreML + Vision let model = try VNCoreMLModel(for: IBMWatson().model) let request = VNCoreMLRequest(model: model, completionHandler: { request, error in let results = request.results as? [VNClassificationObservation], let handler = VNImageRequestHandler(cgImage: image.cgImage!, options: [:]) try handler.perform([request])

Slide 25

Slide 25 text

Azure Custom Vision • https:/ /www.customvision.ai/

Slide 26

Slide 26 text

Azure Custom Vision - Project

Slide 27

Slide 27 text

Azure Custom Vision - Assets

Slide 28

Slide 28 text

Azure Custom Vision - Train

Slide 29

Slide 29 text

Google Cloud AutoML Vision • https:/ /cloud.google.com/automl/ • https:/ /console.cloud.google.com/vision

Slide 30

Slide 30 text

Google Cloud AutoML Vision

Slide 31

Slide 31 text

Google Cloud AutoML Vision - Dataset

Slide 32

Slide 32 text

Google Cloud AutoML Vision - Google Cloud Storage https:/ /console.cloud.google.com/storage

Slide 33

Slide 33 text

Firebase AutoML Vision Edge

Slide 34

Slide 34 text

Firebase AutoML Vision Edge - Dataset

Slide 35

Slide 35 text

Firebase AutoML Vision Edge - Dataset

Slide 36

Slide 36 text

Firebase AutoML Vision Edge - Train pod 'Firebase/MLModelInterpreter'

Slide 37

Slide 37 text

Fritz AI

Slide 38

Slide 38 text

CreateML • Activity, Sound, Image, Text, Tabular Classification • Word tagger • Recommendor • Object detection

Slide 39

Slide 39 text

CreateML - Create Document

Slide 40

Slide 40 text

CreateML - Data

Slide 41

Slide 41 text

CreateML - Train

Slide 42

Slide 42 text

CreateMLUI Playground • macOS Playground

Slide 43

Slide 43 text

Turi Create • https:/ /github.com/apple/turicreate • Open source Python framework • Latest version 5.8

Slide 44

Slide 44 text

Turi Create

Slide 45

Slide 45 text

Turi Create - SFrame import turicreate as tc import os # 1. Load images data = tc.image_analysis.load_images('dataset', with_path=True) # 2. Create label column based on folder name data['hero_name'] = data['path'].apply(lambda path: os.path.basename(os.path.dirname(path))) # 3. Save as .sframe data.save('turi.sframe') # 4. Explore data.explore()

Slide 46

Slide 46 text

Turi Create - Visualization

Slide 47

Slide 47 text

Turi Create - Training import turicreate as tc # 1. Load the data data = tc.SFrame('turi.sframe') # 2. Split to train and test data train_data, test_data = data.random_split(0.8) # 3. Create model model = tc.image_classifier.create(train_data, target='hero_name') # 4. Predictions predictions = model.predict(test_data) # 5. Evaluate the model and show metrics metrics = model.evaluate(test_data) print(metrics['accuracy']) # 6. Save the model model.save('turi.model') # 7. Export to CoreML format model.export_coreml('model/TuriCreate.mlmodel')

Slide 48

Slide 48 text

Turi Create - Transfer Learning resnet-50 model = tc.image_classifier.create(train_data, target='hero_name', model='squeezenet_v1.1')

Slide 49

Slide 49 text

Writing • Machine Learning in iOS: IBM Watson and CoreML • Machine Learning in iOS: Azure Custom Vision and CoreML • Machine Learning in iOS: Turi Create and CoreML • Vision in iOS: Text detection and Tesseract recognition

Slide 50

Slide 50 text

Thank you May your code continue to compile