def test_forward1(self): x0 = np.array([1, 2, 3]) x1 = Variable(np.array([1, 2, 3])) y = x0 + x1 res = y.data expected = np.array([2, 4, 6]) self.assertTrue(array_equal(res, expected))
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 = array_equal(y.data, expected) self.assertTrue(res)
def test_forward3(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).astype('f') W = np.random.randn(o, c, k[0], k[1]).astype('f') b = None y = F.conv2d(x, W, b, s, p) expected = CF.convolution_2d(x, W, b, s, p) self.assertTrue(array_equal(expected.data, y.data))
def test_forward1(self): n, c, h, w = 1, 5, 15, 15 o, k, s, p = 8, (3, 3), (1, 1), (1, 1) x = np.random.randn(n, c, h, w).astype('f') W = np.random.randn(o, c, k[0], k[1]).astype('f') b = None y = F.conv2d_simple(x, W, b, s, p) expected = CF.convolution_2d(x, W, b, s, p) self.assertTrue(array_equal(expected.data, y.data))
def test_forward1(self): x = np.random.randn(100, 100) y = F.dropout(Variable(x), dropout_ratio=0.0) res = array_equal(y.data, x) self.assertTrue(res)
def test_forward2(self): x = np.random.randn(100, 100) with dezero.test_mode(): y = F.dropout(x) res = array_equal(y.data, x) self.assertTrue(res)
def test_div(self): self.assertTrue( array_equal( Variable(np.array(12)) / Variable(np.array(3)), Variable(np.array(4))))
def test_rsub(self): self.assertTrue( array_equal( np.array(4) - Variable(np.array(3)), Variable(np.array(1))))
def test_neg(self): self.assertTrue( array_equal(-Variable(np.array(1)), Variable(np.array(-1))))
def test_add(self): self.assertTrue( array_equal( Variable(np.array(3)) + Variable(np.array(4)), Variable(np.array(7))))
def test_mul_variable_num(self): a = Variable(np.array(3)) b = 4 expect = Variable(np.array(12)) self.assertTrue(array_equal(a * b, expect))
def test_mul_num_variable(self): a = 3 b = Variable(np.array(4)) expect = Variable(np.array(12)) self.assertTrue(array_equal(a * b, expect))
def test_pow(self): self.assertTrue( array_equal(Variable(np.array(3))**2, Variable(np.array(9))))