为了账号安全,请及时绑定邮箱和手机立即绑定

报错Attempted to use a closed Session.是怎么回事呀

我的session应该是正常的呀

x = tf.compat.v1.placeholder('float', [None, 784])
sess = tf.Session()


#取出线性回归方法
with tf.variable_scope('regression'):
    y1, variables = model.regression(x)

saver = tf.train.Saver(variables)
saver.restore(sess, 'mnist/data/regression.ckpt')

#取出训练好的卷积的模型
with tf.variable_scope('convolutionoal'):
    keep_prob = tf.placeholder('float')
    y2, variables = model.convolutional(x, keep_prob)

saver = tf.train.Saver(variables)
#saver.restore(sess, "mnist/data/convalutional.ckpt")
#tf.train.latest_checkpoint('mnist/data/convalutional.ckpt')
module_file =  tf.train.latest_checkpoint('mnist/data/convolutional.ckpt')
with tf.Session() as sess:
   sess.run(tf.global_variables_initializer())
   if module_file is not None:
      saver.restore(sess, module_file)

#定义输入  线性
def regression(input):
    return sess.run(y1, feed_dict={x: input}).flatten().tolist()
#定义输入   卷积
def convolutional(input):
    return sess.run(y2, feed_dict={x: input, keep_prob: 1.0}).flatten().tolist()


正在回答

2 回答

举报

0/150
提交
取消

报错Attempted to use a closed Session.是怎么回事呀

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信