I am trying to make a CNN model that takes variable size input (sentence matrix) and produce a fixed size output for a subsequent fully connected layer (similar to this paper).
I am trying to implement a dynamic kernel size for a max pooling layer so I need the shape of the input at runtime to achieve this.
input = tf.placeholder(tf.float32)
# convolution layer here ....
tf.nn.max_pool(convolution_output, ksize=[1, s, 1, 1],
strides=[1, 1, 1, 1], padding='VALID')
s in ksize=[1, s, 1, 1] should be inferred from the input shape.
However, I can't find a way to do it with Tensorflow.
Anyone knows a way to do it?
I know it's an old thread, but for people who are looking for a solution. It has been implemented in tensorflow 1.4.0
tf.nn.max_pool() now takes 1d tensor as an input as opposed to a list of ints in the older versions. So you can use a placeholder as the argument of ksize.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With