def test_backward1(self):
        n, c, h, w = 1, 1, 3, 3
        x = np.arange(n * c * h * w).reshape((n, c, h, w))
        # y = F.im2col(x, 3, 3, 0)

        f = lambda x: F.im2col(x, 3, 3, 0)
        self.assertTrue(check_backward(f, x))
Пример #2
0
    def test_forward1(self):
        n, c, h, w = 1, 1, 3, 3
        x = np.arange(n * c * h * w).reshape((n, c, h, w))
        y = F.im2col(x, 3, 3, 0, to_matrix=True)
        expected = np.array([[0, 1, 2, 3, 4, 5, 6, 7, 8]])

        res = np.array_equal(y.data, expected)
        self.assertTrue(res)
Пример #3
0
#!/usr/bin/python3
# coding: utf-8

if '__file__' in globals():
    import os, sys
    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import numpy as np
from dezero import Variable
import dezero.functions as F

x1 = np.random.rand(1, 3, 7, 7)
col1 = F.im2col(x1, kernel_size=5, stride=1, pad=0, to_matrix=True)
print(col1.shape)

x2 = np.random.rand(10, 3, 7, 7)
kernel_size = (5, 5)
stride = (1, 1)
pad = (0, 0)
col2 = F.im2col(x2, kernel_size, stride, pad, to_matrix=True)
print(col2.shape)

print()

N, C, H, W = 1, 5, 15, 15
OC, (KH, KW) = 8, (3, 3)

x = Variable(np.random.randn(N, C, H, W))
W = np.random.randn(OC, C, KH, KW)
# y = F.conv2d_simple(x, W, b=None, stride=1, pad=1)  ## こっちだと動かない
y = F.conv2d(x, W, b=None, stride=1, pad=1)
Пример #4
0
 def test_backward2(self):
     n, c, h, w = 1, 1, 3, 3
     x = np.arange(n * c * h * w).reshape((n, c, h, w))
     f = lambda x: F.im2col(x, 3, 3, 0, to_matrix=False)
     self.assertTrue(check_backward(f, x))
Пример #5
0
 def test_backward1(self):
     n, c, h, w = 1, 1, 3, 3
     x = np.arange(n * c * h * w).reshape((n, c, h, w))
     f = lambda x: F.im2col(x, 3, 3, 0, to_matrix=True)
     self.assertTrue(gradient_check(f, x))