1
$\begingroup$

I'm following the RNN text-generation tutorial with eager execution pretty much line for line. I've trained the model with my own data set and have saved a low loss checkpoint. I'm able to load the weights and generate text but I want to export/save the model so that I can learn how to deploy one using flask. However I can't figure out how. The version I'm using is '1.14.0-rc1'.

The tutorial: https://www.tensorflow.org/tutorials/sequences/text_generation

I have been able to save the model as an HDF5 file but I cannot load it. I've also disabled eager execution but that causes problems with running the code later on. I have tried the following and a few more snippets but those led to nothing as well:

new_model = keras.models.load_model("/content/gdrive/My Drive/ColabNotebooks/ckpt4/my_model.h5")

How ever I get

RuntimeError: tf.placeholder() is not compatible with eager execution.

Lastly I found this in another post and tried it as well but was met with another error:

tf.saved_model.save(model, "/content/gdrive/My Drive/Colab Notebooks/ckpt4/my_model.h5")

error:

AssertionError: Tried to export a function which references untracked object Tensor("StatefulPartitionedCall/args_2:0", shape=(), dtype=resource).TensorFlow objects (e.g. tf.Variable) captured by functions must be tracked by assigning them to an attribute of a tracked object or assigned to an attribute of the main object directly.

$\endgroup$
1
$\begingroup$

I ran into the same problem and solved it by running the keras that comes with tensorflow:

from tensorflow.python.keras.models import Model, load_model

instead of:

from keras.models import Model, load_model

I suspect there's a version mismatch at the core of this problem. Loading the model worked with the Keras included with the current Tensorflow 2.0.0-beta1.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.