def test_1D_convolution_without_reduction_dim(): c = Convolution1D(3, init=np.array([4, 2, 1]), pad=True, reduction_rank=0, bias=False) c.update_signature(5) data = [np.array([[2, 6, 4, 8, 6]])] # like a audio sequence, in a static dimension out = c(data) exp = [[10, 24, 40, 38, 44]] np.testing.assert_array_equal(out, exp, err_msg='Error in 1D convolution without reduction dimension') # Failing call with pytest.raises(ValueError): Convolution1D((2,3))
def test_layers_convolution_1d(): inC, inW = 1, 3 y = C.input_variable((inC, inW)) dat = np.ones([1, inC, inW], dtype = np.float32) model = Convolution1D((3, ), num_filters=1, activation=None, pad=False, strides=1, name='foo') # shape should be model_shape = model(y).foo.shape np.testing.assert_array_equal(model_shape, (1, 1), \ "Error in convolution1D with stride = 1 and padding") res = model(y).eval({y: dat}) expected_res = np.sum(model.foo.W.value) np.testing.assert_array_almost_equal(res[0][0][0], expected_res, decimal=5, \ err_msg="Error in convolution1D computation with stride = 1 and zeropad = True")