def forward(self, x): x = F.relu(self.conv1_1(x)) x = F.relu(self.conv1_2(x)) x = F.pooling_simple(x, 2, 2) x = F.relu(self.conv2_1(x)) x = F.relu(self.conv2_2(x)) x = F.pooling_simple(x, 2, 2) x = F.relu(self.conv3_1(x)) x = F.relu(self.conv3_2(x)) x = F.relu(self.conv3_3(x)) x = F.pooling_simple(x, 2, 2) x = F.relu(self.conv4_1(x)) x = F.relu(self.conv4_2(x)) x = F.relu(self.conv4_3(x)) x = F.pooling_simple(x, 2, 2) x = F.relu(self.conv5_1(x)) x = F.relu(self.conv5_2(x)) x = F.relu(self.conv5_3(x)) x = F.pooling_simple(x, 2, 2) x = F.reshape(x, (x.shape[0], -1)) x = F.dropout(F.relu(self.fc6(x))) x = F.dropout(F.relu(self.fc7(x))) x = self.fc8(x) return x
def test_forward1(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') y = F.pooling_simple(x, ksize, stride, pad) expected = CF.max_pooling_2d(x, ksize, stride, pad) self.assertTrue(np.array_equal(expected.data, y.data))
def test_forward2(self): n, c, h, w = 1, 5, 15, 15 ksize, stride, pad = 2, 2, 0 x = np.random.randn(n, c, h, w).astype('f') y = F.pooling_simple(x, ksize, stride, pad) expected = CF.max_pooling_2d(x, ksize, stride, pad, cover_all=False) self.assertTrue(array_allclose(expected.data, y.data))
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') * 100 f = lambda x: F.pooling_simple(x, ksize, stride, pad) self.assertTrue(gradient_check(f, x))