Example #1
0
def test_conv_border_mode(impl):
    import lasagne.theano_extensions.conv
    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()

    with pytest.raises(Exception):
        conv(X, W, (1, 1, 10), (2, 1, 3), border_mode=None)
Example #2
0
def test_conv_stride(impl):
    import lasagne.theano_extensions.conv
    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()

    with pytest.raises(Exception):
        conv(X, W, (1, 1, 10), (2, 1, 3), subsample=(2, ))
Example #3
0
def test_conv_invalid_border_mode(impl):
    import lasagne.theano_extensions.conv
    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()

    with pytest.raises(Exception):
        conv(X, W, (1, 1, 10), (2, 1, 3), border_mode=None)
Example #4
0
def test_conv_stride(impl):
    import lasagne.theano_extensions.conv
    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()

    with pytest.raises(Exception):
        conv(X, W, (1, 1, 10), (2, 1, 3), subsample=(2,))
Example #5
0
def test_conv(impl, stride, filter_flip):
    import lasagne.theano_extensions.conv
    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()
    input = lasagne.utils.floatX(np.ones((1, 1, 10)))
    kernel = lasagne.utils.floatX(np.random.uniform(-1, 1, (2, 1, 6)))

    conv_theano = conv(X, W, input.shape, kernel.shape, subsample=(stride,),
                       filter_flip=filter_flip).eval({X: input, W: kernel})

    conv_np = conv1d(input, kernel, stride)

    assert np.allclose(conv_theano, conv_np)
Example #6
0
def test_conv_nones(impl):
    import lasagne.theano_extensions.conv
    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()
    input = lasagne.utils.floatX(np.ones((1, 1, 12)))
    kernel = lasagne.utils.floatX(np.random.uniform(-1, 1, (2, 1, 3)))

    conv_theano = conv(X, W, None, None).eval({
        X: input, W: kernel
        })

    conv_np = conv1d(input, kernel)

    assert np.allclose(conv_theano, conv_np)
Example #7
0
def test_conv_pad(impl, pad):
    import lasagne.theano_extensions.conv
    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()
    input = lasagne.utils.floatX(np.ones((1, 1, 12)))
    kernel = lasagne.utils.floatX(np.random.uniform(-1, 1, (2, 1, 3)))

    conv_theano = conv(X, W, input.shape, kernel.shape, border_mode=pad).eval({
        X: input, W: kernel
        })

    pad = pad[0] if isinstance(pad, tuple) else pad
    input = np.pad(input, [(0, 0), (0, 0), (pad, pad)], mode='constant')
    conv_np = conv1d(input, kernel)

    assert np.allclose(conv_theano, conv_np)
Example #8
0
def test_conv_nones(impl):
    import lasagne.theano_extensions.conv
    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()
    input = lasagne.utils.floatX(np.ones((1, 1, 12)))
    kernel = lasagne.utils.floatX(np.random.uniform(-1, 1, (2, 1, 3)))

    conv_theano = conv(X, W, None, None).eval({X: input, W: kernel})

    output = []
    for b in input:
        temp = []
        for c in kernel:
            temp.append(np.convolve(b[0, :], c[0, :], mode='valid'))
        output.append(temp)
    conv_np = np.array(output)

    assert np.allclose(conv_theano, conv_np)
def test_conv_nones(impl):
    import lasagne.theano_extensions.conv

    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()
    input = lasagne.utils.floatX(np.ones((1, 1, 12)))
    kernel = lasagne.utils.floatX(np.random.uniform(-1, 1, (2, 1, 3)))

    conv_theano = conv(X, W, None, None).eval({X: input, W: kernel})

    output = []
    for b in input:
        temp = []
        for c in kernel:
            temp.append(np.convolve(b[0, :], c[0, :], mode="valid"))
        output.append(temp)
    conv_np = np.array(output)

    assert np.allclose(conv_theano, conv_np)
def test_conv(impl, stride):
    import lasagne.theano_extensions.conv

    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()
    input = lasagne.utils.floatX(np.ones((1, 1, 10)))
    kernel = lasagne.utils.floatX(np.random.uniform(-1, 1, (2, 1, 6)))

    conv_theano = conv(X, W, input.shape, kernel.shape, subsample=(stride,)).eval({X: input, W: kernel})

    output = []
    for b in input:
        temp = []
        for c in kernel:
            temp.append(np.convolve(b[0, :], c[0, :], mode="valid"))
        output.append(temp)
    conv_np = np.array(output)[:, :, ::stride]

    assert np.allclose(conv_theano, conv_np)
Example #11
0
def test_conv(impl, stride):
    import lasagne.theano_extensions.conv
    conv = getattr(lasagne.theano_extensions.conv, impl)

    X = T.tensor3()
    W = T.tensor3()
    input = lasagne.utils.floatX(np.ones((1, 1, 10)))
    kernel = lasagne.utils.floatX(np.random.uniform(-1, 1, (2, 1, 6)))

    conv_theano = conv(X, W, input.shape, kernel.shape,
                       subsample=(stride, )).eval({
                           X: input,
                           W: kernel
                       })

    output = []
    for b in input:
        temp = []
        for c in kernel:
            temp.append(np.convolve(b[0, :], c[0, :], mode='valid'))
        output.append(temp)
    conv_np = np.array(output)[:, :, ::stride]

    assert np.allclose(conv_theano, conv_np)