Exemplo n.º 1
0
    def testCreateSeparableConvWithStridesChannelsFirst(self):
        data_format = 'channels_first'
        height, width = 6, 8
        # Test strides tuple
        images = random_ops.random_uniform((5, 3, height, width), seed=1)
        layer = conv_layers.SeparableConv2D(32, [3, 3],
                                            strides=(2, 2),
                                            padding='same',
                                            data_format=data_format)
        output = layer.apply(images)
        self.assertListEqual(output.get_shape().as_list(),
                             [5, 32, height / 2, width / 2])

        # Test strides integer
        layer = conv_layers.SeparableConv2D(32, [3, 3],
                                            strides=2,
                                            padding='same',
                                            data_format=data_format)
        output = layer.apply(images)
        self.assertListEqual(output.get_shape().as_list(),
                             [5, 32, height / 2, width / 2])

        # Test unequal strides
        layer = conv_layers.SeparableConv2D(32, [3, 3],
                                            strides=(2, 1),
                                            padding='same',
                                            data_format=data_format)
        output = layer.apply(images)
        self.assertListEqual(output.get_shape().as_list(),
                             [5, 32, height / 2, width])
Exemplo n.º 2
0
    def testCreateSeparableConvWithStrides(self):
        height, width = 6, 8
        # Test strides tuple
        images = random_ops.random_uniform((5, height, width, 3), seed=1)
        layer = conv_layers.SeparableConv2D(32, [3, 3],
                                            strides=(2, 2),
                                            padding='same')
        output = layer.apply(images)
        self.assertListEqual(output.get_shape().as_list(),
                             [5, height / 2, width / 2, 32])

        # Test strides integer
        layer = conv_layers.SeparableConv2D(32, [3, 3],
                                            strides=2,
                                            padding='same')
        output = layer.apply(images)
        self.assertListEqual(output.get_shape().as_list(),
                             [5, height / 2, width / 2, 32])

        # Test unequal strides
        layer = conv_layers.SeparableConv2D(32, [3, 3],
                                            strides=(2, 1),
                                            padding='same')
        output = layer.apply(images)
        self.assertListEqual(output.get_shape().as_list(),
                             [5, height / 2, width, 32])
Exemplo n.º 3
0
 def testSeparableConv2DPaddingSame(self):
   height, width = 7, 9
   images = random_ops.random_uniform((5, height, width, 32), seed=1)
   layer = conv_layers.SeparableConv2D(
       64, images.get_shape()[1:3], padding='same')
   output = layer.apply(images)
   self.assertListEqual(output.get_shape().as_list(), [5, height, width, 64])
Exemplo n.º 4
0
 def testSeparableConv2DBiasRegularizer(self):
     height, width = 7, 9
     images = random_ops.random_uniform((5, height, width, 4))
     reg = lambda x: 0.1 * math_ops.reduce_sum(x)
     layer = conv_layers.SeparableConv2D(32, [3, 3], bias_regularizer=reg)
     layer.apply(images)
     loss_keys = ops.get_collection(ops.GraphKeys.REGULARIZATION_LOSSES)
     self.assertEqual(len(loss_keys), 1)
     self.assertListEqual(layer.losses, loss_keys)
Exemplo n.º 5
0
 def testCreateSeparableConv2DIntegerKernelSize(self):
     height, width = 7, 9
     images = random_ops.random_uniform((5, height, width, 4))
     layer = conv_layers.SeparableConv2D(32, 3)
     output = layer.apply(images)
     self.assertListEqual(output.get_shape().as_list(),
                          [5, height - 2, width - 2, 32])
     self.assertListEqual(layer.depthwise_kernel.get_shape().as_list(),
                          [3, 3, 4, 1])
     self.assertListEqual(layer.pointwise_kernel.get_shape().as_list(),
                          [1, 1, 4, 32])
     self.assertListEqual(layer.bias.get_shape().as_list(), [32])
Exemplo n.º 6
0
 def testCreateSeparableConv2DChannelsFirst(self):
     height, width = 7, 9
     images = random_ops.random_uniform((5, 4, height, width))
     layer = conv_layers.SeparableConv2D(32, [3, 3],
                                         data_format='channels_first')
     output = layer.apply(images)
     self.assertListEqual(output.get_shape().as_list(),
                          [5, 32, height - 2, width - 2])
     self.assertListEqual(layer.depthwise_kernel.get_shape().as_list(),
                          [3, 3, 4, 1])
     self.assertListEqual(layer.pointwise_kernel.get_shape().as_list(),
                          [1, 1, 4, 32])
     self.assertListEqual(layer.bias.get_shape().as_list(), [32])
Exemplo n.º 7
0
 def testCreateSeparableConv2D(self):
     height, width = 7, 9
     images = random_ops.random_uniform((5, height, width, 4))
     layer = conv_layers.SeparableConv2D(32, [3, 3], activation=nn_ops.relu)
     output = layer.apply(images)
     self.assertEqual(output.op.name, 'separable_conv2d/Relu')
     self.assertListEqual(output.get_shape().as_list(),
                          [5, height - 2, width - 2, 32])
     self.assertListEqual(layer.depthwise_kernel.get_shape().as_list(),
                          [3, 3, 4, 1])
     self.assertListEqual(layer.pointwise_kernel.get_shape().as_list(),
                          [1, 1, 4, 32])
     self.assertListEqual(layer.bias.get_shape().as_list(), [32])
Exemplo n.º 8
0
 def testConstraints(self):
   d_constraint = lambda x: x / math_ops.reduce_sum(x)
   p_constraint = lambda x: x / math_ops.reduce_sum(x)
   b_constraint = lambda x: x / math_ops.reduce_max(x)
   layer = conv_layers.SeparableConv2D(2, 3,
                                       depthwise_constraint=d_constraint,
                                       pointwise_constraint=p_constraint,
                                       bias_constraint=b_constraint)
   inputs = random_ops.random_uniform((5, 3, 3, 5), seed=1)
   layer(inputs)
   self.assertEqual(layer.depthwise_constraint, d_constraint)
   self.assertEqual(layer.pointwise_constraint, p_constraint)
   self.assertEqual(layer.bias_constraint, b_constraint)