Пример #1
0
    def testSeparableConv2DSameWithInputOddSize(self):
        n, n2 = 5, 3

        # Input image.
        x = create_test_input(1, n, n, 1)

        # Convolution kernel.
        dw = create_test_input(1, 3, 3, 1)
        dw = tf.reshape(dw, [3, 3, 1, 1])

        tf.get_variable('Conv/depthwise_weights', initializer=dw)
        tf.get_variable('Conv/pointwise_weights',
                        initializer=tf.ones([1, 1, 1, 1]))
        tf.get_variable('Conv/biases', initializer=tf.zeros([1]))
        tf.get_variable_scope().reuse_variables()

        y1 = slim.separable_conv2d(x,
                                   1, [3, 3],
                                   depth_multiplier=1,
                                   stride=1,
                                   scope='Conv')
        y1_expected = tf.to_float([[14, 28, 43, 58, 34], [28, 48, 66, 84, 46],
                                   [43, 66, 84, 102,
                                    55], [58, 84, 102, 120, 64],
                                   [34, 46, 55, 64, 30]])
        y1_expected = tf.reshape(y1_expected, [1, n, n, 1])

        y2 = resnet_utils.subsample(y1, 2)
        y2_expected = tf.to_float([[14, 43, 34], [43, 84, 55], [34, 55, 30]])
        y2_expected = tf.reshape(y2_expected, [1, n2, n2, 1])

        y3 = xception.separable_conv2d_same(x,
                                            1,
                                            3,
                                            depth_multiplier=1,
                                            regularize_depthwise=True,
                                            stride=2,
                                            scope='Conv')
        y3_expected = y2_expected

        y4 = slim.separable_conv2d(x,
                                   1, [3, 3],
                                   depth_multiplier=1,
                                   stride=2,
                                   scope='Conv')
        y4_expected = y2_expected

        with self.test_session() as sess:
            sess.run(tf.global_variables_initializer())
            self.assertAllClose(y1.eval(), y1_expected.eval())
            self.assertAllClose(y2.eval(), y2_expected.eval())
            self.assertAllClose(y3.eval(), y3_expected.eval())
            self.assertAllClose(y4.eval(), y4_expected.eval())
Пример #2
0
  def testSeparableConv2DSameWithInputOddSize(self):
    n, n2 = 5, 3

    # Input image.
    x = create_test_input(1, n, n, 1)

    # Convolution kernel.
    dw = create_test_input(1, 3, 3, 1)
    dw = tf.reshape(dw, [3, 3, 1, 1])

    tf.get_variable('Conv/depthwise_weights', initializer=dw)
    tf.get_variable('Conv/pointwise_weights',
                    initializer=tf.ones([1, 1, 1, 1]))
    tf.get_variable('Conv/biases', initializer=tf.zeros([1]))
    tf.get_variable_scope().reuse_variables()

    y1 = slim.separable_conv2d(x, 1, [3, 3], depth_multiplier=1,
                               stride=1, scope='Conv')
    y1_expected = tf.to_float([[14, 28, 43, 58, 34],
                               [28, 48, 66, 84, 46],
                               [43, 66, 84, 102, 55],
                               [58, 84, 102, 120, 64],
                               [34, 46, 55, 64, 30]])
    y1_expected = tf.reshape(y1_expected, [1, n, n, 1])

    y2 = resnet_utils.subsample(y1, 2)
    y2_expected = tf.to_float([[14, 43, 34],
                               [43, 84, 55],
                               [34, 55, 30]])
    y2_expected = tf.reshape(y2_expected, [1, n2, n2, 1])

    y3 = xception.separable_conv2d_same(x, 1, 3, depth_multiplier=1,
                                        regularize_depthwise=True,
                                        stride=2, scope='Conv')
    y3_expected = y2_expected

    y4 = slim.separable_conv2d(x, 1, [3, 3], depth_multiplier=1,
                               stride=2, scope='Conv')
    y4_expected = y2_expected

    with self.test_session() as sess:
      sess.run(tf.global_variables_initializer())
      self.assertAllClose(y1.eval(), y1_expected.eval())
      self.assertAllClose(y2.eval(), y2_expected.eval())
      self.assertAllClose(y3.eval(), y3_expected.eval())
      self.assertAllClose(y4.eval(), y4_expected.eval())