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

Method _conv_same_pad

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

Source from the content-addressed store, hash-verified

147 self._conv2d_helper(gpu_dev)
148
149 def _conv_same_pad(self, dev, pad_mode, is_2d):
150 if is_2d:
151 x_h, w_h, k_h, p_h = 32, 4, 4, 1
152 else:
153 x_h, w_h, k_h, p_h = 1, 1, 1, 0
154
155 x = tensor.Tensor(shape=(3, 3, x_h, 32), device=dev)
156 x.gaussian(0.0, 1.0)
157
158 # with the same padding, the padding should be 3
159 # for SAME_UPPER, is (1, 1) + (0, 1)
160 # for SAME_LOWER, is (1, 1) + (1, 0)
161
162 kernel = (k_h, 4)
163 padding = (p_h, 1)
164 stride = (1, 1)
165 group = 1
166 bias = False
167 out_channels = 3
168
169 conv_0 = layer.Conv2d(out_channels,
170 kernel,
171 stride=stride,
172 group=group,
173 bias=bias,
174 pad_mode=pad_mode)
175
176 y = conv_0(x)
177 dy = np.ones((3, 3, x_h, 32), dtype=np.float32)
178 dy = tensor.from_numpy(dy)
179 dy.to_device(dev)
180
181 dx, dW = y.creator.backward(dy.data)
182 self.check_shape(y.shape, (3, 3, x_h, 32))
183 self.check_shape(dx.shape(), (3, 3, x_h, 32))
184 self.check_shape(dW.shape(), (3, 3, w_h, 4))
185
186 def test_conv2d_same_pad_cpu(self):
187 self._conv_same_pad(cpu_dev, "SAME_LOWER", True)

Callers 4

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