TF2 AttributeError: 'FuncGraph' object has no attribute 'outer_graph'

Viewed 33

I use ModelCheckpoint in tf 2.0, and then meet this error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-44-9c7ccc2cd985> in <module>
     33           verbose = 0,
     34           callbacks=[model_check_point_callbacks],
---> 35           epochs=5)

...

/usr/local/anaconda3/lib/python3.6/site-packages/tensorflow_core/python/framework/func_graph.py in capture(self, tensor, name)
    602               " it. Defined in: %s; accessed from: %s.\n"
    603               % (tensor, tensor.graph, self))
--> 604         inner_graph = inner_graph.outer_graph
    605       return self._capture_helper(tensor, name)
    606     return tensor

AttributeError: 'FuncGraph' object has no attribute 'outer_graph'

It happens when using callback to save the model. The log record the message Epoch 00001: val_loss improved from inf to 0.38231, saving model to saved_models/test_model-0.38 and then it aborts. My code likes this:

import tensorflow as tf

model_check_point_callbacks = tf.keras.callbacks.ModelCheckpoint(filepath="saved_models/test_model-{val_loss:.2f}", 
                                       save_best_only=True, monitor="val_loss",                                                                               
                                       verbose=1,
                                       mode = 'min')
                                      
model.fit(train_ds,
          validation_data=val_ds,
          verbose = 1,
          callbacks=[model_check_point_callbacks],
          epochs=5)

I find it happends when saving the model. If I only save the weights using save_weights_only=True, the program runs well.

0 Answers
Related