As a preface, I understand how to make None sized tensors and their primary usage.
My hidden layers depend upon the batch_size of the data I am passing in. As such I'm passing in the batch size to a placeholder. Unfortunately, this has caused me a bunch of stress and bugs, as many functions don't work well with None sized shapes. I am looking for a way to use the dynamic shape of a tensor to calculate the number of nodes in my hidden layers.
Currently, I'm receiving the error
InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_2' with dtype int32 [[Node: Placeholder_2 = Placeholderdtype=DT_INT32, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]]
It doesn't like initializing the fill constant with a shape that is unknown at run. I would greatly appreciate help
Below is a snippet of code where the error is isolated.
import tensorflow as tf
x = tf.placeholder(tf.float32, shape=(None, 784))
nodes = tf.div(tf.shape(x)[0],2)
bias = tf.Variable(tf.constant(.1 ,shape = [nodes]), validate_shape = False )
init = tf.initialize_all_variables()
sess = tf.InteractiveSession()
sess.run(init)
I also receive the error:
shape = [int(dim) for dim in shape] TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'
When replacing the fill line with
bias = tf.Variable(tf.constant(.1 ,shape = [nodes]), validate_shape = False )
Thank you in advance.