python - How do I pass a scalar via a TensorFlow feed dictionary -
my tensorflow model uses tf.random_uniform initialize variable. specify range when begin training, created placeholder initialization value.
init = tf.placeholder(tf.float32, name="init") v = tf.variable(tf.random_uniform((100, 300), -init, init), dtype=tf.float32) initialize = tf.initialize_all_variables() i initialize variables @ start of training so.
session.run(initialize, feed_dict={init: 0.5}) this gives me following error:
valueerror: initial_value must have shape specified: tensor("embedding/random_uniform:0", dtype=float32) i cannot figure out correct shape parameter pass tf.placeholder. think scalar should init = tf.placeholder(tf.float32, shape=0, name="init") gives following error:
valueerror: incompatible shapes broadcasting: (100, 300) , (0,) if replace init literal value 0.5 in call tf.random_uniform works.
how pass scalar initial value via feed dictionary?
tl;dr: define init scalar shape follows:
init = tf.placeholder(tf.float32, shape=(), name="init") this looks unfortunate implementation detail of tf.random_uniform(): uses tf.add() , tf.multiply() rescale random value [-1, +1] [minval, maxval], if shape of minval or maxval unknown, tf.add() , tf.multiply() can't infer proper shapes, because there might broadcasting involved.
by defining init known shape (where scalar () or [], not 0), tensorflow can draw proper inferences shape of result of tf.random_uniform(), , program should work intended.
Comments
Post a Comment