fix bug in maxout function#20455
Conversation
The line "shape[axis] = -1" will make the shape wrong when dealing with batches with arbitrary sizes.
|
@martinwicke can I merge this? |
|
Check with @yifeif but I think yes. |
|
You are good if it's for non-master branches. |
|
MacOS flake. Re-running. |
| 'a multiple of num_units({})'.format( | ||
| num_channels, num_units)) | ||
| shape[axis] = -1 | ||
| shape[axis] = num_units |
There was a problem hiding this comment.
Can we add a test case with None value for an axis?
There was a problem hiding this comment.
Like this? I am not sure.
input_tensor = tf.placeholder(tf.float32, [None, 32, 32, 3], name="input_data")
with tf.variable_scope('conv_layer'):
conv_out = tf.layers.conv2d(input_tensor, 10, (5,5), padding='same', name="conv")
maxout_out = tf.contrib.layers.maxout(conv_out, 5, axis=3)
#... some test code.
self.assertEqual(maxout_out.get_shape().as_list()[3], 5, "shape in maxout function failed")There was a problem hiding this comment.
Yes, basically a test case that would have otherwise failed without this change.
There was a problem hiding this comment.
import numpy as np
import tensorflow as tf
# Suppose this function belongs to some test class
def testMaxoutShape(self):
data = np.random.randn(64, 32, 32, 3).astype(np.float32)
input_tensor = tf.placeholder(tf.float32, [None, 32, 32, 3], name="input_data")
conv_out = tf.layers.conv2d(input_tensor, 10, (5,5), padding='same', name="conv")
maxout_out = tf.contrib.layers.maxout(conv_out, 5, axis=3)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
value = sess.run(maxout_out, feed_dict={input_tensor: data})
self.assertEqual(value.shape[3], 5, "shape in maxout function failed")There was a problem hiding this comment.
Would you like to make the change to the test file? https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/layers/python/layers/layers_test.py#L4172
|
Going to merge this fix into 1.9 so we can start official release builds. Please follow-up with @pavithrasv comment and add a test case with None please though. Thanks! |
The line "shape[axis] = -1" will make the shape wrong when dealing with batches with arbitrary sizes.
if the shape of input tensor is [None, ... , num_channels, ... ], "shape[axis]=-1" together with "shape+=[num_channels // num_units]" will make the shape become [None, ... , -1, ... , num_channels // num_units]. But when reshape the input tensor, the "None" element in shape will make "-1" become "None", not "num_units".