Converting the TensorFlow model into the Core ML model

The TensorFlow team has developed a package that is used to convert the models created in TensorFlow into Core ML, which in through is used in iOS apps. To use this, you must have macOS with Python 3.6 and TensorFlow installed. Using this, we can convert the TensorFlow model file (.pb) into the Core ML format (.mlmodel). First, you need to execute the following command:

Pip install tfcoreml

Once this is installed, write the following code in your Python file, name it inspect.py, and save it:

import tensorflow as tffrom tensorflow.core.framework import graph_pb2import timeimport operatorimport sys def inspect(model_pb, output_txt_file):    graph_def = graph_pb2.GraphDef() with open(model_pb, ...

Get Machine Learning for Mobile 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.