Exemplo n.º 1
0
    def test_pooling_late_shape_init(self):
        network = layers.join(
            layers.AveragePooling((2, 2)),
            layers.Softmax(),
        )
        self.assertShapesEqual(network.output_shape, (None, None, None, None))

        network = layers.join(layers.Input((10, 10, 1)), network)
        self.assertShapesEqual(network.output_shape, (None, 5, 5, 1))
Exemplo n.º 2
0
 def test_failed_pooling_connection(self):
     network = layers.join(
         layers.Relu(),
         layers.AveragePooling((2, 2)),
         layers.Reshape(),
     )
     error_message = ("Pooling layer expects an input with 4 "
                      "dimensions, got 2 with shape \(\?, 10\)")
     with self.assertRaisesRegexp(LayerConnectionError, error_message):
         layers.join(layers.Input(10), network)
Exemplo n.º 3
0
    def test_average_pooling(self):
        input_data = asfloat(
            np.array([
                [1, 2, 3, -1],
                [4, -6, 3, 1],
                [0, 0, 1, 0],
                [0, -1, 0, 0],
            ])).reshape(1, 4, 4, 1)
        expected_output = asfloat(
            np.array([
                [1 / 4., 6 / 4.],
                [-1 / 4., 1 / 4.],
            ])).reshape(1, 2, 2, 1)

        average_pool_layer = layers.AveragePooling((2, 2))
        actual_output = self.eval(average_pool_layer.output(input_data))
        np.testing.assert_array_almost_equal(actual_output, expected_output)
Exemplo n.º 4
0
def Inception_1(conv_filters):
    return layers.join(
        [[
            ConvReluBN((conv_filters[0][0], 1, 1)),
        ], [
            ConvReluBN((conv_filters[1][0], 1, 1)),
            ConvReluBN((conv_filters[1][1], 5, 5), padding=2),
        ], [
            ConvReluBN((conv_filters[2][0], 1, 1)),
            ConvReluBN((conv_filters[2][1], 3, 3), padding=1),
            ConvReluBN((conv_filters[2][2], 3, 3), padding=1),
        ], [
            layers.AveragePooling((3, 3), stride=(1, 1), padding=1,
                                  mode='exclude_padding'),
            ConvReluBN((conv_filters[3][0], 1, 1)),
        ]],
        layers.Concatenate(),
    )
Exemplo n.º 5
0
    def test_average_pooling(self):
        X = asfloat(np.array([
            [1, 2, 3, -1],
            [4, -6, 3, 1],
            [0, 0, 1, 0],
            [0, -1, 0, 0],
        ])).reshape(1, 4, 4, 1)
        expected_output = asfloat(np.array([
            [1 / 4., 6 / 4.],
            [-1 / 4., 1 / 4.],
        ])).reshape(1, 2, 2, 1)

        network = layers.join(
            layers.Input((4, 4, 1)),
            layers.AveragePooling((2, 2)),
        )
        actual_output = self.eval(network.output(X))
        np.testing.assert_array_almost_equal(actual_output, expected_output)