我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用chainer.functions.spatial_pyramid_pooling_2d()。
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): return functions.spatial_pyramid_pooling_2d(x, self.pyramid_height, self.pooling_class)
def check_forward(self, x_data, use_cudnn=True): x = chainer.Variable(x_data) y = functions.spatial_pyramid_pooling_2d( x, self.pyramid_height, self.pooling_class, 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)
def check_forward_ones(self, x_data, use_cudnn=True): x = chainer.Variable(x_data) y = functions.spatial_pyramid_pooling_2d( x, self.pyramid_height, self.pooling_class, use_cudnn=use_cudnn) y_data = cuda.to_cpu(y.data) self.assertEqual(y_data.shape, (self.n, self.output_dim, 1, 1)) self.assertEqual(y_data.dtype, self.dtype) gradient_check.assert_allclose(y_data, numpy.ones_like(y_data))
def check_invalid_dtype(self): functions.spatial_pyramid_pooling_2d( self.v, 3, functions.MaxPooling2D)
def forward(self): x = chainer.Variable(self.x) return functions.spatial_pyramid_pooling_2d( x, 3, functions.MaxPooling2D, use_cudnn=self.use_cudnn)
def __init__(self, pyramid_height, pooling_class, use_cudnn=True): self._function = "spatial_pyramid_pooling_2d" self.pyramid_height = pyramid_height self.pooling_class = pooling_class self.use_cudnn = use_cudnn
def __call__(self, x): return F.spatial_pyramid_pooling_2d(x, self.pyramid_height, self.pooling_class, self.use_cudnn)
def __call__(self, x): h = F.elu(self.conv1(x)) h = F.max_pooling_2d(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.spatial_pyramid_pooling_2d(h, 3, F.MaxPooling2D) h = F.elu(self.conv2(h)) h = F.dropout(h, ratio=0.5) h = self.conv3(h) h = F.reshape(h, (-1, self.num_class)) return h
def _spatial_pyramid_pooling_2d(x): return F.spatial_pyramid_pooling_2d(x, 4, F.MaxPooling2D)