Using Core ML with Keras and TensorFlow

The coremltools tool also officially supports converting models built with Keras (see the keras.convert link at https://apple.github.io/coremltools/coremltools.converters.html). The latest version of coremltools, 0.8, as of March 2018, works with TensorFlow 1.4 and Keras 2.1.5, which we used to build the Keras stock prediction model in Chapter 8, Predicting Stock Price with RNN. There are two ways you can use coremltools to generate the Core ML format of the model. The first is to call coremltools' convert and save methods directly in the Python Keras code after the model has been trained. For example, add the last three lines of code below to the ch8/python/keras/train.py file after model.fit:

model.fit( ...

Get Intelligent Mobile Projects with TensorFlow now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.