我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用chainer.functions.max_pooling_2d()。
def __call__(self, x, t, train=True, finetune=False): h = self.l1(x, train, finetune) h = F.dropout(h, self.dr, train) h = self.l2(h, train, finetune) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0, cover_all=True, use_cudnn=True) h = self.l3(h, train, finetune) h = F.dropout(h, self.dr, train) h = self.l4(h, train, finetune) h = F.dropout(h, self.dr, train) h = self.l5(h, train, finetune) h = F.dropout(h, self.dr, train) h = self.l6(h, train, finetune) h = F.dropout(h, self.dr, train) h = self.top(h) h = F.max(h, axis=-1, keepdims=False) h = F.max(h, axis=-1, keepdims=False) return F.softmax_cross_entropy(h, t), F.accuracy(h, t)
def __call__(self, x, train=True): h = self.conv1(x, train) h = self.conv2(h, train) h = self.conv3(h, train) h = F.max_pooling_2d(h, ksize=(3, 3), stride=(2, 2), pad=(1, 1)) h = self.conv4(h, train) h = self.conv5(h, train) h = self.conv6(h, train) h = self.inception_f5_1(h, train) h = self.inception_f5_2(h, train) h = self.inception_f5_3(h, train) h = self.inception_f6_1(h, train) h = self.inception_f6_2(h, train) h = self.inception_f6_3(h, train) h = self.inception_f6_4(h, train) h = self.inception_f6_5(h, train) h = self.inception_f7_1(h, train) h = self.inception_f7_2(h, train) num, categories, y, x = h.data.shape # global average pooling h = F.reshape(F.average_pooling_2d(h, (y, x)), (num, categories)) h = F.dropout(h, ratio=0.2, train=train) h = self.linear(h) return h
def predict(self, xs): """ batch: list of splitted sentences """ xs = [self.extractor.process(x) for x in xs] batchsize = len(xs) ws, cs, ls = zip(*xs) ws = map(self.emb_word, ws) cs = [F.squeeze( F.max_pooling_2d( self.conv_char( F.expand_dims( self.emb_char(c), 1)), (l, 1))) for c, l in zip(cs, ls)] xs_f = [F.dropout(F.concat([w, c]), self.dropout_ratio, train=self.train) for w, c in zip(ws, cs)] xs_b = [x[::-1] for x in xs_f] cx_f, hx_f, cx_b, hx_b = self._init_state(batchsize) _, _, hs_f = self.lstm_f(hx_f, cx_f, xs_f, train=self.train) _, _, hs_b = self.lstm_b(hx_b, cx_b, xs_b, train=self.train) hs_b = [x[::-1] for x in hs_b] ys = [self.linear2(F.relu(self.linear1(F.concat([h_f, h_b])))) for h_f, h_b in zip(hs_f, hs_b)] return [y.data[1:-1] for y in ys]
def __call__(self, x, train=True): hlist = [] h_0 = self['embed'](x) if not self.non_static: h_0 = Variable(h_0.data) h_1 = F.reshape(h_0, (h_0.shape[0], 1, h_0.shape[1], h_0.shape[2])) for filter_h in self.filter_sizes: pool_size = (self.doc_length - filter_h + 1, 1) h = F.max_pooling_2d(F.relu(self['conv' + str(filter_h)](h_1)), pool_size) hlist.append(h) h = F.concat(hlist) pos = 0 while pos < len(self.hidden_units) - 1: h = F.dropout(F.relu(self['l' + str(pos)](h))) pos += 1 y = F.relu(self['l' + str(pos)](h)) return y
def __call__(self, x, t): self.clear() h = F.max_pooling_2d(F.relu( F.local_response_normalization(self.conv1(x))), 3, stride=2) h = F.max_pooling_2d(F.relu( F.local_response_normalization(self.conv2(h))), 3, stride=2) h = F.relu(self.conv3(h)) h = F.relu(self.conv4(h)) h = F.max_pooling_2d(F.relu(self.conv5(h)), 3, stride=2) h = F.dropout(F.relu(self.fc6(h)), train=self.train) h = F.dropout(F.relu(self.fc7(h)), train=self.train) h = self.fc8(h) self.loss = F.softmax_cross_entropy(h, t) self.accuracy = F.accuracy(h, t) return self.loss
def _setup_pooling(self, layer): param = layer.pooling_param ksize = _get_ksize(param) stride = _get_stride(param) pad = _get_pad(param) if param.pool == param.MAX: func = functions.max_pooling_2d elif param.pool == param.AVE: func = functions.average_pooling_2d else: raise RuntimeError('Stochastic pooling is not supported') fw = _SingleArgumentFunction(func, ksize, stride=stride, pad=pad) self.forwards[layer.name] = fw self._add_layer(layer)
def __call__(self, x, t): self.clear() h = self.bn1(self.conv1(x), test=not self.train) h = F.max_pooling_2d(F.relu(h), 3, stride=2) h = self.bn2(self.conv2(h), test=not self.train) h = F.max_pooling_2d(F.relu(h), 3, stride=2) h = F.relu(self.conv3(h)) h = F.relu(self.conv4(h)) h = F.max_pooling_2d(F.relu(self.conv5(h)), 3, stride=2) h = F.dropout(F.relu(self.fc6(h)), train=self.train) h = F.dropout(F.relu(self.fc7(h)), train=self.train) h = self.fc8(h) self.loss = F.softmax_cross_entropy(h, t) self.accuracy = F.accuracy(h, t) return self.loss
def check_forward(self, x_data, use_cudnn=True): x = chainer.Variable(x_data) y = functions.max_pooling_2d(x, 3, stride=2, pad=1, cover_all=self.cover_all, use_cudnn=use_cudnn) self.assertEqual(y.data.dtype, self.dtype) y_data = cuda.to_cpu(y.data) self.assertEqual(self.gy.shape, y_data.shape) for k in six.moves.range(2): for c in six.moves.range(3): x = self.x[k, c] if self.cover_all: expect = numpy.array([ [x[0:2, 0:2].max(), x[0:2, 1:3].max()], [x[1:4, 0:2].max(), x[1:4, 1:3].max()], [x[3:4, 0:2].max(), x[3:4, 1:3].max()]]) else: expect = numpy.array([ [x[0:2, 0:2].max(), x[0:2, 1:3].max()], [x[1:4, 0:2].max(), x[1:4, 1:3].max()]]) gradient_check.assert_allclose(expect, y_data[k, c])
def predict(self,x): h = F.leaky_relu(self.c1(x),slope=0.1) h = F.max_pooling_2d(h,ksize=2,stride=2,pad=0) h = F.leaky_relu(self.c3(h),slope=0.1) h = F.max_pooling_2d(h,ksize=2,stride=2,pad=0) h = F.leaky_relu(self.c5(h),slope=0.1) h = F.max_pooling_2d(h,ksize=2,stride=2,pad=0) h = F.leaky_relu(self.c7(h),slope=0.1) h = F.max_pooling_2d(h,ksize=2,stride=2,pad=0) h = F.leaky_relu(self.c9(h),slope=0.1) h = F.max_pooling_2d(h,ksize=2,stride=2,pad=0) h = F.leaky_relu(self.c11(h),slope=0.1) h = F.max_pooling_2d(h,ksize=2,stride=2,pad=0) h = F.leaky_relu(self.c13(h),slope=0.1) h = F.leaky_relu(self.c14(h),slope=0.1) h = F.leaky_relu(self.c15(h),slope=0.1) h = F.leaky_relu(self.l16(h),slope=0.1) h = F.leaky_relu(self.l17(h),slope=0.1) # skip dropout h = self.l19(h) return h
def predict(self, x): """ Predict 2D pose from image. """ # layer1 h = F.relu(self.conv1(x)) h = F.max_pooling_2d(h, 3, stride=2) # layer2 h = F.relu(self.conv2(h)) h = F.max_pooling_2d(h, 3, stride=2) # layer3-5 h = F.relu(self.conv3(h)) h = F.relu(self.conv4(h)) h = F.relu(self.conv5(h)) h = F.max_pooling_2d(h, 3, stride=2) # layer6-8 h = F.dropout(F.relu(self.fc6(h)), train=self.train) h = F.dropout(F.relu(self.fc7(h)), train=self.train) h = self.fc8(h) return F.reshape(h, (-1, self.Nj, 2))
def __call__(self, x): h = self.conv1(x) h = F.relu(h) h = F.max_pooling_2d(h, ksize=3, stride=2) h = self.conv2(h) h = F.relu(h) h = F.max_pooling_2d(h, ksize=3, stride=2) h = self.conv3(h) h = F.relu(h) h = F.max_pooling_2d(h, ksize=3, stride=2) h = self.conv4(h) h = F.relu(h) h = self.conv5(h) h = F.relu(h) h = self.conv6(h) h = F.relu(h) h = self.conv7(h) return h
def __call__(self, xs): if self.freeze: self.embed.disable_update() xs = self.embed(xs) batchsize, height, width = xs.shape xs = F.reshape(xs, (batchsize, 1, height, width)) conv3_xs = self.conv3(xs) conv4_xs = self.conv4(xs) conv5_xs = self.conv5(xs) h1 = F.max_pooling_2d(F.relu(conv3_xs), conv3_xs.shape[2]) h2 = F.max_pooling_2d(F.relu(conv4_xs), conv4_xs.shape[2]) h3 = F.max_pooling_2d(F.relu(conv5_xs), conv5_xs.shape[2]) concat_layer = F.concat([h1, h2, h3], axis=1) with chainer.using_config('train', True): y = self.l1(F.dropout(F.tanh(concat_layer))) return y
def __call__(self, x): h = F.relu(self.conv1_1(x)) h = F.relu(self.conv1_2(h)) h = F.max_pooling_2d(h, 2, 2) h = F.relu(self.conv2_1(h)) h = F.relu(self.conv2_2(h)) h = F.max_pooling_2d(h, 2, 2) h = F.relu(self.conv3_1(h)) h = F.relu(self.conv3_2(h)) h = F.relu(self.conv3_3(h)) h = F.relu(self.conv3_4(h)) h = F.max_pooling_2d(h, 2, 2) h = F.relu(self.fc4(h)) h = F.relu(self.fc5(h)) h = self.fc6(h) L_out = h return L_out # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
def __call__(self, x): h = self.bconv1_1(x) h = self.bconv1_2(h) h = F.dropout(F.max_pooling_2d(h, 2), 0.25) h = self.bconv2_1(h) h = self.bconv2_2(h) h = F.dropout(F.max_pooling_2d(h, 2), 0.25) h = self.bconv3_1(h) h = self.bconv3_2(h) h = self.bconv3_3(h) h = self.bconv3_4(h) h = F.dropout(F.max_pooling_2d(h, 2), 0.25) h = F.relu(self.fc4(F.dropout(h))) h = F.relu(self.fc5(F.dropout(h))) h = self.fc6(h) return h
def __call__(self, x): h = self.l0(x) h = self.l1_1(h) h = self.l1_2(h) h = F.dropout(F.max_pooling_2d(h, 2), 0.25) h = self.l2_1(h) h = self.l2_2(h) h = F.dropout(F.max_pooling_2d(h, 2), 0.25) h = self.l3_1(h) h = self.l3_2(h) h = F.dropout(F.max_pooling_2d(h, 2), 0.25) h = self.l4_1(h) h = self.l4_2(h) h = F.dropout(h, 0.25) h = F.average_pooling_2d(h, 4, 1, 0) h = self.fc(h) return h
def __call__(self, x, train=True): h = self.conv1(x, train) h = F.max_pooling_2d(h, ksize=(3, 3), stride=(2, 2), pad=(1, 1)) h = self.conv2_1x1(h, train) h = self.conv2_3x3(h, train) h = F.max_pooling_2d(h, ksize=(3, 3), stride=(2, 2), pad=(1, 1)) h = self.inception3a(h, train) h = self.inception3b(h, train) h = self.inception3c(h, train) h = self.inception4a(h, train) h = self.inception4b(h, train) h = self.inception4c(h, train) h = self.inception4d(h, train) h = self.inception4e(h, train) h = self.inception5a(h, train) h = self.inception5b(h, train) num, categories, y, x = h.data.shape # global average pooling h = F.reshape(F.average_pooling_2d(h, (y, x)), (num, categories)) h = self.linear(h) return h
def __call__(self, x): h = F.relu(self.conv1_1(x)) h = F.relu(self.conv1_2(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv2_1(h)) h = F.relu(self.conv2_2(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv3_1(h)) h = F.relu(self.conv3_2(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv4_1(h)) h = F.relu(self.conv4_2(h)) h = F.spatial_pyramid_pooling_2d(h, 3, F.MaxPooling2D) h = F.tanh(self.fc4(h)) h = F.dropout(h, ratio=.5, train=self.train) h = F.tanh(self.fc5(h)) h = F.dropout(h, ratio=.5, train=self.train) h = self.fc6(h) return h
def __call__(self, x, train=True): h = F.relu(self.conv1(x)) h = F.max_pooling_2d(h, ksize=(3, 3), stride=(2, 2), pad=(1, 1)) h = F.relu(self.conv2_1x1(h)) h = F.relu(self.conv2_3x3(h)) h = F.max_pooling_2d(h, ksize=(3, 3), stride=(2, 2), pad=(1, 1)) h = self.inception3a(h) h = self.inception3b(h) h = F.max_pooling_2d(h, ksize=(3, 3), stride=(2, 2), pad=(1, 1)) h = self.inception4a(h) h = self.inception4b(h) h = self.inception4c(h) h = self.inception4d(h) h = self.inception4e(h) h = F.max_pooling_2d(h, ksize=(3, 3), stride=(2, 2), pad=(1, 1)) h = self.inception5a(h) h = F.relu(self.inception5b(h)) num, categories, y, x = h.data.shape # global average pooling h = F.reshape(F.average_pooling_2d(h, (y, x)), (num, categories)) h = F.dropout(h, ratio=0.4, train=train) h = self.linear(h) return h
def __call__(self, x, train=False): h = F.relu(self.conv1(x)) h = F.max_pooling_2d(h, 3, stride=2) h = self.fire2(h) h = self.fire3(h) h = self.fire4(h) h = F.max_pooling_2d(h, 3, stride=2) h = self.fire5(h) h = self.fire6(h) h = self.fire7(h) h = self.fire8(h) h = F.max_pooling_2d(h, 3, stride=2) h = self.fire9(h) h = F.dropout(h, ratio=0.5, train=train) h = F.relu(self.conv10(h)) h = F.average_pooling_2d(h, 13) return F.reshape(h, (-1, 1000))
def __call__(self, x, train=True): h = F.relu(self.conv1(x)) h = F.max_pooling_2d(h, ksize=(2, 2), stride=(2, 2), pad=(0, 0)) h = F.relu(self.conv2(h)) h = F.max_pooling_2d(h, ksize=(2, 2), stride=(2, 2), pad=(0, 0)) h = F.relu(self.conv3_1(h)) h = F.relu(self.conv3_2(h)) h = F.max_pooling_2d(h, ksize=(2, 2), stride=(2, 2), pad=(0, 0)) h = F.relu(self.conv4_1(h)) h = F.relu(self.conv4_2(h)) h = F.max_pooling_2d(h, ksize=(2, 2), stride=(2, 2), pad=(0, 0)) h = F.relu(self.conv5_1(h)) h = F.relu(self.conv5_2(h)) h = F.max_pooling_2d(h, ksize=(2, 2), stride=(2, 2), pad=(0, 0)) h = F.dropout(h, ratio=0.5, train=train) h = F.relu(self.fc1(h)) h = F.dropout(h, ratio=0.5, train=train) h = F.relu(self.fc2(h)) h = self.fc3(h) num, categories, y, x = h.data.shape # global average pooling h = F.reshape(F.average_pooling_2d(h, (y, x)), (num, categories)) return h
def __call__(self, x): self.clear() h = self.conv1(x) h = F.max_pooling_2d(h, (3, 5), stride=2) h = self.conv2(h) h = self.conv3(h) h = F.max_pooling_2d(h, 3, stride=2, pad=1) h = self.conv4(h) h = self.fc1(h) h = self.fc2(h) return h
def h(self, x, train, finetune): # First convolution layer. h = self[0](x) h = F.dropout(h, ratio=self.dropout, train=train) # Residual blocks. for i in range(1, len(self) - 2): h = self[i](h, train, finetune) # Batch normalization. h = self[-2](h, test=not train, finetune=finetune) h = F.relu(h) # Average pooling. h = F.max_pooling_2d(h, ksize=2, pad=0) # Prediction layer 5. h = self[-1](h) h = F.reshape(h, (h.data.shape[0], 5)) return h
def h(self, x, train, finetune): # First convolution layer. h = self[0](x) h = F.dropout(h, ratio=self.dropout, train=train) # Residual blocks. for i in range(1, len(self) - 2): h = self[i](h, train, finetune) # Batch normalization. h = self[-2](h, test=not train, finetune=finetune) h = F.relu(h) # Average pooling. h = F.max_pooling_2d(h, ksize=4, pad=0) # Prediction layer 5. h = self[-1](h) h = F.reshape(h, (h.data.shape[0], 5)) return h
def __call__(self, x, t): self.clear() h = self.bn1(self.conv1(x), test=not self.train) h = F.max_pooling_2d(F.relu(h), 3, stride=2) h = self.res2(h, self.train) h = self.res3(h, self.train) h = self.res4(h, self.train) h = self.res5(h, self.train) h = F.average_pooling_2d(h, 7, stride=1) if t=="feature": return h h = self.fc(h) if self.train: self.loss = F.softmax_cross_entropy(h, t) self.accuracy = F.accuracy(h, t) return self.loss else: return h
def __call__(self, x, t, predict=False): h = self.bn1(self.conv1(x), test=not self.train) h = F.max_pooling_2d(F.relu(h), 2, stride=2) h = self.bn2(self.conv2(h), test=not self.train) h = F.max_pooling_2d(F.relu(h), 2, stride=2) h = F.dropout(F.relu(self.conv3(h)), ratio=0.6, train=self.train) h = F.max_pooling_2d(F.relu(self.conv4(h)), 2, stride=2) h = F.average_pooling_2d(F.relu(self.conv5(h)), 3, stride=1) h = F.dropout(F.relu(self.fc6(h)), ratio=0.6, train=self.train) h = self.fc7(h) self.loss = F.softmax_cross_entropy(h, t) self.accuracy = F.accuracy(h, t) if predict: return h else: return self.loss
def reduct(self, x): h = F.relu(self.conv1_1(x)) h = F.relu(self.bn1(self.conv1_2(h))) # 100 -> 50 h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv2_1(h)) h = F.relu(self.bn2(self.conv2_2(h))) # 50 -> 25 h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv3_1(h)) h = F.relu(self.bn3(self.conv3_2(h))) # 25 -> (25 + 1 * 2 - 3) / 3 + 1 = 9 h = F.max_pooling_2d(h, 3, stride=3, pad=1) h = F.relu(self.conv4_1(h)) h = F.relu(self.bn4(self.conv4_2(h))) # 9 -> 1 h = F.average_pooling_2d(h, 9, stride=1) return h
def reduct(self, x): h = F.relu(self.conv1_1(x)) h = F.relu(self.conv1_2(h)) h = self.bn1(h) # 100 -> 50 h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv2(h)) h = self.bn2(h) # 50 -> 25 h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv3(h)) h = self.bn3(h) # 25 -> (25 + 1 * 2 - 3) / 3 + 1 = 9 h = F.max_pooling_2d(h, 3, stride=3, pad=1) h = F.relu(self.conv4(h)) h = self.bn4(h) # 9 -> 1 h = F.average_pooling_2d(h, 9, stride=1) return h
def __call__(self, x): h = self.st(x) h = F.average_pooling_2d(h, 2, 2) # For TC and RTS datasets h = F.relu(self.conv1(h)) h = F.max_pooling_2d(h, 2, 2) h = F.relu(self.conv2(h)) h = F.max_pooling_2d(h, 2, 2) h = self.fc(h) return h
def affine_matrix(self, x): h = F.max_pooling_2d(x, 2, 2) h = F.relu(self.conv1(h)) h = F.max_pooling_2d(h, 2, 2) h = F.relu(self.conv2(h)) h = F.max_pooling_2d(h, 2, 2) theta = F.reshape(self.fc(h), (x.shape[0], 2, 3)) return theta
def __call__(self, x): h = F.leaky_relu(self.bias1(self.bn1(self.conv1(x), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias2(self.bn2(self.conv2(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias3(self.bn3(self.conv3(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias4(self.bn4(self.conv4(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias5(self.bn5(self.conv5(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias6(self.bn6(self.conv6(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias7(self.bn7(self.conv7(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias8(self.bn8(self.conv8(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias9(self.bn9(self.conv9(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias10(self.bn10(self.conv10(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias11(self.bn11(self.conv11(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias12(self.bn12(self.conv12(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias13(self.bn13(self.conv13(h), finetune=self.finetune)), slope=0.1) high_resolution_feature = h h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias14(self.bn14(self.conv14(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias15(self.bn15(self.conv15(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias16(self.bn16(self.conv16(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias17(self.bn17(self.conv17(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias18(self.bn18(self.conv18(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias19(self.bn19(self.conv19(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias20(self.bn20(self.conv20(h), finetune=self.finetune)), slope=0.1) h2 = high_resolution_feature h2 = F.leaky_relu(self.bias21(self.bn21(self.conv21(h2), finetune=self.finetune)), slope=0.1) h2 = reorg(h2) h = F.concat((h2, h), axis=1) h = F.leaky_relu(self.bias22(self.bn22(self.conv22(h), finetune=self.finetune)), slope=0.1) h = self.bias23(self.conv23(h)) return h
def __call__(self, x): h = F.leaky_relu(self.bias1(self.bn1(self.conv1(x), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.dropout(h, 0.25) h = F.leaky_relu(self.bias2(self.bn2(self.conv2(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.dropout(h, 0.25) h = F.leaky_relu(self.bias3(self.bn3(self.conv3(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias4(self.bn4(self.conv4(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias5(self.bn5(self.conv5(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.dropout(h, 0.25) h = F.leaky_relu(self.bias6(self.bn6(self.conv6(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias7(self.bn7(self.conv7(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias8(self.bn8(self.conv8(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.dropout(h, 0.25) h = F.leaky_relu(self.bias9(self.bn9(self.conv9(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias10(self.bn10(self.conv10(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias11(self.bn11(self.conv11(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias12(self.bn12(self.conv12(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias13(self.bn13(self.conv13(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.dropout(h, 0.25) h = F.leaky_relu(self.bias14(self.bn14(self.conv14(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias15(self.bn15(self.conv15(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias16(self.bn16(self.conv16(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias17(self.bn17(self.conv17(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias18(self.bn18(self.conv18(h), finetune=self.finetune)), slope=0.1) h = F.average_pooling_2d(h, h.shape[-2:]) h = self.fc19(h) return h
def __call__(self, x): h = F.leaky_relu(self.bias1(self.bn1(self.conv1(x), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias2(self.bn2(self.conv2(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias3(self.bn3(self.conv3(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias4(self.bn4(self.conv4(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias5(self.bn5(self.conv5(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias6(self.bn6(self.conv6(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias7(self.bn7(self.conv7(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias8(self.bn8(self.conv8(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias9(self.bn9(self.conv9(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias10(self.bn10(self.conv10(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias11(self.bn11(self.conv11(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias12(self.bn12(self.conv12(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias13(self.bn13(self.conv13(h), finetune=self.finetune)), slope=0.1) high_resolution_feature = h h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias14(self.bn14(self.conv14(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias15(self.bn15(self.conv15(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias16(self.bn16(self.conv16(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias17(self.bn17(self.conv17(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias18(self.bn18(self.conv18(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias19(self.bn19(self.conv19(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias20(self.bn20(self.conv20(h), finetune=self.finetune)), slope=0.1) h2 = high_resolution_feature h2 = F.leaky_relu(self.bias21(self.bn21(self.conv21(h2), finetune=self.finetune)), slope=0.1) h2 = reorg(h2) h = F.concat((h2, h), axis=1) h = F.leaky_relu(self.bias22(self.bn22(self.conv22(h), finetune=self.finetune)), slope=0.1) h = self.bias23(self.conv23(h)) return h
def __call__(self, x): h = F.leaky_relu(self.bias1(self.bn1(self.conv1(x), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias2(self.bn2(self.conv2(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias3(self.bn3(self.conv3(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias4(self.bn4(self.conv4(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias5(self.bn5(self.conv5(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias6(self.bn6(self.conv6(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias7(self.bn7(self.conv7(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias8(self.bn8(self.conv8(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias9(self.bn9(self.conv9(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias10(self.bn10(self.conv10(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias11(self.bn11(self.conv11(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias12(self.bn12(self.conv12(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias13(self.bn13(self.conv13(h), finetune=self.finetune)), slope=0.1) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = F.leaky_relu(self.bias14(self.bn14(self.conv14(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias15(self.bn15(self.conv15(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias16(self.bn16(self.conv16(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias17(self.bn17(self.conv17(h), finetune=self.finetune)), slope=0.1) h = F.leaky_relu(self.bias18(self.bn18(self.conv18(h), finetune=self.finetune)), slope=0.1) h = F.average_pooling_2d(h, h.shape[-2:]) h = self.fc19(h) return h
def __call__(self, x, t=None): h = x h = F.relu(self.conv1_1(h)) h = F.relu(self.conv1_2(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv2_1(h)) h = F.relu(self.conv2_2(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv3_1(h)) h = F.relu(self.conv3_2(h)) h = F.relu(self.conv3_3(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv4_1(h)) h = F.relu(self.conv4_2(h)) h = F.relu(self.conv4_3(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.relu(self.conv5_1(h)) h = F.relu(self.conv5_2(h)) h = F.relu(self.conv5_3(h)) h = F.max_pooling_2d(h, 2, stride=2) h = F.dropout(F.relu(self.fc6(h)), ratio=.5) h = F.dropout(F.relu(self.fc7(h)), ratio=.5) h = self.fc8(h) fc8 = h self.score = fc8 if t is None: assert not chainer.config.train return self.loss = F.softmax_cross_entropy(fc8, t) self.accuracy = F.accuracy(self.score, t) return self.loss
def __call__(self, x, t, train=True, finetune=False): h = self.l1(x, train, finetune) # h = F.dropout(h, self.dr, train) h = F.max(h, axis=-3, keepdims=False) h = self.l2(h, train, finetune) h = F.max(h, axis=-3, keepdims=False) h = F.max_pooling_2d(h, ksize=2, stride=2, pad=0) h = self.l3(h, train, finetune) h = F.max(h, axis=-3, keepdims=False) # h = F.dropout(h, self.dr, train) h = self.l4(h, train, finetune) h = F.max(h, axis=-3, keepdims=False) # h = F.dropout(h, self.dr, train) h = self.l5(h, train, finetune) h = F.max(h, axis=-3, keepdims=False) # h = F.dropout(h, self.dr, train) h = self.l6(h, train, finetune) h = F.max(h, axis=-3, keepdims=False) h = self.top(h) h = F.max(h, axis=-3, keepdims=False) h = F.max(h, axis=-1, keepdims=False) h = F.max(h, axis=-1, keepdims=False) return F.softmax_cross_entropy(h, t), F.accuracy(h, t)
def __call__(self, x): y1 = F.relu(self.conv1_2(F.relu(self.conv1_1(x)))) h = F.max_pooling_2d(y1, 2, stride=2) y2 = F.relu(self.conv2_2(F.relu(self.conv2_1(h)))) h = F.max_pooling_2d(y2, 2, stride=2) y3 = F.relu(self.conv3_3(F.relu(self.conv3_2(F.relu(self.conv3_1(h)))))) h = F.max_pooling_2d(y3, 2, stride=2) y4 = F.relu(self.conv4_3(F.relu(self.conv4_2(F.relu(self.conv4_1(h)))))) return [y1, y2, y3, y4]
def __call__(self, x): h = F.relu(self.bn1(self.conv1(x))) h = F.max_pooling_2d(h, 3, stride=2, pad=0) return h
def __call__(self, x, t, before_fc=False): self.clear() h = self.bn1(self.conv1(x), test=not self.train) h = F.max_pooling_2d(F.relu(h), 3, stride=2) h = self.res2(h, self.train) h = self.res3(h, self.train) h = self.res4(h, self.train) h = self.res5(h, self.train) h = F.average_pooling_2d(h, h.data.shape[2], stride=1) self.feature = h return h
def __call__(self, x, train=False): h = self.conv_bn_relu(x, train=train) h = F.max_pooling_2d(h, (3, 3), (2, 2), (1, 1)) for i, n in enumerate(self.block_num): for ii in six.moves.range(n): h = self['resnext_block_{}_{}'.format(i, ii)](h, train=train) batch, channels, height, width = h.data.shape h = F.reshape(F.average_pooling_2d(h, (height, width)), (batch, channels)) return self.linear(h, train)
def plane_group_spatial_max_pooling(x, ksize, stride=None, pad=0, cover_all=True, use_cudnn=True): xs = x.data.shape x = F.reshape(x, (xs[0], xs[1] * xs[2], xs[3], xs[4])) x = F.max_pooling_2d(x, ksize, stride, pad, cover_all, use_cudnn) x = F.reshape(x, (xs[0], xs[1], xs[2], x.data.shape[2], x.data.shape[3])) return x
def __call__(self, x): layer_names = ['1_1', '1_2', 'pool', '2_1', '2_2', 'pool', '3_1', '3_2', '3_3', 'pool', '4_1', '4_2', '4_3'] layers = {} h = x for layer_name in layer_names: if layer_name == 'pool': h = F.max_pooling_2d(h, 2, stride=2) else: h = F.relu(self['conv' + layer_name](h)) layers[layer_name] = h return layers
def __call__(self, x): layer_names = ['1_1', '1_2', 'pool', '2_1', '2_2', 'pool', '3_1', '3_2', '3_3', '3_4', 'pool', '4_1', '4_2', '4_3', '4_4', 'pool', '5_1', '5_2', '5_3', '5_4'] layers = {} h = x for layer_name in layer_names: if layer_name == 'pool': h = F.max_pooling_2d(h, 2, stride=2) else: h = F.relu(self['conv' + layer_name](h)) layers[layer_name] = h return layers
def forward(self, ws, cs, ls, dep_ts=None): batchsize = len(ws) xp = chainer.cuda.get_array_module(ws[0]) ws = map(self.emb_word, ws) cs = [F.squeeze( F.max_pooling_2d( self.conv_char( F.expand_dims( self.emb_char(c), 1)), (int(l[0]), 1))) for c, l in zip(cs, ls)] xs_f = [F.dropout(F.concat([w, c]), self.dropout_ratio, train=self.train) for w, c in zip(ws, cs)] xs_b = [x[::-1] for x in xs_f] cx_f, hx_f, cx_b, hx_b = self._init_state(xp, batchsize) _, _, hs_f = self.lstm_f(hx_f, cx_f, xs_f, train=self.train) _, _, hs_b = self.lstm_b(hx_b, cx_b, xs_b, train=self.train) hs_b = [x[::-1] for x in hs_b] hs = [F.concat([h_f, h_b]) for h_f, h_b in zip(hs_f, hs_b)] dep_ys = [self.biaffine_arc( F.elu(F.dropout(self.arc_dep(h), 0.32, train=self.train)), F.elu(F.dropout(self.arc_head(h), 0.32, train=self.train))) for h in hs] if dep_ts is not None: heads = dep_ts else: heads = [F.argmax(y, axis=1) for y in dep_ys] cat_ys = [ self.biaffine_tag( F.elu(F.dropout(self.rel_dep(h), 0.32, train=self.train)), F.elu(F.dropout(self.rel_head( F.embed_id(t, h, ignore_label=IGNORE)), 0.32, train=self.train))) \ for h, t in zip(hs, heads)] return cat_ys, dep_ys
def forward(self, ws, cs, ls): """ xs [(w,s,p,y), ..., ] w: word, c: char, l: length, y: label """ batchsize = len(ws) # cs: [(sentence length, max word length)] ws = map(self.emb_word, ws) # ls: [(sentence length, char dim)] # before conv: (sent len, 1, max word len, char_size) # after conv: (sent len, char_size, max word len, 1) # after max_pool: (sent len, char_size, 1, 1) cs = [F.squeeze( F.max_pooling_2d( self.conv_char( F.expand_dims( self.emb_char(c), 1)), (l, 1))) for c, l in zip(cs, ls)] # [(sentence length, (word_dim + char_dim))] xs_f = [F.dropout(F.concat([w, c]), self.dropout_ratio, train=self.train) for w, c in zip(ws, cs)] xs_b = [x[::-1] for x in xs_f] cx_f, hx_f, cx_b, hx_b = self._init_state(batchsize) _, _, hs_f = self.lstm_f(hx_f, cx_f, xs_f, train=self.train) _, _, hs_b = self.lstm_b(hx_b, cx_b, xs_b, train=self.train) hs_b = [x[::-1] for x in hs_b] # ys: [(sentence length, number of category)] hs = [F.concat([h_f, h_b]) for h_f, h_b in zip(hs_f, hs_b)] cat_ys = [self.linear_cat2(F.relu(self.linear_cat1(h))) for h in hs] dep_ys = [self.biaffine( F.relu(F.dropout(self.linear_dep(h), 0.32, train=self.train)), F.relu(F.dropout(self.linear_head(h), 0.32, train=self.train))) for h in hs] return cat_ys, dep_ys
def forward(self, ws, cs): batchsize, length, max_word_len = cs.shape ws = self.emb_word(ws) # (batch, length, word_dim) cs = F.reshape( F.max_pooling_2d( self.conv_char( F.reshape( self.emb_char(cs), (batchsize * length, 1, max_word_len, 50))), (max_word_len, 1)), (batchsize, length, self.char_dim)) hs = F.transpose(F.concat([ws, cs], 2), (1, 0, 2)) hs = F.dropout(hs, self.dropout_ratio, train=self.train) hs = F.split_axis(hs, length, 0) hs_f = [] hs_b = [] self._init_state() for h_in_f, h_in_b in zip(hs, reversed(hs)): h_f = self.lstm_f2(self.lstm_f1(F.reshape(h_in_f, (batchsize, -1)))) hs_f.append(h_f) h_b = self.lstm_b2(self.lstm_b1(F.reshape(h_in_b, (batchsize, -1)))) hs_b.append(h_b) hs = [F.concat([h_f, h_b]) for h_f, h_b in zip(hs_f, reversed(hs_b))] cat_ys = [self.linear_cat2(F.dropout( F.elu(self.linear_cat1(h)), 0.5, train=self.train)) for h in hs] hs = [F.reshape(h, (length, -1)) for h in \ F.split_axis(F.transpose(F.stack(hs, 2), (0, 2, 1)), batchsize, 0)] dep_ys = [self.biaffine( F.relu(F.dropout(self.linear_dep(h), 0.32, train=self.train)), F.relu(F.dropout(self.linear_head(h), 0.32, train=self.train))) for h in hs] return cat_ys, dep_ys
def __call__(self, x, train=True): h = F.max_pooling_2d(self.bn2(F.relu(self.conv1(x))), 3, stride=3) h = F.max_pooling_2d(self.bn4(F.relu(self.conv3(h))), 3, stride=3) h = F.max_pooling_2d(self.bn6(F.relu(self.conv5(h))), 2, stride=2) h = F.dropout(F.relu(self.fc7(h)), train=train) h = F.dropout(F.relu(self.fc8(h)), train=train) y = self.fc9(h) return y
def __call__(self, x): x = x/255. h = F.relu(self.conv1(x)) h = F.relu(self.conv2(h)) h = F.relu(self.conv3(h)) #h = F.max_pooling_2d(F.relu(self.bnorm4(self.conv4(h))), 2, stride=2) h = F.relu(self.fc1(h)) y = self.fc2(h) return y