You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are several use cases where the shape of random numbers is to be determined at runtime. E.g. for variational auto encoder or injection of noise into an MLPs units. As of now, this seems not possible in an elegant way with tensorflow:
import tensorflow as tf
x = tf.placeholder('float32', [None, 784])
noised = x + tf.random_normal(x.get_shape())
The above throws this traceback. I have to replace None above with a number known before runtime. But then I have to fix my batch size beforehand (to which the None corresponds) and need different expressions for each batch size.
Sorry but this doesn't seem to be working with TF2, as placeholders don't exist anymore.
Using None to specify the shape doesn't work either, i.e, tf.random.normal((None, 784))
gives
ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.
Any idea, apart from using tf.shape() on another tensor of the model to extract the batchsize ?
Reacted by coleridge, Hermann Stolte, JJKK1313, Gabriel, ShudaoWei and thomaskleiven
Activity
rafaljozefowicz commentedon Nov 28, 2015
TF.shape(x) should work instead.
bayerj commentedon Nov 29, 2015
Thank you!
guerrillacaptain commentedon Nov 29, 2017
like
idofr commentedon May 14, 2019
Uh! that's actually really helpful :) thanks. Why is that?
Merge pull request tensorflow#373 from ROCmSoftwarePlatform/fix_370
Merge pull request tensorflow#373 from ROCmSoftwarePlatform/fix_370
BBillot commentedon Dec 14, 2020
Sorry but this doesn't seem to be working with TF2, as placeholders don't exist anymore.
Using None to specify the shape doesn't work either, i.e,
tf.random.normal((None, 784))gives
ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.
Any idea, apart from using tf.shape() on another tensor of the model to extract the batchsize ?
JJKK1313 commentedon Aug 8, 2021
Also having the same problem,
tf.shape() returns some wierd number for placeholder's shape.
gives me:
Update XNNPACK in XLA