Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform max pooling on a 1-dimensional ConvNet (conv1d) in TensowFlow?

I'm training a convolutional neural network on text (on the character level) and I want to do max-pooling. tf.nn.max_pool expects a rank 4 Tensor, but 1-d convnets are rank 3 in tensorflow ([batch, width, depth]), so when I pass the output of conv1d to the max pool function, this is the error:

ValueError: Shape (1, 144, 512) must have rank 4

I'm new to tensorflow and deep learning frameworks in general and would like advice on the best practice here, because I can imagine there are multiple workarounds. How can I perform max-pooling in the 1-d case?

Thanks.

like image 889
ibairdo Avatar asked Oct 04 '16 03:10

ibairdo


People also ask

What is Max pooling in Tensorflow?

Max pooling operation for 2D spatial data. Downsamples the input along its spatial dimensions (height and width) by taking the maximum value over an input window (of size defined by pool_size ) for each channel of the input. The window is shifted by strides along each dimension.

What does Max pooling 1D do?

The 1D Global max pooling block takes a 2-dimensional tensor tensor of size (input size) x (input channels) and computes the maximum of all the (input size) values for each of the (input channels).

How does Max pooling change dimensions?

Max pooling is a type of operation that is typically added to CNNs following individual convolutional layers. When added to a model, max pooling reduces the dimensionality of images by reducing the number of pixels in the output from the previous convolutional layer.


1 Answers

A quick way would be to add an extra singleton dimension i.e. make the shape (1, 1, 144, 512), from there you can reduce it back with tf.squeeze.

I'm curious about other approaches though.

like image 114
Steven Avatar answered Sep 23 '22 21:09

Steven