Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max_pool with dynamic ksize #9394

Closed
FilipeAleixo opened this issue Apr 23, 2017 · 5 comments
Closed

Max_pool with dynamic ksize #9394

FilipeAleixo opened this issue Apr 23, 2017 · 5 comments
Labels
stat:contribution welcome Status - Contributions welcome type:feature Feature requests

Comments

@FilipeAleixo
Copy link

FilipeAleixo commented Apr 23, 2017

I have the following code for a convolutional layer. This layer is part a larger computational graph.

# Define the shape of the filter
filter_shape = [1,
                config.char_filter_size,
                config.dim_char,
                config.dim_char]

# Define the convolutional layer weights and biases
W_conv = tf.Variable(tf.truncated_normal(filter_shape, stddev=0.1),
                     name="W_conv")
b_conv = tf.Variable(tf.constant(0.1, shape=[config.dim_char]),
                     name="b_conv")
# Do 2d convolution
conv = tf.nn.conv2d(char_embeddings,
                    W_conv,
                    strides=[1, 1, 1, 1],
                    padding="VALID",
                    name="conv")
# Apply nonlinearity
# h_conv has the same shape as conv
h_conv = tf.nn.relu(tf.nn.bias_add(conv, b_conv),
                    name="conv_relu")
# Maxpooling h_conv over dim 2 (char dim)

# ERROR HERE
conv_pooled = tf.nn.max_pool(h_conv,
                             ksize=[1, 1, tf.shape(h_conv)[-2], 1],
                             strides=[1, 1, 1, 1],
                             padding='VALID',
                             name="conv_max_pool")

When trying to run, I get the error:

TypeError: Expected int for argument 'ksize' not tf.Tensor shape=() dtype=int32.

is tf.nn.max_pool unable to handle dynamic ksize?

@girving
Copy link
Contributor

girving commented Apr 24, 2017

This looks like it should work via Derek's auto-stack machinery. I'll briefly try to reproduce...

@girving
Copy link
Contributor

girving commented Apr 24, 2017

Ah, correct: tf.nn.max_pool does not support dynamic size. ksize is an attr, therefore must be a constant. This would be reasonable to fix, but would require a MaxPoolV2 op kernel similar to TopKV2. I'll leave it open as contributions welcome.

@girving girving added stat:contribution welcome Status - Contributions welcome type:feature Feature requests labels Apr 24, 2017
@girving
Copy link
Contributor

girving commented Apr 24, 2017

Duplicate of #4746.

@girving girving closed this as completed Apr 24, 2017
@nkszjx
Copy link

nkszjx commented Apr 8, 2019

tf.reduce_max(activation, axis=1, keep_dims=True)

@nkszjx
Copy link

nkszjx commented Apr 8, 2019

see https://stackoverflow.com/questions/46760927/using-the-shape-of-a-tensor-with-dynamic-shape-in-tensorflow-operations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:contribution welcome Status - Contributions welcome type:feature Feature requests
Projects
None yet
Development

No branches or pull requests

3 participants