Beruflich Dokumente
Kultur Dokumente
Part two
© 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.
Core ML
Part One Recap
Model size
•
Performance
•
Customization 60 MB 15 MB
•
Part One Recap
Model size
•
Performance
•
Customization
•
Part One Recap
Model size
•
Performance
•
Customization
•
Part One Recap
Model size
•
Performance
•
Customization
•
Part Two
Agenda
Agenda
Quantization utilities
Agenda
Quantization utilities
•
Custom conversion
•
Quantization utilities
•
Custom conversion
?
Download
https://developer.apple.com/machine-learning/
NEW
Create ML
Last Year
Core ML Tools
https://github.com/apple/coremltools
Last Year
Core ML Tools
Today
Core ML Tools
Today
Core ML Tools
TensorFlow Converter
https://github.com/tf-coreml/tf-coreml
Quantization utilities
•
Custom conversion
•
Quantization utilities
Core ML Tools
Post-training Quantization
Quantization
Peeking under the hood
W W W
Quantization
Peeking under the hood
W
Quantization
Peeking under the hood
W
Quantization
Peeking under the hood
0.14
0.15
0.35
W 0.26
0.34
0.87
0.13
…
Weight Quantization
Peeking under the hood
Min Max
Float weights
Weight Quantization
Peeking under the hood
Min Max
Float weights
Quantized weights
Linear
Three-bit example
Min Max
Float weights
Quantized weights
0 1 2 3 4 5 6 7
Linear
Three-bit example
Min Max
Float weights
scale*quantized + bias
Quantized weights
0 1 2 3 4 5 6 7
Lookup Table
Three-bit example
Min Max
Float weights
Quantized weights
0 1 2 3 4 5 6 7
Lookup Table
Three-bit example
Min Max
Float weights
lookupTable[quantized]
Quantized weights
0 1 2 3 4 5 6 7
Quantization Utilities
Core ML Tools
Core ML Tools
Core ML Tools
Demo
Quantization in Core ML Tools
// Quantize model using KMeans Lookup Table
quantized_model = quantize_weights(model, 8, ‘kmeans’)
Model 1
Agreement Model 2
Metric
Model Size
Model Size Versus Agreement
Model 1
Agreement Model 2
Metric
Model Size
Model Size Versus Agreement
Metrics
• Accuracy Model 1
• Model-specific metrics
Model Size
32 bit - 6.7 MB 16 bit - 3.4 MB 8 bit (linear) - 1.7 MB
Quantization utilities
•
Custom conversion
•
Custom Conversion
import coremltools
coremltools.converters.keras.convert(keras_model)
Model Conversion
import onnx_coreml
onnx_coreml.convert(onnx_model)
Model Conversion
import tfcoreml
tfcoreml.convert(tf_model_path=tf_model_path,
mlmodel_path=mlmodel_path,
output_feature_names=['output:0'])
Model Conversion
import tfcoreml
tfcoreml.convert(tf_model_path=tf_model_path,
mlmodel_path=mlmodel_path,
output_feature_names=[‘output:0'],
)
Model Conversion
import tfcoreml
tfcoreml.convert(tf_model_path=tf_model_path,
mlmodel_path=mlmodel_path,
output_feature_names=[‘output:0'],
)
Beach
Opening the Hood
Beach
Neural Network
Convertible to Core ML
ReLU ReLU
Convolution Convolution Convolution
Activation Activation
Supported by Core ML
Not convertible to Core ML
New New
Convolution Convolution Convolution
Activation Activation
Supported by Core ML
New New
Convolution Convolution Convolution
Activation Activation
Supported by Core ML
Beach
Beach
Classifier Net
6
Localization Net
sha1_base64="8ziVlcrM346ng4sDFlX68r05NSY=">AAAB7nicjVDLSgNBEOyNrxhfUY9eBoPgKeyKoMegF48RzAOSJcxOOsmQ2dllplcISz7CiwdFvPo93vwbJ4+DioIFDUVVN91dUaqkJd//8Aorq2vrG8XN0tb2zu5eef+gaZPMCGyIRCWmHXGLSmpskCSF7dQgjyOFrWh8PfNb92isTPQdTVIMYz7UciAFJye1ujRC4qVeuRJU/TnY36QCS9R75fduPxFZjJqE4tZ2Aj+lMOeGpFA4LXUziykXYz7EjqOax2jDfH7ulJ04pc8GiXGlic3VrxM5j62dxJHrjDmN7E9vJv7mdTIaXIa51GlGqMVi0SBTjBI2+531pUFBauIIF0a6W5kYccMFuYT+GULzrBr41eD2vFK7WsZRhCM4hlMI4AJqcAN1aICAMTzAEzx7qffovXivi9aCt5w5hG/w3j4B3uSPPw==</latexit>
sha1_base64="8ziVlcrM346ng4sDFlX68r05NSY=">AAAB7nicjVDLSgNBEOyNrxhfUY9eBoPgKeyKoMegF48RzAOSJcxOOsmQ2dllplcISz7CiwdFvPo93vwbJ4+DioIFDUVVN91dUaqkJd//8Aorq2vrG8XN0tb2zu5eef+gaZPMCGyIRCWmHXGLSmpskCSF7dQgjyOFrWh8PfNb92isTPQdTVIMYz7UciAFJye1ujRC4qVeuRJU/TnY36QCS9R75fduPxFZjJqE4tZ2Aj+lMOeGpFA4LXUziykXYz7EjqOax2jDfH7ulJ04pc8GiXGlic3VrxM5j62dxJHrjDmN7E9vJv7mdTIaXIa51GlGqMVi0SBTjBI2+531pUFBauIIF0a6W5kYccMFuYT+GULzrBr41eD2vFK7WsZRhCM4hlMI4AJqcAN1aICAMTzAEzx7qffovXivi9aCt5w5hG/w3j4B3uSPPw==</latexit><latexit
sha1_base64="8ziVlcrM346ng4sDFlX68r05NSY=">AAAB7nicjVDLSgNBEOyNrxhfUY9eBoPgKeyKoMegF48RzAOSJcxOOsmQ2dllplcISz7CiwdFvPo93vwbJ4+DioIFDUVVN91dUaqkJd//8Aorq2vrG8XN0tb2zu5eef+gaZPMCGyIRCWmHXGLSmpskCSF7dQgjyOFrWh8PfNb92isTPQdTVIMYz7UciAFJye1ujRC4qVeuRJU/TnY36QCS9R75fduPxFZjJqE4tZ2Aj+lMOeGpFA4LXUziykXYz7EjqOax2jDfH7ulJ04pc8GiXGlic3VrxM5j62dxJHrjDmN7E9vJv7mdTIaXIa51GlGqMVi0SBTjBI2+531pUFBauIIF0a6W5kYccMFuYT+GULzrBr41eD2vFK7WsZRhCM4hlMI4AJqcAN1aICAMTzAEzx7qffovXivi9aCt5w5hG/w3j4B3uSPPw==</latexit><latexit
sha1_base64="8ziVlcrM346ng4sDFlX68r05NSY=">AAAB7nicjVDLSgNBEOyNrxhfUY9eBoPgKeyKoMegF48RzAOSJcxOOsmQ2dllplcISz7CiwdFvPo93vwbJ4+DioIFDUVVN91dUaqkJd//8Aorq2vrG8XN0tb2zu5eef+gaZPMCGyIRCWmHXGLSmpskCSF7dQgjyOFrWh8PfNb92isTPQdTVIMYz7UciAFJye1ujRC4qVeuRJU/TnY36QCS9R75fduPxFZjJqE4tZ2Aj+lMOeGpFA4LXUziykXYz7EjqOax2jDfH7ulJ04pc8GiXGlic3VrxM5j62dxJHrjDmN7E9vJv7mdTIaXIa51GlGqMVi0SBTjBI2+531pUFBauIIF0a6W5kYccMFuYT+GULzrBr41eD2vFK7WsZRhCM4hlMI4AJqcAN1aICAMTzAEzx7qffovXivi9aCt5w5hG/w3j4B3uSPPw==</latexit><latexit
latexit
<
✓
Spatial Transformer Network
Grid Sampler
(Custom layer)
Jaderberg, Max, Karen Simonyan, and Andrew Zisserman. "Spatial transformer networks." Advances in neural information processing systems. 2015.
Classifier Net
6
•
Demo
•
gridSampler.swift
Custom Layer
New Model
Summary
Core ML Tools 2.0
Core ML Tools 2.0