tensorflow:self.stack [-1]不是默认值(列表索引超出范围)

时间:2017-11-13 12:54:01

标签: python tensorflow

我收到错误消息:

  

IndexErrorTraceback(最近一次调用最后一次)

/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.pyc in get_controller(self, default)
3813     finally:
3814       if self._enforce_nesting:
-> 3815         if self.stack[-1] is not default:
3816           raise AssertionError(
3817               "Nesting violated for default stack of %s objects"
     

IndexError:列表索引超出范围

我的代码是这样的:

with tf.Graph().as_default():
    tf.reset_default_graph()
    session_conf = tf.ConfigProto(
      allow_soft_placement=True,
      log_device_placement=False)
    sess = tf.Session(config=session_conf)
    with sess.as_default():
        cnn = TextCNN(
            sequence_length=708,
            num_classes=9,
            embedding_size=embedding_size,
            filter_sizes=filter_sizes,
            num_filters=num_filters,
            l2_reg_lambda=l2_reg_lambda)

        ...

        step = 0
        while step < num_epochs:
            x_batch, y_batch = next_batch(training_x, training_y, training_prot_num)
            v_x_batch, v_y_batch = next_batch(validation_x, validation_y, validation_prot_num)
            train_step(x_batch, y_batch)
            currenct_step = tf.train.global_step(sess, gloabl_step)
            if currect_step % evaluate_every == 0:
                print("\nEvaluation:")
                dev_step(v_x_batch,v_y_batch)
                print("")

如何修改此代码以修复错误?

1 个答案:

答案 0 :(得分:1)

您的问题与this StackOverflow question类似。

尝试删除tf.reset_default_graph()并查看是否可以解决您的问题。