简体   繁体   English

我怎样才能在theano中获得一维卷积

[英]How can I get a 1D convolution in theano

The only function I can find is for 2D convolutions described here ... 我能找到的唯一功能是这里描述的 2D卷积...

Is there any optimised 1D function ? 有没有优化的1D功能?

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... 我已经意识到我可以通过将宽度或高度指定为1来使用conv2d()函数...

For the function conv2d() , the parameter image_shape takes a list of length 4 containing: 对于函数conv2d() ,参数image_shape采用长度为4的列表,其中包含:

([number_images,] height, width)

by setting height=1 or width=1 it forces it to a 1D convolution. 通过设置height=1width=1它会强制它进行1D卷积。

While I believe there's no conv1d in theano, Lasagne (a neural network library on top of theano) has several implementations of Conv1D layer. 虽然我相信conv1d中没有conv1d ,但Lasagne(theano顶部的神经网络库)有几个Conv1D层的实现。 Some are based on conv2d function of theano with one of the dimensions equal to 1, some use single or multiple dot products. 一些基于conv2d函数,其中一个维度等于1,一些使用单个或多个点积。 I would try all of them, may be a dot-product based ones will perform better than conv2d with width=1 . 我会尝试所有这些,可能是基于点的产品conv2d width=1 conv2d表现更好。

https://github.com/Lasagne/Lasagne/blob/master/lasagne/theano_extensions/conv.py https://github.com/Lasagne/Lasagne/blob/master/lasagne/theano_extensions/conv.py

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. border_mode = 'full'是可选的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM