As we mentioned earlier, on-device machine learning is typically used for inference. Therefore, a prerequisite is to have a trained model. Hopefully, this book will have given you a good idea of how to implement and prepare your network. We now need to convert the model to an intermediate file format. It will then be converted by a library for mobile use.
In TensorFlow 2, the intermediate format of choice is SavedModel. A SavedModel contains the model architecture (the graph) and the weights.
Most TensorFlow objects can be exported as a SavedModel. For instance, the following code exports a trained Keras model:
tf.saved_model.save(model, export_dir='./saved_model')