我能找到的唯一函数是用于2D卷积的,可以在这里查看...
是否有任何经过优化的1D函数?
看起来这个还在开发中,详情请参考这里。
我已经意识到可以通过将宽度或高度指定为1来使用conv2d()
函数...
对于conv2d()
函数,参数image_shape
需要一个长度为4的列表,其中包含:
([number_images,] height, width)
height=1
或者width=1
,可以强制将其转换为一维卷积。尽管我认为 theano 中没有 conv1d
,但 Lasagne(基于 theano 的神经网络库)有几个 Conv1D 层的实现。其中一些基于 theano 的 conv2d
函数,其中一个维度等于 1,有些使用单个或多个点积。我会尝试它们所有,也许基于点积的方法比 conv2d
和 width=1
表现更好。
https://github.com/Lasagne/Lasagne/blob/master/lasagne/theano_extensions/conv.py
为了更具体说明,我发现这个方法效果不错:
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.