Converting a full model to a reduced float16 model
In this section, we are going to load the model we just trained and quantize it into a reduced float16
model. For the convenience of step-by-step explanations and your learning experience, it is recommended that you use JupyterLab or Jupyter Notebook to follow along with the explanation here:
- Let's start by loading the trained model:
import tensorflow as tf import pathlib import os import numpy as np from matplotlib.pyplot import imshow import matplotlib.pyplot as plt root_dir = '../train_base_model' model_dir = ' trained_resnet_vector-unquantized/save_model' saved_model_dir = os.path.join(root_dir, model_dir) trained_model = tf.saved_model.load(saved_model_dir)
The
tf.saved_model.load
API helps us to load the saved model we built and trained. - Then we will create a
converter
object to refer to thesavedModel
directory with the following line of code:converter = tf.lite.TFLiteConverter.from_saved_model...