5 import chainer.functions
as F
6 import chainer.links
as L
10 def __init__(self, in_size, ch, out_size, stride=2):
11 initialW = chainer.initializers.HeNormal()
13 conv1=L.Convolution2D(
14 in_size, ch, 1, stride, 0, nobias=
True, initialW=initialW),
15 bn1=L.BatchNormalization(ch),
16 conv2=L.Convolution2D(
17 ch, ch, 3, 1, 1, nobias=
True, initialW=initialW),
18 bn2=L.BatchNormalization(ch),
19 conv3=L.Convolution2D(
20 ch, out_size, 1, 1, 0, nobias=
True, initialW=initialW),
21 bn3=L.BatchNormalization(out_size),
23 conv4=L.Convolution2D(
24 in_size, out_size, 1, stride, 0,
25 nobias=
True, initialW=initialW),
26 bn4=L.BatchNormalization(out_size),
30 h1 = F.relu(self.bn1(self.conv1(x)))
31 h1 = F.relu(self.bn2(self.conv2(h1)))
32 h1 = self.bn3(self.conv3(h1))
33 h2 = self.bn4(self.conv4(x))
35 return F.relu(h1 + h2)
40 initialW = chainer.initializers.HeNormal()
42 conv1=L.Convolution2D(
43 in_size, ch, 1, 1, 0, nobias=
True, initialW=initialW),
44 bn1=L.BatchNormalization(ch),
45 conv2=L.Convolution2D(
46 ch, ch, 3, 1, 1, nobias=
True, initialW=initialW),
47 bn2=L.BatchNormalization(ch),
48 conv3=L.Convolution2D(
49 ch, in_size, 1, 1, 0, nobias=
True, initialW=initialW),
50 bn3=L.BatchNormalization(in_size),
54 h = F.relu(self.bn1(self.conv1(x)))
55 h = F.relu(self.bn2(self.conv2(h)))
56 h = self.bn3(self.conv3(h))
62 def __init__(self, layer, in_size, ch, out_size, stride=2):
64 links = [(
'a',
BottleNeckA(in_size, ch, out_size, stride))]
65 for i
in range(layer - 1):
74 f = getattr(self, name)
85 initialW = chainer.initializers.HeNormal()
87 conv1=L.Convolution2D(
88 3, 64, 7, 2, 3, nobias=
True, initialW=initialW),
89 bn1=L.BatchNormalization(64),
90 res2=
Block(3, 64, 64, 256, 1),
91 res3=
Block(4, 256, 128, 512),
92 res4=
Block(6, 512, 256, 1024),
93 res5=
Block(3, 1024, 512, 2048),
94 fc=L.Linear(2048, 1000),
103 h = self.bn1(self.conv1(x))
104 h = F.max_pooling_2d(F.relu(h), 3, stride=2)
109 h = F.average_pooling_2d(h, 7, stride=1)
115 self.
loss = F.softmax_cross_entropy(h, t)
123 h = self.bn1(self.conv1(x))
124 h = F.max_pooling_2d(F.relu(h), 3, stride=2)
129 h = F.average_pooling_2d(h, 7, stride=1)
def __init__(self, in_size, ch)
def __init__(self, layer, in_size, ch, out_size, stride=2)
def __call__(self, x, t=None)
def __init__(self, in_size, ch, out_size, stride=2)