I am trying to generate a random array of integers in tensorflow 2.0 as below (Please note that I am using Colab):
tf.random.set_seed(123)
var = tf.random.normal(shape=[10, 10], mean=5, stddev=2, dtype=tf.int32, seed=123)
var
This gave me the following error:
NotFoundError: Could not find valid device for node.
Node:{{node RandomStandardNormal}}
All kernels registered for op RandomStandardNormal :
device='XLA_GPU'; T in [DT_INT32, DT_INT64]; dtype in [DT_FLOAT, DT_DOUBLE, DT_BFLOAT16, DT_HALF]
device='XLA_CPU'; T in [DT_INT32, DT_INT64]; dtype in [DT_FLOAT, DT_DOUBLE, DT_BFLOAT16, DT_HALF]
device='XLA_CPU_JIT'; T in [DT_INT32, DT_INT64]; dtype in [DT_FLOAT, DT_DOUBLE, DT_BFLOAT16, DT_HALF]
device='CPU'; dtype in [DT_DOUBLE]
device='CPU'; dtype in [DT_FLOAT]
device='CPU'; dtype in [DT_BFLOAT16]
device='CPU'; dtype in [DT_HALF]
device='XLA_GPU_JIT'; T in [DT_INT32, DT_INT64]; dtype in [DT_FLOAT, DT_DOUBLE, DT_BFLOAT16, DT_HALF]
device='GPU'; T in [DT_INT32]; dtype in [DT_DOUBLE]
device='GPU'; T in [DT_INT32]; dtype in [DT_FLOAT]
device='GPU'; T in [DT_INT32]; dtype in [DT_HALF]
[Op:RandomStandardNormal]
Any help is much appreciated!
you used dtype=tf.int32
in your code which is not supported.
you should use one of these types:
types: DT_FLOAT, DT_DOUBLE, DT_BFLOAT16, DT_HALF
to use: XLA_GPU
types: [DT_DOUBLE],[DT_FLOAT],[DT_BFLOAT16],[DT_HALF]
to use: CPU
types: [DT_DOUBLE],[DT_FLOAT],[DT_HALF]
to use: GPU
update:
it seems like I manage to work it out, you can use numpy array with numpy random, then convert it to tensor:
import tensorflow as tf
import numpy as np
numpy.random.seed(123)
s = np.random.normal(5, 2, 100)
s=np.reshape(s, (-1, 10))
data_tf = tf.convert_to_tensor(s, tf.int32)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With