vgg16.py
Go to the documentation of this file.
1 import chainer
2 import chainer.functions as F
3 import chainer.links as L
4 
5 
6 class VGG16(chainer.Chain):
7 
8  def __init__(self, n_class):
9  super(VGG16, self).__init__(
10  conv1_1=L.Convolution2D(3, 64, 3, stride=1, pad=1),
11  conv1_2=L.Convolution2D(64, 64, 3, stride=1, pad=1),
12 
13  conv2_1=L.Convolution2D(64, 128, 3, stride=1, pad=1),
14  conv2_2=L.Convolution2D(128, 128, 3, stride=1, pad=1),
15 
16  conv3_1=L.Convolution2D(128, 256, 3, stride=1, pad=1),
17  conv3_2=L.Convolution2D(256, 256, 3, stride=1, pad=1),
18  conv3_3=L.Convolution2D(256, 256, 3, stride=1, pad=1),
19 
20  conv4_1=L.Convolution2D(256, 512, 3, stride=1, pad=1),
21  conv4_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
22  conv4_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),
23 
24  conv5_1=L.Convolution2D(512, 512, 3, stride=1, pad=1),
25  conv5_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
26  conv5_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),
27 
28  fc6=L.Linear(25088, 4096),
29  fc7=L.Linear(4096, 4096),
30  fc8=L.Linear(4096, n_class)
31  )
32 
33  def __call__(self, x, t=None):
34  h = F.relu(self.conv1_1(x))
35  h = F.relu(self.conv1_2(h))
36  h = F.max_pooling_2d(h, 2, stride=2)
37 
38  h = F.relu(self.conv2_1(h))
39  h = F.relu(self.conv2_2(h))
40  h = F.max_pooling_2d(h, 2, stride=2)
41 
42  h = F.relu(self.conv3_1(h))
43  h = F.relu(self.conv3_2(h))
44  h = F.relu(self.conv3_3(h))
45  h = F.max_pooling_2d(h, 2, stride=2)
46 
47  h = F.relu(self.conv4_1(h))
48  h = F.relu(self.conv4_2(h))
49  h = F.relu(self.conv4_3(h))
50  h = F.max_pooling_2d(h, 2, stride=2)
51 
52  h = F.relu(self.conv5_1(h))
53  h = F.relu(self.conv5_2(h))
54  h = F.relu(self.conv5_3(h))
55  h = F.max_pooling_2d(h, 2, stride=2)
56 
57  h = F.dropout(F.relu(self.fc6(h)), ratio=0.5)
58  h = F.dropout(F.relu(self.fc7(h)), ratio=0.5)
59  h = self.fc8(h)
60 
61  self.pred = F.softmax(h)
62  if t is None:
63  assert not chainer.config.train
64  return
65 
66  self.loss = F.softmax_cross_entropy(h, t)
67  self.acc = F.accuracy(h, t)
68  return self.loss


jsk_recognition_utils
Author(s):
autogenerated on Wed May 27 2020 03:59:48