MCPcopy Create free account
hub / github.com/apache/singa / _pooling_same_pad

Method _pooling_same_pad

test/python/test_operation.py:204–232  ·  view source on GitHub ↗
(self, dev, pad_mode, is_2d)

Source from the content-addressed store, hash-verified

202 self._conv_same_pad(gpu_dev, "SAME_UPPER", False)
203
204 def _pooling_same_pad(self, dev, pad_mode, is_2d):
205 if is_2d:
206 x_h, k_h, p_h = 32, 4, 1
207 else:
208 x_h, k_h, p_h = 1, 1, 0
209
210 x = tensor.Tensor(shape=(3, 3, x_h, 32), device=dev)
211 x.gaussian(0.0, 1.0)
212
213 # with the same padding, the padding should be 3
214 # for SAME_UPPER, is (1, 1) + (0, 1)
215 # for SAME_LOWER, is (1, 1) + (1, 0)
216
217 kernel = (k_h, 4)
218 # we add 4 padding here and hope the conv and trim one padding then
219 padding = (p_h, 1)
220 stride = (1, 1)
221
222 pooling = layer.Pooling2d(kernel, stride=stride, pad_mode=pad_mode)
223
224 y = pooling(x)
225
226 dy = np.ones((3, 3, x_h, 32), dtype=np.float32)
227 dy = tensor.from_numpy(dy)
228 dy.to_device(dev)
229
230 dx = y.creator.backward(dy.data)
231 self.check_shape(y.shape, (3, 3, x_h, 32))
232 self.check_shape(dx.shape(), (3, 3, x_h, 32))
233
234 def test_pooling2d_same_pad_cpu(self):
235 self._pooling_same_pad(cpu_dev, "SAME_LOWER", True)

Calls 6

gaussianMethod · 0.95
check_shapeMethod · 0.95
TensorMethod · 0.80
shapeMethod · 0.80
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected