3

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?

3
  • This sounds similar to what they do here: (arxiv.org/abs/1412.6071). But unfortunately this is not supported directly by tensorflow yet (github.com/tensorflow/tensorflow/issues/2953). Once added, what you want to do could be just an extension. Commented Jul 28, 2016 at 13:27
  • 1
    Maybe tf.reduce_max could work in this case? Not sure if this will for the paper you are implementing, but at least it works for simple CNN with variable input size. Commented Oct 12, 2016 at 13:23
  • tf.reduce_max made the job for what I wanted to do. I wanted to pool depending of the size of the batch size. (Not for every sentences though) Thanks! Commented Jun 8, 2017 at 2:35

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.