feng_h
feng_h

Reputation: 215

why the tf.Session() returns a wrong result?

I'm a newbie to tensorflow and met the problem below. I'm very thankful for your answer.

a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_node = a + b  

print(sess.run(adder_node, {a: 3, b:4.5}))

then the result is 0.0.

Upvotes: 2

Views: 222

Answers (2)

Juan Carlos Sastre
Juan Carlos Sastre

Reputation: 21

It can be a memory problem.

If you're using notebooks, try stopping these notebooks.

If you're using Docker-Nvidia, just try restarting the container:

nvidia-docker stop <container-name>

And then restart:

nvidia-docker start <container-name>

Upvotes: 1

jabalazs
jabalazs

Reputation: 1264

How exactly did you define sess?

I just ran your code within a tf.Session() context and it worked:

import tensorflow as tf

with tf.Session() as sess:
    a = tf.placeholder(tf.float32)
    b = tf.placeholder(tf.float32)
    adder_node = a + b  

    print(sess.run(adder_node, {a: 3, b: 4.5}))

Output: 7.5

Upvotes: 0

Related Questions