def forward(self, x): x = F.relu(self.conv1_1(x)) x = F.relu(self.conv1_2(x)) x = F.pooling(x, 2, 2) x = F.relu(self.conv2_1(x)) x = F.relu(self.conv2_2(x)) x = F.pooling(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(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(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(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 forward(self, x): x = F.relu(self.conv1_1(x)) # (OH, OW)=(28, 28) x = F.relu(self.conv1_2(x)) # (OH, OW)=(28, 28) x = F.pooling(x, 2, 2) # (OH, OW)=(14, 14) x = F.relu(self.conv2_1(x)) # (OH, OW)=(14, 14) x = F.relu(self.conv2_2(x)) # (OH, OW)=(14, 14) x = F.pooling(x, 2, 2) # (OH, OW)=(7, 7) x = F.reshape(x, (x.shape[0], -1)) # (7, 7)->(49, ) x = F.dropout(F.relu(self.fc3(x))) x = self.fc4(x) return x
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(x, ksize, stride, pad) expected = CF.max_pooling_2d(x, ksize, stride, pad, cover_all=False) self.assertTrue(np.array_equal(expected.data, y.data))
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(x, ksize, stride, pad) expected = CF.max_pooling_2d(x, ksize, stride, pad) self.assertTrue(array_allclose(expected.data, y.data))
def forward(self, x): x = F.relu(self.bn1(self.conv1(x))) x = F.pooling(x, kernel_size=3, stride=2) x = self.res2(x) x = self.res3(x) x = self.res4(x) x = self.res5(x) x = _global_average_pooling_2d(x) x = self.fc6(x) return x
def forward(self, x): x = F.relu(self.conv1(x)) # (OH, OW)=(28, 28) x = F.pooling(x, 2, 2) # (OH, OW)=(14, 14) #x = F.relu(self.conv2(x)) #x = F.pooling(x, 2, 2) x = F.reshape(x, (x.shape[0], -1)) # (14, 14)->(196, ) x = F.dropout(F.relu(self.fc3(x))) #x = F.dropout(F.relu(self.fc4(x))) x = self.fc5(x) return x
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(gradient_check(f, x))