Esempio n. 1
0
 def forward(self, input):
     self._saved_for_backward(input)
     output = avgpool2d_forward(input, self.kernel_size, self.pad)
     return output
Esempio n. 2
0
            flag = 0

    if test_grad_b.shape != grad_b.shape:
        print('[ERROR] conv2d_backward: grad_b shape is not correct')
        flag = 0
    else:
        diff = test_grad_b - grad_b
        if abs(diff).max() > 1e-5:
            print('[ERROR] conv2d_backward: grad_b value is not correct')
            flag = 0
finally:
    if flag:
        print('[PASS] conv2d_backward: all correct')

try:
    test_pool_out = avgpool2d_forward(pool_inp, 2, 0)
except:
    print(
        '[FAILED] avgpool2d_forward: bug in codes, can not run for inp.shape = (4, 3, 6, 6), ker_size = 2, pad = 0'
    )
else:
    if test_pool_out.shape != pool_out.shape:
        print('[ERROR] avgpool2d_forward: output shape is not correct')
    else:
        diff = test_pool_out - pool_out
        if abs(diff).max() > 1e-5:
            print('[ERROR] avgpool2d_forward: output value is not correct')
        else:
            print('[PASS] avgpool2d_forward: all correct')

try: