I load a saved h5 model and want to save the model as pb.
The model is saved during training with the tf.keras.callbacks.ModelCheckpoint
callback function.
TF version: 2.0.0a
edit: same issue also with 2.0.0-beta1
My steps to save a pb:
- I first set
K.set_learning_phase(0)
- then I load the model with
tf.keras.models.load_model
- Then, I define the
freeze_session()
function. - (optional I compile the model)
- Then using the
freeze_session()
function withtf.keras.backend.get_session
The error I get, with and without compiling:
AttributeError: module 'tensorflow.python.keras.api._v2.keras.backend' has no attribute 'get_session'
My Question:
Does TF2 not have the
get_session
anymore? (I know thattf.contrib.saved_model.save_keras_model
does not exist anymore and I also triedtf.saved_model.save
which not really worked)Or does
get_session
only work when I actually train the model and just loading the h5 does not work Edit: Also with a freshly trained session, no get_session is available.- If so, how would I go about to convert the h5 without training to pb? Is there a good tutorial?
Thank you for your help
update:
Since the official release of TF2.x graph/session concept has changed. The savedmodel
api should be used.
You can use the tf.compat.v1.disable_eager_execution()
with TF2.x and it will result in a pb file. However, I am not sure what kind of pb file type it is, as saved model composition changed from TF1 to TF2. I will keep digging.