Reputation: 1565
I am having hard time due to dynamic and static shapes in tf.
I have
shape=tf.shape(net)
s1=tf.cast(shape[2],tf.int32)
s2=tf.cast(shape[2]/2,tf.int32)
a0=tf.random_normal([s1,s2],mean=0.,stdev=1.)
b0 = tf.get_variable(some_name, initializer=a0)
I get the error:
ValueError: initial_value must have a shape specified:
for line b0=... .Then, I added the shape information:
b0 = tf.get_variable(some_name, initializer=a0,shape=[s1,s2])
Now I get the error:
If initializer is a constant, do not specify shape.
I realized, it has probably something to do with it being dynamic shape. So, I went back and changed to
shape = net.get_shape().as_list()
Now, I get the error:
ValueError: None values not supported.
in line corresponding to assignment of cast to s1.
I feel like I am running around in circles. How does one solve this?
I have gone through: How to understand static shape and dynamic shape in TensorFlow?
Upvotes: 1
Views: 941
Reputation: 24581
You need to specify validate_shape=False
in the argument of tf.get_variable
, e.g
init = tf.random_normal((s1, s2))
tf.get_variable(name, initializer=init, validate_shape=False)
Upvotes: 1