Esempio n. 1
0
    def test_fprop_avgpool2d(self):

        pool_layer = layers.AvgPool2D(pool_size=(2, 2),
                                      strides=(1, 1),
                                      padding=PaddingMode.valid,
                                      data_format="channels_last")
        self.create_small_net_with_pool_layer(pool_layer,
                                              outputs_per_channel=9)

        func = compile_func([self.input_layer.get_activation_vars()],
                            self.pool_layer.get_activation_vars())
        np.testing.assert_almost_equal(
            func([self.reference_inps[0], self.reference_inps[0] - 1]),
            0.25 * np.array([[[[1, 3, 5], [6, 10, 4], [11, 16, 19]],
                              [[5, 7, 9], [10, 14, 8], [15, 20, 23]]],
                             [[[-3, -1, 1], [2, 6, 0], [7, 12, 15]],
                              [[1, 3, 5], [6, 10, 4], [11, 16, 19]]]
                             ]).transpose(0, 2, 3, 1))
Esempio n. 2
0
    def test_backprop_avgpool2d(self):
        pool_layer = layers.AvgPool2D(pool_size=(2, 2),
                                      strides=(1, 1),
                                      padding=PaddingMode.valid,
                                      data_format="channels_last")
        self.create_small_net_with_pool_layer(pool_layer,
                                              outputs_per_channel=9)

        self.dense_layer.update_task_index(task_index=0)
        func = compile_func([
            self.input_layer.get_activation_vars(),
            self.input_layer.get_reference_vars()
        ], self.input_layer.get_mxts())
        avg_pool_grads = np.array([[1, 2, 2, 1], [2, 4, 4, 2], [2, 4, 4, 2],
                                   [1, 2, 2, 1]]).astype("float32")
        np.testing.assert_almost_equal(
            func([
                self.backprop_test_inps,
                np.ones_like(self.backprop_test_inps) * self.reference_inps
            ]),
            np.array([[avg_pool_grads * 2 * 0.25, avg_pool_grads * 3 * 0.25],
                      [avg_pool_grads * 2 * 0.25,
                       avg_pool_grads * 3 * 0.25]]).transpose(0, 2, 3, 1))
Esempio n. 3
0
def avgpool2d_conversion(config, name, verbose, **kwargs):
    pool2d_kwargs = prep_pool2d_kwargs(config=config,
                                       name=name,
                                       verbose=verbose)
    return [layers.AvgPool2D(**pool2d_kwargs)]