alexnet.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 AlexNet(chainer.Chain):
7 
8  def __init__(self, n_class=1000):
9  super(AlexNet, self).__init__(
10  conv1=L.Convolution2D(3, 96, 11, stride=4),
11  conv2=L.Convolution2D(96, 256, 5, pad=2),
12  conv3=L.Convolution2D(256, 384, 3, pad=1),
13  conv4=L.Convolution2D(384, 384, 3, pad=1),
14  conv5=L.Convolution2D(384, 256, 3, pad=1),
15  fc6=L.Linear(9216, 4096),
16  fc7=L.Linear(4096, 4096),
17  fc8=L.Linear(4096, n_class))
18 
19  def __call__(self, x, t=None):
20  h = F.local_response_normalization(self.conv1(x))
21  h = F.max_pooling_2d(F.relu(h), 3, stride=2)
22  h = F.local_response_normalization(self.conv2(h))
23  h = F.max_pooling_2d(F.relu(h), 3, stride=2)
24  h = F.relu(self.conv3(h))
25  h = F.relu(self.conv4(h))
26  h = F.max_pooling_2d(F.relu(self.conv5(h)), 3, stride=2)
27  h = F.dropout(F.relu(self.fc6(h)))
28  h = F.dropout(F.relu(self.fc7(h)))
29  h = self.fc8(h)
30 
31  self.pred = F.softmax(h)
32  if t is None:
33  assert not chainer.config.train
34  return
35 
36  self.loss = F.softmax_cross_entropy(h, t)
37  self.accuracy = F.accuracy(h, t)
38  return self.loss


jsk_recognition_utils
Author(s):
autogenerated on Mon May 3 2021 03:03:03