andre_bauer
andre_bauer

Reputation: 850

Tensorflow generate random values unexpected behaviour

I want to generate a random Vector and don't understand tensorflows results....

Code:

import tensorflow as tf

some_test = tf.Variable(
    tf.random_uniform([20], -1.0, 1.0, dtype=tf.float32))
init_op = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init_op)
random = sess.run(some_test)
print(random)

gives me this:

[             nan              nan              nan              nan
              nan              nan              nan              nan
              nan   3.57331108e-43   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00  -3.05175781e-05
  -1.70141183e+38  -1.70141183e+38  -1.70141183e+38  -1.70141183e+38]

Upvotes: 2

Views: 142

Answers (1)

andre_bauer
andre_bauer

Reputation: 850

Okay this is very confusing but the reason it did not work was that I was running some other Tensorflow Code in parallel. After I stopped this code the random generation works as expected. I doubt this is expected behaviour though.

If I use with tf.device('/cpu:0'): it works on my machine even if other code is running. Using gpu:0 gives the strange numbers, when tensorflow uses the GPU.

Also I tried to reproduce this on different machines and I couldn't. This means even with other tensorflow code running (same code, all on GPU etc..) selecting devices everything worked fine.

Upvotes: 2

Related Questions