Reputation: 1283
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?
Upvotes: 3
Views: 4790
Reputation: 520
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.
Upvotes: 4
Reputation: 1283
I didn't find a way to do it in Tensorflow and had to reimplement my model in theano and use a different solution: Dynamic KMax Pooling.
Upvotes: 2