使用tf.keras时,出现错误:
AssertionError: Do not use tf.reset_default_graph() to clear nested graphs.
If you need a cleared graph, exit the nesting and create a new graph.
代码如下:
from tensorflow import keras
config = tf.ConfigProto()
with tf.Session(config=config) as sess:
keras.reset_default_graph()
model = Network(n_H0, n_W0, n_C0, n_y)
print('Start Training...')
train(X_train, Y_train, sess, model)
原因:
keras.reset_default_graph()不能位于 with tf.Session(config=config) as sess:内,类似的还有 分布式训练时,with strategy.scope()等。需要将该操作前置,或弃用。
ops.reset_default_graph()
config = tf.ConfigProto()
with tf.Session(config=config) as sess:
model = Network(n_H0, n_W0, n_C0, n_y)
print('Start Training...')
train(X_train, Y_train, sess, model)
————————————————