Exemplo n.º 1
0
    def test_fprop_avgpool2d(self): 

        pool_layer = blobs.AvgPool2D(pool_size=(2,2),
                                  strides=(1,1),
                                  border_mode=B.BorderMode.valid,
                                  ignore_border=True,
                                  channels_come_last=False)
        self.create_small_net_with_pool_layer(pool_layer,
                                              outputs_per_channel=9)

        func = B.function([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]]]]))
Exemplo n.º 2
0
    def test_backprop_avgpool2d(self):
        pool_layer = blobs.AvgPool2D(pool_size=(2,2),
                  strides=(1,1),
                  border_mode=B.BorderMode.valid,
                  ignore_border=True,
                  channels_come_last=False)
        self.create_small_net_with_pool_layer(pool_layer,
                                              outputs_per_channel=9)

        self.dense_layer.update_task_index(task_index=0)
        func = B.function([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]]))
Exemplo n.º 3
0
def avgpool2d_conversion(layer, name, verbose, **kwargs):
    pool2d_kwargs = prep_pool2d_kwargs(layer=layer, name=name, verbose=verbose)
    return [blobs.AvgPool2D(**pool2d_kwargs)]