def forward(self, bottom, top): """Computes the forward pass.""" features = bottom[0].data() output = top[0].init_data(features.shape, features.dtype) scale = self._scale.init_data(features.shape, features.dtype) if self._size > features.shape[-1]: raise base.DecafError('Incorrect size: should be smaller than ' 'the number of input channels.') wrapper.lrn_forward(features, output, scale, self._size, self._k, self._alpha, self._beta)
def testLocalResponseNormalizationForward(self): np.random.seed(1701) dtypes = [np.float32, np.float64] for dtype in dtypes: features = np.random.rand(5, 10).astype(dtype) output = np.random.rand(5, 10).astype(dtype) scale = np.random.rand(5, 10).astype(dtype) # odd size, k = 1 wrapper.lrn_forward(features, output, scale, 5, 1., 1.5, 0.75) output_ref, scale_ref = self.reference_forward_implementation( features, 5, 1., 1.5, 0.75) np.testing.assert_array_almost_equal(output, output_ref) np.testing.assert_array_almost_equal(scale, scale_ref) # odd size, k = 2 wrapper.lrn_forward(features, output, scale, 5, 2., 1.5, 0.75) output_ref, scale_ref = self.reference_forward_implementation( features, 5, 2., 1.5, 0.75) np.testing.assert_array_almost_equal(output, output_ref) np.testing.assert_array_almost_equal(scale, scale_ref) # even size wrapper.lrn_forward(features, output, scale, 6, 1., 1.5, 0.75) output_ref, scale_ref = self.reference_forward_implementation( features, 6, 1., 1.5, 0.75) np.testing.assert_array_almost_equal(output, output_ref) np.testing.assert_array_almost_equal(scale, scale_ref)