vgg16_batch_normalization.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 VGG16BatchNormalization(chainer.Chain):
7 
8  def __init__(self, n_class=1000):
9  super(self.__class__, self).__init__(
10  conv1_1=L.Convolution2D(3, 64, 3, stride=1, pad=1),
11  bn1_1=L.BatchNormalization(64),
12  conv1_2=L.Convolution2D(64, 64, 3, stride=1, pad=1),
13  bn1_2=L.BatchNormalization(64),
14 
15  conv2_1=L.Convolution2D(64, 128, 3, stride=1, pad=1),
16  bn2_1=L.BatchNormalization(128),
17  conv2_2=L.Convolution2D(128, 128, 3, stride=1, pad=1),
18  bn2_2=L.BatchNormalization(128),
19 
20  conv3_1=L.Convolution2D(128, 256, 3, stride=1, pad=1),
21  bn3_1=L.BatchNormalization(256),
22  conv3_2=L.Convolution2D(256, 256, 3, stride=1, pad=1),
23  bn3_2=L.BatchNormalization(256),
24  conv3_3=L.Convolution2D(256, 256, 3, stride=1, pad=1),
25  bn3_3=L.BatchNormalization(256),
26 
27  conv4_1=L.Convolution2D(256, 512, 3, stride=1, pad=1),
28  bn4_1=L.BatchNormalization(512),
29  conv4_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
30  bn4_2=L.BatchNormalization(512),
31  conv4_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),
32  bn4_3=L.BatchNormalization(512),
33 
34  conv5_1=L.Convolution2D(512, 512, 3, stride=1, pad=1),
35  bn5_1=L.BatchNormalization(512),
36  conv5_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
37  bn5_2=L.BatchNormalization(512),
38  conv5_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),
39  bn5_3=L.BatchNormalization(512),
40 
41  fc6=L.Linear(25088, 4096),
42  fc7=L.Linear(4096, 4096),
43  fc8=L.Linear(4096, n_class)
44  )
45 
46  def __call__(self, x, t=None):
47  h = F.relu(self.bn1_1(self.conv1_1(x)))
48  h = F.relu(self.bn1_2(self.conv1_2(h)))
49  h = F.max_pooling_2d(h, 2, stride=2)
50 
51  h = F.relu(self.bn2_1(self.conv2_1(h)))
52  h = F.relu(self.bn2_2(self.conv2_2(h)))
53  h = F.max_pooling_2d(h, 2, stride=2)
54 
55  h = F.relu(self.bn3_1(self.conv3_1(h)))
56  h = F.relu(self.bn3_2(self.conv3_2(h)))
57  h = F.relu(self.bn3_3(self.conv3_3(h)))
58  h = F.max_pooling_2d(h, 2, stride=2)
59 
60  h = F.relu(self.bn4_1(self.conv4_1(h)))
61  h = F.relu(self.bn4_2(self.conv4_2(h)))
62  h = F.relu(self.bn4_3(self.conv4_3(h)))
63  h = F.max_pooling_2d(h, 2, stride=2)
64 
65  h = F.relu(self.bn5_1(self.conv5_1(h)))
66  h = F.relu(self.bn5_2(self.conv5_2(h)))
67  h = F.relu(self.bn5_3(self.conv5_3(h)))
68  h = F.max_pooling_2d(h, 2, stride=2)
69 
70  h = F.dropout(F.relu(self.fc6(h)), ratio=0.5)
71  h = F.dropout(F.relu(self.fc7(h)), ratio=0.5)
72  h = self.fc8(h)
73  fc8 = h
74 
75  self.pred = F.softmax(h)
76 
77  if t is None:
78  assert not chainer.config.train
79  return
80 
81  self.loss = F.softmax_cross_entropy(fc8, t)
82  self.acc = F.accuracy(self.pred, t)
83 
84  return self.loss


jsk_recognition_utils
Author(s):
autogenerated on Fri Dec 6 2019 04:02:51