Exemple #1
0
    def testConv(self):
        if 'GPU' in self.device:
            # TODO(b/32333178)
            self.skipTest(
                'Current implementation of RandomStandardNormal kernel '
                'is very slow on GPU, and has been blacklisted.')
        with self.test_scope():
            data_format = 'channels_last'
            conv = convolutional.Conv2D(
                filters=1,
                kernel_size=2,
                padding='VALID',
                data_format=data_format,
                activation=nn_ops.relu,
                kernel_initializer=init_ops.ones_initializer(),
                bias_initializer=init_ops.zeros_initializer())
            pool = pooling.MaxPooling2D(2, 2, data_format=data_format)

            def model(x):
                x = conv(x)
                return pool(x)

            model = function.defun(model)

            x = array_ops.ones([1, 4, 4, 1])
            y = model(x)
            self.assertAllEqual(y.numpy(), [[[[4.]]]])
Exemple #2
0
 def testMaxPooling2DPaddingSame(self):
   height, width = 7, 9
   images = random_ops.random_uniform((5, height, width, 4), seed=1)
   layer = pooling_layers.MaxPooling2D(
       images.get_shape()[1:3], strides=2, padding='same')
   output = layer.apply(images)
   self.assertListEqual(output.get_shape().as_list(), [5, 4, 5, 4])
Exemple #3
0
 def testCreateMaxPooling2DChannelsFirst(self):
     height, width = 7, 9
     images = random_ops.random_uniform((5, 2, height, width))
     layer = pooling_layers.MaxPooling2D([2, 2],
                                         strides=1,
                                         data_format='channels_first')
     output = layer.apply(images)
     self.assertListEqual(output.get_shape().as_list(), [5, 2, 6, 8])
Exemple #4
0
  def testCreatePooling2DWithStrides(self):
    height, width = 6, 8
    # Test strides tuple
    images = random_ops.random_uniform((5, height, width, 3), seed=1)
    layer = pooling_layers.MaxPooling2D([2, 2], strides=(2, 2), padding='same')
    output = layer.apply(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.apply(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.apply(images)
    self.assertListEqual(output.get_shape().as_list(),
                         [5, height / 2, width, 3])
Exemple #5
0
 def testCreateMaxPooling2D(self):
     height, width = 7, 9
     images = random_ops.random_uniform((5, height, width, 4))
     layer = pooling_layers.MaxPooling2D([2, 2], strides=2)
     output = layer.apply(images)
     self.assertListEqual(output.get_shape().as_list(), [5, 3, 4, 4])