Unable to convert partially transformed tensor to TensorFlow

There are many methods in TensorFlow that require specifying a form, for example truncated_normal:

tf.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None) 

I have a place to enter the form [None, 784], where the first dimension is None, because the batch size can vary. I could use a fixed batch size, but it will still be different from the set test / check size.

I cannot pass this placeholder to tf.truncated_normal because it requires a fully defined tensor form. What is an easy way to use tf.truncated_normal different tensor forms?

+8
python tensorflow
source share
1 answer

You just need to submit it as one example, but in form. Thus, this means adding extra size to the form, for example.

 batch_size = 32 # set this to the actual size of your batch tf.truncated_normal((batch_size, 784), mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None) 

Thus, it "fits" in the placeholder.

If you expect batch_size to change, you can also use:

 tf.truncated_normal(tf.shape(input_tensor), mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None) 

If input_tensor can be a placeholder or just some kind of tensor this noise will be added.

+12
source share

All Articles