python - 如何使用 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:尝试使用关闭的会话。
我不明白我做错了什么,有人可以帮忙吗?
解决方案
您可以在没有and的情况下从 except 块中删除try
和except
阻止并仅提及以下行,这应该可以。try
except
modell.fit(trening, output, n_epoch=1000, batch_size=8, show_metric=True)
modell.save("modell.tflearn")
推荐阅读
- node.js - 是否有任何使用 PostgreSQL 管理 React / NodeJS + Express CRUD 应用程序的 OSS 项目?
- javascript - Javascript 无法从成员函数中删除成员属性
- c - C - 如何为可变长度的字符串输入分配内存?
- sql-server - 将新按钮添加到 App 组件并在按钮单击时显示弹出窗口
- prolog - 如何在Prolog中制作“小于”功能?
- java - 重定向到 Android 应用程序时,我们如何从 URL 中提取值?
- kubernetes - 在没有 kubeadm 的情况下创建 Bootstrap-Token
- python - 使用 Web(Html css) 和 Python 进行人脸检测
- amazon-web-services - Docker容器导出和部署问题
- .net - 在 WorkerService 文件生成中不仅仅适用于 Linux .Net Core