2 import chainer.functions
as F
3 import chainer.links
as L
4 from chainer
import initializers
9 def __init__(self, in_size, out_size, stride=1, activation=F.elu,
10 is_first=False, pad=1, projection_pad=0, flag=False):
12 initialW = initializers.HeNormal()
19 with self.init_scope():
21 self.
bn0 = L.BatchNormalization(in_size)
23 self.
conv1 = L.Convolution2D(
24 in_size, out_size, 3, stride, pad,
25 initialW=initialW, nobias=
True)
27 self.
conv1 = L.Convolution2D(
28 in_size, out_size, 3, stride, 0,
29 initialW=initialW, nobias=
True)
30 self.
bn1 = L.BatchNormalization(out_size)
31 self.
conv2 = L.Convolution2D(
32 out_size, out_size, 3, 1,
33 pad, initialW=initialW, nobias=
False)
34 if in_size != out_size:
35 if out_size != 2 * in_size:
36 raise ValueError(
'out_size should be two 2 * in_size ',
37 '{} != {}'.
format(out_size, 2 * in_size))
40 1, stride, projection_pad, nobias=
True)
43 batchsize, channel, height, width = x.shape
51 h = F.concat([F.concat([
53 self.xp.zeros((batchsize, channel, 1, width),
'f')], axis=2),
55 batchsize, channel, height + 1, 1),
'f')],
60 h = F.dropout(h, ratio=0.6)
71 super(DeepSortFeatureExtractor, self).
__init__()
73 with self.init_scope():
75 3, 32, 3, 1, 1, nobias=
True)
76 self.
bn1 = L.BatchNormalization(32)
78 32, 32, 3, 1, 1, nobias=
True)
79 self.
bn2 = L.BatchNormalization(32)
83 32, 64, stride=2, pad=1, projection_pad=0)
86 64, 128, stride=2, pad=1, projection_pad=0, flag=
True)
88 self.
fc1 = L.Linear(16384, 128, nobias=
True)
89 self.
fc1_bn = L.BatchNormalization(128)
91 self.
ball = L.BatchNormalization(128)
93 self.
scale = chainer.Parameter(0, shape=[1501])
97 batchsize = x.shape[0]
100 h = F.max_pooling_2d(h, 3, 2, cover_all=
False)
108 h = h.reshape(batchsize, -1)
109 h = F.dropout(h, ratio=0.6)
114 features = self.
ball(h)
115 features = F.normalize(features, eps=1e-8)
116 scale = F.softplus(self.
scale)
117 normalized_weight = F.normalize(weights, axis=0, eps=1e-8)
118 logits = F.tile(scale[
None, ], (batchsize, 1)) * \
119 F.matmul(features, normalized_weight)