CoreMLͰ͡ΊΔػցֶश
Neural Networks on Keras ( TensorFlow backends )
Timers inc. / Github: naru-jpn / Twitter: @naruchigi
Slide 2
Slide 2 text
CoreMLͰ͡ΊΔػցֶश
Timers inc. / Github: naru-jpn / Twitter: @naruchigi
Neural Networks on Keras ( TensorFlow backends )
Slide 3
Slide 3 text
What is Neural Networks?
Slide 4
Slide 4 text
One of machine learning models.
- Neural networks
- Tree ensembles
- Support vector machines
- Generalized linear models
- …
https://developer.apple.com/documentation/coreml/converting_trained_models_to_core_ml
Slide 5
Slide 5 text
What is Keras?
Slide 6
Slide 6 text
Theano TensorFlow
Keras
Keras is a high-level neural networks API, written in Python and
capable of running on top of either TensorFlow, CNTK or Theano.
https://keras.io
Slide 7
Slide 7 text
What is CoreML?
Slide 8
Slide 8 text
Accelerate and BNNS Metal Performance Shaders
CoreML
BNNS : Basic Neural Network Subroutines
https://developer.apple.com/documentation/coreml
With Core ML,
you can integrate trained machine learning models into your app.
Core ML requires the Core ML model format.
Slide 9
Slide 9 text
CoreML
Trained Model
Application
Keras
Train
coremltools
Slide 10
Slide 10 text
What is coremltools?
Slide 11
Slide 11 text
Convert existing models to .mlmodel format
from popular machine learning tools
including Keras, Caffe, scikit-learn, libsvm, and XGBoost.
https://pypi.python.org/pypi/coremltools
coremltools
Slide 12
Slide 12 text
CoreML
Trained Model
Application
Keras
Train
coremltools
Programs to train neural networks
- mnist_mlp.py
- mnist_cnn.py
※ Keras ͷ࠷৽όʔδϣϯͷϦϯΫʹͳ͍ͬͯ·͕͢ɺ࣮ࡍόʔδϣϯ 1.2.2 Λࢀর͠·͢ɻ
https://github.com/fchollet/keras/tree/master/examples
Slide 16
Slide 16 text
Convert model with coremltools
1. Import coremltools
import coremltools
model = Sequential()
…
coreml_model = coremltools.converters.keras.convert(model)
coreml_model.save("keras_mnist_mlp.mlmodel")
2. Convert model
Slide 17
Slide 17 text
Import model into Xcode project
// 入力データ
class keras_mnist_mlpInput : MLFeatureProvider {
var input1: MLMultiArray
// …
}
// 出力データ
class keras_mnist_mlpOutput : MLFeatureProvider {
var output1: MLMultiArray
// …
}
// モデル
@objc class keras_mnist_mlp:NSObject {
var model: MLModel
init(contentsOf url: URL) throws {
self.model = try MLModel(contentsOf: url)
}
// …
func prediction(input: keras_mnist_mlpInput) throws -> keras_mnist_mlpOutput {
// …
keras_mnist_mlp.mlmodel Λѻ͏ҝͷίʔυ͕ࣗಈੜ͞ΕΔ
Slide 18
Slide 18 text
Prepare model and input in code
// モデルの作成
let model = keras_mnist_mlp()
// 入力データの格納用変数 (入力は28*28の画像)
let input = keras_mnist_mlpInput(
input1: try! MLMultiArray(shape: [784], dataType: .double)
)