How can I get a 1D convolution in theano

北城余情 提交于 2019-12-19 18:18:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!