Example #1
0
    def testCreatePooling2DWithStrides(self):
        height, width = 6, 8
        # Test strides tuple
        images = tf.random.uniform((5, height, width, 3), seed=1)
        layer = pooling_layers.MaxPooling2D(
            [2, 2], strides=(2, 2), padding="same"
        )
        output = layer(images)
        self.assertListEqual(
            output.get_shape().as_list(), [5, height / 2, width / 2, 3]
        )

        # Test strides integer
        layer = pooling_layers.MaxPooling2D([2, 2], strides=2, padding="same")
        output = layer(images)
        self.assertListEqual(
            output.get_shape().as_list(), [5, height / 2, width / 2, 3]
        )

        # Test unequal strides
        layer = pooling_layers.MaxPooling2D(
            [2, 2], strides=(2, 1), padding="same"
        )
        output = layer(images)
        self.assertListEqual(
            output.get_shape().as_list(), [5, height / 2, width, 3]
        )
Example #2
0
 def testMaxPooling2DPaddingSame(self):
   height, width = 7, 9
   images = tf.random.uniform((5, height, width, 4), seed=1)
   layer = pooling_layers.MaxPooling2D(
       images.get_shape()[1:3], strides=2, padding='same')
   output = layer(images)
   self.assertListEqual(output.get_shape().as_list(), [5, 4, 5, 4])
Example #3
0
 def testCreateMaxPooling2DChannelsFirst(self):
     height, width = 7, 9
     images = tf.random.uniform((5, 2, height, width))
     layer = pooling_layers.MaxPooling2D([2, 2],
                                         strides=1,
                                         data_format="channels_first")
     output = layer(images)
     self.assertListEqual(output.get_shape().as_list(), [5, 2, 6, 8])
Example #4
0
 def testCreateMaxPooling2D(self):
     height, width = 7, 9
     images = tf.random.uniform((5, height, width, 4))
     layer = pooling_layers.MaxPooling2D([2, 2], strides=2)
     output = layer(images)
     self.assertListEqual(output.get_shape().as_list(), [5, 3, 4, 4])