首页 > 解决方案 > 如何使用 tensorflow 解决 reset_default_graph() 错误?

问题描述

我正在尝试用 VS 代码训练模型并编写了这段代码(其中的一部分):

import tensorflow as tf
import tflearn'
....
tf.reset_default_graph()

net = tflearn.input_data(shape=[None, len(trening[0])]) 
net = tflearn.fully_connected(net, 8) 
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, len(output[0]), activation="softmax") 
net = tflearn.regression(net)

modell = tflearn.DNN(net)

try: 
    modell.load("modell.tflearn")
except:
    modell.fit(trening, output, n_epoch=1000, batch_size=8, show_metric=True) 
    modell.save("modell.tflearn")
...

输出:raise RuntimeError('尝试使用关闭的会话。') RuntimeError:尝试使用关闭的会话。

我不明白我做错了什么,有人可以帮忙吗?

标签: pythonpython-3.xtensorflowartificial-intelligencetflearn

解决方案


您可以在没有and的情况下从 except 块中删除tryexcept阻止并仅提及以下行,这应该可以。tryexcept

modell.fit(trening, output, n_epoch=1000, batch_size=8, show_metric=True) 
modell.save("modell.tflearn")

推荐阅读