Gi Yeon  Shin
Gi Yeon Shin

Reputation: 367

tensorflow: self.stack[-1] is not default (list index out of range)

I got error message such this:

IndexErrorTraceback (most recent call last)

/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: list index out of range

My code like this:

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("")

How should I modify this code for fixing errors?

Upvotes: 0

Views: 467

Answers (1)

Sunreef
Sunreef

Reputation: 4542

Your problem seems similar to this StackOverflow question.

Try removing tf.reset_default_graph() and see if that fixes your issue.

Upvotes: 1

Related Questions