相关文章推荐
有腹肌的火腿肠  ·  Spring ...·  1 月前    · 
傻傻的伤痕  ·  如何实现C# ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.