Reputation: 93
For example, some model has been pre-trained with a TensorFlow 1 architecture. Is it possible to load this TensorFlow 1 model in TensorFlow 2 with tf.keras.models.load_model(...)
?
Upvotes: 1
Views: 3190
Reputation: 379
In order to use tensorflow v1 models in tensorflow v2 you would need to import the compatibility module as tf.compat.v1
and disable tensorflow v2 behavior through tf.compat.v1.disable_v2_behavior()
You can load a version 1 model checkpoint through:
with tf.Session() as sess:
# Restore variables from disk.
saver.restore(sess, "/tmp/model.ckpt")
As for using the checkpoint in that way, you would need to convert your model using the training code as SavedModel
which is the correct format for usage in tensorflow v2.
Upvotes: 1