Exemplo n.º 1
0
 def extract(self, x):
     c1_1 = F.relu(self.conv1_1(x))
     c1_2 = F.relu(self.conv1_2(c1_1))
     p1 = F.average_pooling(c1_2, 2, 2)
     c2_1 = F.relu(self.conv2_1(p1))
     c2_2 = F.relu(self.conv2_2(c2_1))
     p2 = F.average_pooling(c2_2, 2, 2)
     c3_1 = F.relu(self.conv3_1(p2))
     c3_2 = F.relu(self.conv3_2(c3_1))
     c3_3 = F.relu(self.conv3_3(c3_2))
     p3 = F.average_pooling(c3_3, 2, 2)
     c4_1 = F.relu(self.conv4_1(p3))
     c4_2 = F.relu(self.conv4_2(c4_1))
     c4_3 = F.relu(self.conv4_3(c4_2))
     p4 = F.average_pooling(c4_3, 2, 2)
     c5_1 = F.relu(self.conv5_1(p4))
     c5_2 = F.relu(self.conv5_2(c5_1))
     c5_3 = F.relu(self.conv5_3(c5_2))
     return {
         'conv1_1': c1_1,
         'conv1_2': c1_2,
         'conv2_1': c2_1,
         'conv2_2': c2_2,
         'conv3_1': c3_1,
         'conv3_2': c3_2,
         'conv3_3': c3_3,
         'conv4_1': c4_1,
         'conv5_1': c5_1,
         'conv5_2': c5_2,
         'conv5_3': c5_3
     }
Exemplo n.º 2
0
    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.average_pooling(x, ksize, stride, pad)
        expected = CF.average_pooling_2d(x, ksize, stride, pad)
        self.assertTrue(array_allclose(expected.data, y.data))
Exemplo n.º 3
0
def _global_average_pooling_2d(x):
    N, C, H, W = x.shape
    h = F.average_pooling(x, (H, W), stride=1)
    h = F.reshape(h, (N, C))
    return h
Exemplo n.º 4
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.average_pooling(x, ksize, stride, pad)
     self.assertTrue(gradient_check(f, x))