问题
The only function I can find is for 2D convolutions described here...
Is there any optimised 1D function ?
回答1:
While I believe there's no conv1d
in theano, Lasagne (a neural network library on top of theano) has several implementations of Conv1D layer. Some are based on conv2d
function of theano with one of the dimensions equal to 1, some use single or multiple dot products. I would try all of them, may be a dot-product based ones will perform better than conv2d
with width=1
.
https://github.com/Lasagne/Lasagne/blob/master/lasagne/theano_extensions/conv.py
回答2:
It looks as though this is in development.
I've realised I can use the conv2d()
function by specifying either width or height as 1...
For the function conv2d()
, the parameter image_shape
takes a list of length 4 containing:
([number_images,] height, width)
by setting height=1
or width=1
it forces it to a 1D convolution.
回答3:
Just to be a bit more specific, I found this to work nicely:
conv2d = T.signal.conv.conv2d
x = T.dmatrix()
y = T.dmatrix()
veclen = x.shape[1]
conv1d_expr = conv2d(x, y, image_shape=(1, veclen), border_mode='full')
conv1d = theano.function([x, y], outputs=conv1d_expr)
border_mode = 'full'
is optional.
来源:https://stackoverflow.com/questions/30247061/how-can-i-get-a-1d-convolution-in-theano