Exemplo n.º 1
0
def test_sequential_convolution_without_reduction_dim():
    c = Convolution(3, init=np.array([4., 2., 1.], dtype=np.float32), sequential=True, pad=False, reduction_rank=0, bias=False)
    c.update_signature(Sequence[Tensor[()]])  # input is a sequence of scalars
    data = [np.array([2., 6., 4., 8., 6.])]   # like a short audio sequence, in the dynamic dimension
    out = c(data)
    exp = [[24., 40., 38.]]
    np.testing.assert_array_equal(out, exp, err_msg='Error in sequential convolution without reduction dimension')

    c = Convolution(3, init=np.array([4., 2., 1.], dtype=np.float32), sequential=True, pad=False, reduction_rank=0, bias=False)
    c.update_signature(Sequence[Tensor[1]]) # input is a sequence of dim-1 vectors
    data = [np.array([[2.], [6], [4.], [8.], [6.]])]
    out = c(data)
    exp = [[[24.], [40.], [38]]] # not reducing; hence, output is also a sequence of dim-1 vectors
    np.testing.assert_array_equal(out, exp, err_msg='Error in sequential convolution without reduction dimension')

    # these cases failed before
    emb_dim = 10
    x = input(**Sequence[Tensor[20]])
    m = Embedding(emb_dim)(x)
    m = Convolution(filter_shape=3, sequential=True)(m)

    # this one still fails
    # Reshape: Operand (sub-)dimensions '[3]' incompatible with desired replacement (sub-)dimensions '[]'. Number of elements must be the same..
    m = Embedding(emb_dim)(x)
    m = reshape(m, (emb_dim,1))
    m = Convolution(filter_shape=(3,1), num_filters=13, pad=True, sequential=True)(m)

    m = Embedding(emb_dim)(x)
    m = Convolution(filter_shape=3, pad=True, sequential=True)(m)
Exemplo n.º 2
0
def test_sequential_convolution_without_reduction_dim():
    c = Convolution(3, init=np.array([4., 2., 1.], dtype=np.float32), sequential=True, pad=False, reduction_rank=0, bias=False)
    c.update_signature(Sequence[Tensor[()]])  # input is a sequence of scalars
    data = [np.array([2., 6., 4., 8., 6.])]   # like a short audio sequence, in the dynamic dimension
    out = c(data)
    exp = [[24., 40., 38.]]
    np.testing.assert_array_equal(out, exp, err_msg='Error in sequential convolution without reduction dimension')

    c = Convolution(3, init=np.array([4., 2., 1.], dtype=np.float32), sequential=True, pad=False, reduction_rank=0, bias=False)
    c.update_signature(Sequence[Tensor[1]]) # input is a sequence of dim-1 vectors
    data = [np.array([[2.], [6], [4.], [8.], [6.]])]
    out = c(data)
    exp = [[[24.], [40.], [38]]] # not reducing; hence, output is also a sequence of dim-1 vectors
    np.testing.assert_array_equal(out, exp, err_msg='Error in sequential convolution without reduction dimension')

    # these cases failed before
    emb_dim = 10
    x = C.input_variable(**Sequence[Tensor[20]])
    m = Embedding(emb_dim)(x)
    m = Convolution(filter_shape=3, sequential=True)(m)

    # this one still fails
    # Reshape: Operand (sub-)dimensions '[3]' incompatible with desired replacement (sub-)dimensions '[]'. Number of elements must be the same..
    m = Embedding(emb_dim)(x)
    m = reshape(m, (emb_dim,1))
    m = Convolution(filter_shape=(3,1), num_filters=13, pad=True, sequential=True)(m)

    m = Embedding(emb_dim)(x)
    m = Convolution(filter_shape=3, pad=True, sequential=True)(m)
Exemplo n.º 3
0
def test_failing_convolution():
    with pytest.raises(ValueError):
        conv = Convolution((3,3), 1)
        conv.update_signature(5)
    # BUGBUG: fails with "ValueError: Variable(Plus5_output) with unknown shape detected when compiling the Function graph!"
    #print(out)

    # ----------------------------------------------
    # sequential convolution without reduction dimension
    # ----------------------------------------------

    from cntk.layers import Convolution
    c = Convolution(3,
                    init=array([4, 2, 1]),
                    sequential=True,
                    pad=False,
                    reduction_rank=0,
                    bias=False)
    dump_function(c)
    c.update_signature(1)
    dump_function(c)
    data = [  # audio sequence
        array([[2], [6], [4], [8], [6]])
    ]
    out = c(data)
    print(out)
    # [[[[ 24.  40.  38.]]]]

    # ----------------------------------------------
    # 1D convolution without reduction dimension
    # ----------------------------------------------

    from cntk.layers import Convolution
    c = Convolution(3,
                    init=array([4, 2, 1]),
Exemplo n.º 5
0
def test_failing_convolution():
    with pytest.raises(ValueError):
        conv = Convolution((3,3), 1)
        conv.update_signature(5)
Exemplo n.º 6
0
    debughelpers.dump_function(r)
    data = [   # simple sequence
        array([[2], [6], [4], [8], [6]])
    ]
    #out = r(data)
    # BUGBUG: fails with "ValueError: Variable(Plus5_output) with unknown shape detected when compiling the Function graph!"
    #print(out)

    # ----------------------------------------------
    # sequential convolution without reduction dimension
    # ----------------------------------------------

    from cntk.layers import Convolution
    c = Convolution(3, init=array([4, 2, 1]), sequential=True, pad=False, reduction_rank=0, bias=False)
    debughelpers.dump_function(c)
    c.update_signature(1)
    debughelpers.dump_function(c)
    data = [   # audio sequence
        array([[2], [6], [4], [8], [6]])
    ]
    out = c(data)
    print(out)
    # [[[[ 24.  40.  38.]]]]

    # ----------------------------------------------
    # 1D convolution without reduction dimension
    # ----------------------------------------------

    from cntk.layers import Convolution
    c = Convolution(3, init=array([4, 2, 1]), pad=True, reduction_rank=0, bias=False)
    # BUGBUG: pad seems ignored??