0

I'm having an error in the last line of the following code portion:

confusionMatrix = tf.confusion_matrix(labels=y_true_cls,predictions=y_pred_cls)
x_batch, y_batch, _, cls_batch = data.valid.next_batch(batch_size_validation)
confusionMatrix = session.run(confusionMatrix, feed_dict={x: x_batch, y_true: y_batch})

The error states the following:

NameError: name 'session' is not defined

At the end of my code (after the above code portion), I have the following:

with tf.Session() as session:
    init = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
    session.run(init)
    train( num_iteration=1000)

How can I solve this issue?

Thanks.

1
  • 1
    session can only be used within the with block... Commented Apr 20, 2018 at 23:16

2 Answers 2

2

You haven't defined session prior to session.run() . Simply define it (for example session=tf.Session()) and it should work.

Sign up to request clarification or add additional context in comments.

Comments

1

I simply included my confusion matrix in a function called evaluate(), and issued a call to evaluate() under train(num_iteration=1000) in the with tf.Session() as session: block:

with tf.Session() as session:
    init = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
    session.run(init)
    train(num_iteration=10000)
    evaluate()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.