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_backward3(self):
        x_data = np.random.randn(10, 10)

        def f(x):
            np.random.seed(0)
            return F.dropout(x, 0.0)

        self.assertTrue(check_backward(f, x_data))
 def test_backward3(self):
     n, c, h, w = 1, 5, 20, 15
     o, k, s, p = 3, (5, 3), 1, 3
     x = np.random.randn(n, c, h, w)
     W = np.random.randn(o, c, k[0], k[1])
     b = np.random.randn(o)
     f = lambda W: F.conv2d_simple(x, W, b, s, p)
     self.assertTrue(check_backward(f, W))
 def test_backward3(self):
     n, c_i, c_o = 10, 1, 3
     h_i, w_i = 5, 10
     h_k, w_k = 10, 10
     h_p, w_p = 5, 5
     s_y, s_x = 5, 5
     x = np.random.uniform(0, 1, (n, c_i, h_i, w_i)).astype(np.float32)
     W = np.random.uniform(0, 1, (c_i, c_o, h_k, w_k)).astype(np.float32)
     b = np.random.uniform(0, 1, c_o).astype(np.float32)
     f = lambda b: F.deconv2d(x, W, b, stride=(s_y, s_x), pad=(h_p, w_p))
     self.assertTrue(check_backward(f, b))
 def test_backward1(self):
     x_data = np.array([[1, 2, 3], [4, 5, 6]])
     slices = 1
     y_grad = np.ones(x_data[slices].shape)
     f = lambda x: F.get_item(x, slices)
     check_backward(f, x_data, y_grad=y_grad)
 def test_backward1(self):
     x = np.array([[-1, 0, 1, 2], [2, 0, 1, -1]])
     f = lambda x: F.log_softmax(x)
     self.assertTrue(check_backward(f, x))
 def test_backward2(self):
     x = np.random.randn(10, 10)
     f = lambda x: F.log_softmax(x)
     self.assertTrue(check_backward(f, x))
示例#8
0
 def test_backward2(self):
     x_data = np.random.randn(10, 1)
     w_data = np.random.randn(1, 5)
     f = lambda w: F.matmul(Variable(x_data), w)
     t = check_backward(f, w_data)
     self.assertTrue(t)
示例#9
0
 def test_backward2(self):
     x = np.random.randn(100, 200)
     W = np.random.randn(200, 300)
     b = None
     f = lambda x: F.linear(x, W, b)
     self.assertTrue(check_backward(f, x))
示例#10
0
 def test_backward5(self):
     x_data = np.random.rand(10, 20, 20) * 100
     f = lambda x: F.sum(x, axis=None, keepdims=True)
     self.assertTrue(check_backward(f, x_data))
示例#11
0
 def test_backward2(self):
     n, c, h, w = 1, 1, 3, 3
     x = np.random.rand(1, 1, 3, 3, 1, 1)
     f = lambda x: F.col2im(x, (n, c, h, w), 3, 3, 0, to_matrix=False)
     self.assertTrue(check_backward(f, x))
示例#12
0
 def test_backward1(self):
     x = np.random.randn(3, 3)
     w = np.random.randn(3, 3)
     f = lambda x: x + Variable(w)
     self.assertTrue(check_backward(f, x))
示例#13
0
 def test_backward3(self):
     np.random.seed(0)
     x_data = np.random.rand(10, 10, 10)
     f = lambda x: F.softmax(x, axis=1)
     self.assertTrue(check_backward(f, x_data))
示例#14
0
 def test_backward4(self):
     x_data = np.random.rand(10)
     f = lambda x: F.sum_to(x, (10, )) + 1
     self.assertTrue(check_backward(f, x_data))
示例#15
0
 def test_backward2(self):
     x_data = np.random.rand(10, 10) * 100
     f = lambda x: F.max(x, axis=1)
     self.assertTrue(check_backward(f, x_data))
示例#16
0
 def test_backward3(self):
     x_data = np.random.rand(10, 20, 20) * 100
     f = lambda x: F.sum_to(x, (10, ))
     self.assertTrue(check_backward(f, x_data))
示例#17
0
 def test_backward4(self):
     x_data = np.random.rand(10, 20, 20)
     f = lambda x: F.sum(x, axis=None)
     self.assertTrue(check_backward(f, x_data))
示例#18
0
 def test_backward1(self):
     x_data = np.random.rand(10)
     f = lambda x: F.sum(x)
     self.assertTrue(check_backward(f, x_data))
 def test_backward2(self):
     x_data = np.arange(12).reshape(4, 3)
     slices = slice(1, 3)
     y_grad = np.ones(x_data[slices].shape)
     f = lambda x: F.get_item(x, slices)
     check_backward(f, x_data, y_grad=y_grad)
示例#20
0
 def test_backward1(self):
     n, c, h, w = 1, 5, 16, 16
     ksize, stride, pad = 2, 2, 0
     x = np.random.randn(n, c, h, w).astype('f') * 1000
     f = lambda x: F.pooling(x, ksize, stride, pad)
     self.assertTrue(check_backward(f, x))
示例#21
0
 def test_backward1(self):
     x_data = np.array([[1, 2, 3], [4, 5, 6]])
     self.assertTrue(check_backward(F.transpose, x_data))
示例#22
0
 def test_backward3(self):
     x_data = np.random.rand(10, 20, 30) * 100
     f = lambda x: F.max(x, axis=(1, 2))
     self.assertTrue(check_backward(f, x_data))
示例#23
0
 def test_backward1(self):
     x_data = np.array([[0, 1, 2], [0, 2, 4]])
     f = lambda x: F.softmax(x, axis=1)
     self.assertTrue(check_backward(f, x_data))
示例#24
0
 def test_backward2(self):
     x_data = np.array([1, 2, 3])
     self.assertTrue(check_backward(F.transpose, x_data))
示例#25
0
 def test_backward1(self):
     x_data = np.array([[-1, 0, 1, 2], [2, 0, 1, -1]], np.float32)
     t = np.array([3, 0]).astype(np.int32)
     f = lambda x: F.softmax_cross_entropy(x, Variable(t))
     self.assertTrue(check_backward(f, x_data))
示例#26
0
 def test_backward3(self):
     x_data = np.random.randn(10, 5)
     self.assertTrue(check_backward(F.transpose, x_data))
示例#27
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))
示例#28
0
 def test_backward3(self):
     x = np.random.randn(3, 3)
     y = np.random.randn(3, 1)
     f = lambda x: x / y
     self.assertTrue(check_backward(f, x))
示例#29
0
 def test_backward1(self):
     x = np.random.randn(3, 2)
     W = np.random.randn(2, 3)
     b = np.random.randn(3)
     f = lambda x: F.linear(x, W, b)
     self.assertTrue(check_backward(f, x))
示例#30
0
 def test_backward1(self):
     x = np.random.randn(3, 2)
     w = np.random.randn(2, 3)
     f = lambda x: F.matmul(x, Variable(w))
     self.assertTrue(check_backward(f, x))