ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
CORE ML
§³§´§°§ª§´ §­§ª?
Introduction
Kirill Averyanov !
Discussion
Vision
Pros
Cons
3
CoreML
Siri
new voice "
ARKit
WWDC Results
Machine Learning
ML INTRO
5
Training ModelTask
6
Task
Real Time Image Recognition
Text Prediction
Sentiment Analysis
Machine Translation
Face Detection
Emotion Detection
Personalization Search Prediction
Music Tagging
Natural Language Processing
Speaker Identi?cation
Handwriting Recognition
Task
7
Task
ML INTRO
8
Training ModelTask
Training
9
Training
With
Teacher
Without
Teacher
Training
10
Training
Images + Labels
Learning
Algorithm
Model
With
Teacher
Training
11
Training
Images + Labels
Learning
Algorithm
Model
With
Teacher
64 pixels
+ 1 / 0
1 - hotdog
0 - not hotdog
Training
12
Training
With
Teacher
Without
Teacher
Training
13
Training
Without
Teacher
ML INTRO
14
Training ModelTask
Model
15
Model
Model OUTPUTINPUT
Classical Problems
16
? Classi?cation
? Regression
? Cluster analysis
Classi?cation
17
Square
Classical Problems
18
? Classi?cation
? Regression
? Cluster analysis
Regression
19
a b c
aX1 + bX2 + c = y
Y - §£§à§Ù§â§Ñ§ã§ä
X1 - §£§Ö§ã
X2 - §²§à§ã§ä
Classical Problems
20
? Classi?cation
? Regression
? Cluster analysis
Cluster Analysis
21
Cluster Analysis
22
Classi?cation
Regression
Clustering
Ranking
Dimensionality reduction
Density estimation
Structure prediction
Anomaly
Novelty detection
Rule mining
Denoising
Data compression
Representation learning
Reinforcement learning
24
Your App
Vision Natural Language Processing GameplayKit
Core ML
Accelerate and BNNS Metal Performance Shaders
7 §ñ§Ù§í§Ü§à§Ó,
§Á §Ô§à§Ó§à§â§ð §ß§Ñ
§â§å§ã§ã§Ü§à§Þ!
52 §ñ§Ù§í§Ü§Ñ
§¥§Ý§ñ
§à§á§â§Ö§Õ§Ö§Ý§Ö§ß§Ú§ñ
§ñ§Ù§í§Ü§Ñ
CORE ML
CORE ML
26
Trained model on your device
CORE ML INTRO
27
let model = ModelName()
Core ML Speech
Core ML Speech
Core ML Speech
Core ML Speech
Model
32
Label: iPhone
Con?dence: 90%
let model = §³lassi?er()
If let prediction = try? model.prediction(image: image) {
return prediction.type
}
Model
33
Label: iPhone
Con?dence: 90%
let model = §³lassi?er()
If let prediction = try? model.prediction(image: image) {
return prediction.type
}
CORE ML INTRO
34
C
INPUT & OUTPUT
36
Numeric
Categories
Images
Arrays
Dictionaries
Double, Int64
String, Int64
CVPixelBuffer
MLMultiArray
[ String : Double ], [ Int64 : Double ]
37
Numeric
Categories
Images
Arrays
Dictionaries
Double, Int64
String, Int64
CVPixelBuffer
MLMultiArray
[ String : Double ], [ Int64 : Double ]
38
Numeric
Categories
Images
Arrays
Dictionaries
Double, Int64
String, Int64
CVPixelBuffer
MLMultiArray
[ String : Double ], [ Int64 : Double ]
39
Numeric
Categories
Images
Arrays
Dictionaries
Double, Int64
String, Int64
CVPixelBuffer
MLMultiArray
[ String : Double ], [ Int64 : Double ]
40
Numeric
Categories
Images
Arrays
Dictionaries
Double, Int64
String, Int64
CVPixelBuffer
MLMultiArray
[ String : Double ], [ Int64 : Double ]
41
42
CVPixelBuffer
44
func buffer(from image: UIImage) -> CVPixelBuffer? {
let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue,
kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] as CFDictionary
var pixelBuffer: CVPixelBuffer?
let status = CVPixelBufferCreate(kCFAllocatorDefault, Int(image.size.width),
Int(image.size.height), kCVPixelFormatType_32ARGB,
attrs, &pixelBuffer)
guard status == kCVReturnSuccess else {
return nil
}
CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer!)
let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
let context = CGContext(data: pixelData, width: Int(image.size.width),
height: Int(image.size.height), bitsPerComponent: 8,
bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer!),
space: rgbColorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue)
context?.translateBy(x: 0, y: image.size.height)
context?.scaleBy(x: 1.0, y: -1.0)
UIGraphicsPushContext(context!)
image.draw(in: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
UIGraphicsPopContext()
CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0))
return pixelBuffer
}
Vision
46
47
48
Real Time
50
Feature
51
AVFoundation + Vision + Core ML
Feature
52
AVFoundation + Vision + Core ML
SUMMARY
53
C
Input
CVPixelBuffer
Vision
ML MODEL?
55
https://developer.apple.com/machine-learning/
56
Core ML Tools
58
Core ML Tools
59
Core ML Tools
Open Source v0.4
CORE ML TOOLS
Let¡¯s try
61
VIRTUAL ENV
62
pip install virtualenv
virtualenv --python=/usr/bin/python2.7 python27
source python27/bin/activate
pip install -U coremltools
VIRTUAL ENV
63
pip install virtualenv
virtualenv --python=/usr/bin/python2.7 python27
source python27/bin/activate
pip install -U coremltools
VIRTUAL ENV
64
pip install virtualenv
virtualenv --python=/usr/bin/python2.7 python27
source python27/bin/activate
pip install -U coremltools
VIRTUAL ENV
65
pip install virtualenv
virtualenv --python=/usr/bin/python2.7 python27
source python27/bin/activate
pip install -U coremltools
VIRTUAL ENV
66
pip install virtualenv
virtualenv --python=/usr/bin/python2.7 python27
source python27/bin/activate
pip install -U coremltools
CONVERT
68
import coremltools

# Convert a ca?e model to a classi?er in Core ML

coreml_model = coremltools.converters.ca?e.convert(('bvlc_alexnet.ca?emodel', 

¡®deploy.prototxt'), 

predicted_feature_name='class_labels.txt')

# Now save the model

coreml_model.save('BVLCObjectClassi?er.mlmodel')
69
import coremltools

# Convert a ca?e model to a classi?er in Core ML

coreml_model = coremltools.converters.ca?e.convert(('bvlc_alexnet.ca?emodel', 

¡®deploy.prototxt'), 

predicted_feature_name='class_labels.txt')

# Now save the model

coreml_model.save('BVLCObjectClassi?er.mlmodel')
70
import coremltools

# Convert a ca?e model to a classi?er in Core ML

coreml_model = coremltools.converters.ca?e.convert(('bvlc_alexnet.ca?emodel', 

¡®deploy.prototxt'), 

predicted_feature_name='class_labels.txt')

# Now save the model

coreml_model.save('BVLCObjectClassi?er.mlmodel')
71
import coremltools

# Convert a ca?e model to a classi?er in Core ML

coreml_model = coremltools.converters.ca?e.convert(('bvlc_alexnet.ca?emodel', 

¡®deploy.prototxt'), 

predicted_feature_name='class_labels.txt')

# Now save the model

coreml_model.save('BVLCObjectClassi?er.mlmodel')
72
Core ML Speech
PROS
PROS
75
User Privacy Data Cost Server Cost
Always
Available
CONS
1 2 3
2 Types of ML
78
1
Regression & Classi?cation
79
1
1 2 3
Training & Updating
81
2
1 2 3
Not Compressing
83
3
Results
Results
85
Small
Huge
TO READ
86
?https://developer.apple.com/videos/play/wwdc2017/703/
?https://developer.apple.com/videos/play/wwdc2017/703/
?https://developer.apple.com/videos/play/wwdc2017/208/
?https://developer.apple.com/videos/play/wwdc2017/506/
?https://developer.apple.com/documentation/coreml
?https://alexsosn.github.io/ml/2017/06/09/Core-ML-will-not-Work-for-Your-
App.htm
?https://medium.com/@s1ddok/holistically-nested-edge-detection-on-ios-
with-coreml-and-swift-e45df264cf66
https://machinelearning.apple.com
87
Thanks!
@kirillzzy

More Related Content

Core ML Speech