Summary
Steps to convert Keras H5 model to an IR format.
Description
Unable to determine steps to convert Keras* H5 model to an IR format.
Resolution
Step 1: Convert Keras H5 model to SavedModel Format
- Install dependencies:
cd <INSTALL_DIR>\deployment_tools\model_optimizer\install_prerequisites
install_prerequisites_tf2.bat - Load the model using TensorFlow* 2 and serialize it in the SavedModel format.
import tensorflow as tf
model = tf.keras.models.load_model('model.h5')
tf.saved_model.save(model,'model') - Optional: Model with a custom layer CustomLayer from custom_layer.py:
import tensorflow as tf
from custom_layer import CustomLayer
model = tf.keras.models.load_model('model.h5', custom_objects={'CustomLayer': CustomLayer})
tf.saved_model.save(model,'model')
Step 2: Convert SavedModel Format to Intermediate Representation
- Change directory to <INSTALL_DIR>/deployment_tools/model_optimizer
- Run the mo_tf.py script with a path to the SavedModel directory and a writable output directory:
python mo_tf.py --saved_model_dir <SAVED_MODEL_DIRECTORY> --output_dir <OUTPUT_MODEL_DIR> --input_shape