Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable size Convolutional Neural Network Input and Fixed output

Tags:

tensorflow

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?

like image 836
yazfield Avatar asked Jan 23 '26 17:01

yazfield


1 Answers

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.

like image 59
AhlyM Avatar answered Jan 27 '26 00:01

AhlyM