aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2016-07-28 12:52:23 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-07-28 14:02:53 -0700
commit29dca4894af25ef0153b5e4168c3a7b646495629 (patch)
tree8da576348dd1ed26e016a8ec39f7387053072ee5
parent991a0192bd16c539e39f4f3b054768ad0c849e6e (diff)
Updating comments and simplifying tests for avg_pool2d and max_pool2d.
Change: 128737225
-rw-r--r--tensorflow/contrib/layers/python/layers/layers.py41
-rw-r--r--tensorflow/contrib/layers/python/layers/layers_test.py134
2 files changed, 80 insertions, 95 deletions
diff --git a/tensorflow/contrib/layers/python/layers/layers.py b/tensorflow/contrib/layers/python/layers/layers.py
index e4a25fa113..53e42c0313 100644
--- a/tensorflow/contrib/layers/python/layers/layers.py
+++ b/tensorflow/contrib/layers/python/layers/layers.py
@@ -75,25 +75,24 @@ def avg_pool2d(inputs,
padding='VALID',
outputs_collections=None,
scope=None):
- """Adds a Avg Pooling op.
+ """Adds a 2D average pooling op.
- It is assumed by the wrapper that the pooling is only done per image and not
- in depth or batch.
+ It is assumed that the pooling is done per image but not in batch or channels.
Args:
- inputs: a tensor of size [batch_size, height, width, depth].
- kernel_size: a list of length 2: [kernel_height, kernel_width] of the
+ inputs: A `Tensor` of size [batch_size, height, width, channels].
+ kernel_size: A list of length 2: [kernel_height, kernel_width] of the
pooling kernel over which the op is computed. Can be an int if both
values are the same.
- stride: a list of length 2: [stride_height, stride_width].
- Can be an int if both strides are the same. Note that presently
+ stride: A list of length 2: [stride_height, stride_width].
+ Can be an int if both strides are the same. Note that presently
both strides must have the same value.
- padding: the padding method, either 'VALID' or 'SAME'.
- outputs_collections: collection to add the outputs.
+ padding: The padding method, either 'VALID' or 'SAME'.
+ outputs_collections: The collections to which the outputs are added.
scope: Optional scope for op_scope.
Returns:
- a tensor representing the results of the pooling operation.
+ A `Tensor` representing the results of the pooling operation.
"""
with ops.op_scope([inputs], scope, 'AvgPool2D') as sc:
inputs = ops.convert_to_tensor(inputs)
@@ -843,27 +842,27 @@ def max_pool2d(inputs,
padding='VALID',
outputs_collections=None,
scope=None):
- """Adds a Max Pooling op.
+ """Adds a 2D Max Pooling op.
- It is assumed by the wrapper that the pooling is only done per image and not
- in depth or batch.
+ It is assumed that the pooling is done per image but not in batch or channels.
Args:
- inputs: a tensor of size [batch_size, height, width, depth].
- kernel_size: a list of length 2: [kernel_height, kernel_width] of the
+ inputs: A `Tensor` of size [batch_size, height, width, channels].
+ kernel_size: A list of length 2: [kernel_height, kernel_width] of the
pooling kernel over which the op is computed. Can be an int if both
values are the same.
- stride: a list of length 2: [stride_height, stride_width].
- Can be an int if both strides are the same. Note that presently
+ stride: A list of length 2: [stride_height, stride_width].
+ Can be an int if both strides are the same. Note that presently
both strides must have the same value.
- padding: the padding method, either 'VALID' or 'SAME'.
- outputs_collections: collection to add the outputs.
+ padding: The padding method, either 'VALID' or 'SAME'.
+ outputs_collections: The collections to which the outputs are added.
scope: Optional scope for op_scope.
Returns:
- a tensor representing the results of the pooling operation.
+ A `Tensor` representing the results of the pooling operation.
+
Raises:
- ValueError: if 'kernel_size' is not a 2-D list
+ ValueError: If 'kernel_size' is not a 2-D list
"""
with ops.op_scope([inputs], scope, 'MaxPool2D') as sc:
inputs = ops.convert_to_tensor(inputs)
diff --git a/tensorflow/contrib/layers/python/layers/layers_test.py b/tensorflow/contrib/layers/python/layers/layers_test.py
index dc962ac76e..02d38220de 100644
--- a/tensorflow/contrib/layers/python/layers/layers_test.py
+++ b/tensorflow/contrib/layers/python/layers/layers_test.py
@@ -30,59 +30,52 @@ class AvgPool2DTest(tf.test.TestCase):
def testCreateAvgPool(self):
height, width = 3, 3
- with self.test_session():
- images = np.random.uniform(size=(5, height, width, 3))
- output = tf.contrib.layers.avg_pool2d(images, [3, 3])
- self.assertEquals(output.op.name, 'AvgPool2D/AvgPool')
- self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
+ images = np.random.uniform(size=(5, height, width, 3))
+ output = tf.contrib.layers.avg_pool2d(images, [3, 3])
+ self.assertEquals(output.op.name, 'AvgPool2D/AvgPool')
+ self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
def testCollectOutputs(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.avg_pool2d(images, [3, 3],
- outputs_collections='outputs')
- c_output = tf.get_collection('outputs')[0]
- self.assertEquals(c_output.name, 'AvgPool2D')
- self.assertEquals(c_output.outputs, output)
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.avg_pool2d(images, [3, 3],
+ outputs_collections='outputs')
+ output_collection = tf.get_collection('outputs')[0]
+ self.assertEquals(output_collection.name, 'AvgPool2D')
+ self.assertEquals(output_collection.outputs, output)
def testCreateSquareAvgPool(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.avg_pool2d(images, 3)
- self.assertEquals(output.op.name, 'AvgPool2D/AvgPool')
- self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.avg_pool2d(images, 3)
+ self.assertEquals(output.op.name, 'AvgPool2D/AvgPool')
+ self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
def testCreateAvgPoolWithScope(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.avg_pool2d(images, [3, 3], scope='pool1')
- self.assertEquals(output.op.name, 'pool1/AvgPool')
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.avg_pool2d(images, [3, 3], scope='pool1')
+ self.assertEquals(output.op.name, 'pool1/AvgPool')
- def testCreateAvgPoolSAME(self):
+ def testCreateAvgPoolWithSamePadding(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.avg_pool2d(images, [3, 3], padding='SAME')
- self.assertListEqual(output.get_shape().as_list(), [5, 2, 2, 3])
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.avg_pool2d(images, [3, 3], padding='SAME')
+ self.assertListEqual(output.get_shape().as_list(), [5, 2, 2, 3])
- def testCreateAvgPoolStrideSAME(self):
+ def testCreateAvgPoolStrideWithSamePadding(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.avg_pool2d(images, [3, 3], stride=1,
- padding='SAME')
- self.assertListEqual(output.get_shape().as_list(), [5, height, width, 3])
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.avg_pool2d(images, [3, 3], stride=1,
+ padding='SAME')
+ self.assertListEqual(output.get_shape().as_list(), [5, height, width, 3])
def testGlobalAvgPool(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.avg_pool2d(images, images.get_shape()[1:3],
- stride=1)
- self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.avg_pool2d(images, images.get_shape()[1:3],
+ stride=1)
+ self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
class BiasAddTest(tf.test.TestCase):
@@ -1502,59 +1495,52 @@ class MaxPool2DTest(tf.test.TestCase):
def testCreateMaxPool(self):
height, width = 3, 3
- with self.test_session():
- images = np.random.uniform(size=(5, height, width, 3)).astype(np.float32)
- output = tf.contrib.layers.max_pool2d(images, [3, 3])
- self.assertEquals(output.op.name, 'MaxPool2D/MaxPool')
- self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
+ images = np.random.uniform(size=(5, height, width, 3)).astype(np.float32)
+ output = tf.contrib.layers.max_pool2d(images, [3, 3])
+ self.assertEquals(output.op.name, 'MaxPool2D/MaxPool')
+ self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
def testCollectOutputs(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.max_pool2d(images, [3, 3],
- outputs_collections='outputs')
- c_output = tf.get_collection('outputs')[0]
- self.assertEquals(c_output.name, 'MaxPool2D')
- self.assertEquals(c_output.outputs, output)
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.max_pool2d(images, [3, 3],
+ outputs_collections='outputs')
+ outputs_collection = tf.get_collection('outputs')[0]
+ self.assertEquals(outputs_collection.name, 'MaxPool2D')
+ self.assertEquals(outputs_collection.outputs, output)
def testCreateSquareMaxPool(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.max_pool2d(images, 3)
- self.assertEquals(output.op.name, 'MaxPool2D/MaxPool')
- self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.max_pool2d(images, 3)
+ self.assertEquals(output.op.name, 'MaxPool2D/MaxPool')
+ self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
def testCreateMaxPoolWithScope(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.max_pool2d(images, [3, 3], scope='pool1')
- self.assertEquals(output.op.name, 'pool1/MaxPool')
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.max_pool2d(images, [3, 3], scope='pool1')
+ self.assertEquals(output.op.name, 'pool1/MaxPool')
- def testCreateMaxPoolSAME(self):
+ def testCreateMaxPoolWithSamePadding(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.max_pool2d(images, [3, 3], padding='SAME')
- self.assertListEqual(output.get_shape().as_list(), [5, 2, 2, 3])
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.max_pool2d(images, [3, 3], padding='SAME')
+ self.assertListEqual(output.get_shape().as_list(), [5, 2, 2, 3])
- def testCreateMaxPoolStrideSAME(self):
+ def testCreateMaxPoolStrideWithSamePadding(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.max_pool2d(images, [3, 3], stride=1,
- padding='SAME')
- self.assertListEqual(output.get_shape().as_list(), [5, height, width, 3])
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.max_pool2d(images, [3, 3], stride=1,
+ padding='SAME')
+ self.assertListEqual(output.get_shape().as_list(), [5, height, width, 3])
def testGlobalMaxPool(self):
height, width = 3, 3
- with self.test_session():
- images = tf.random_uniform((5, height, width, 3), seed=1)
- output = tf.contrib.layers.max_pool2d(images, images.get_shape()[1:3],
- stride=1)
- self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
+ images = tf.random_uniform((5, height, width, 3), seed=1)
+ output = tf.contrib.layers.max_pool2d(images, images.get_shape()[1:3],
+ stride=1)
+ self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 3])
class OneHotEncodingTest(tf.test.TestCase):