How can I get 1D convolution in anano

The only function I can find is the 2D convolution described here ...

Is there an optimized 1D function?

+6
source share
3 answers

While I believe that there is no conv1d , Lasagne (the neural network library on top of theano) has several Conv1D level implementations. Some of them are based on the conv2d function with one of the sizes equal to 1, some use one or more point products. I would try all of them, maybe based on the dot product would work better than conv2d with width=1 .

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

+2
source

It looks like it's under development . I realized that I can use the conv2d() function, specifying the width or height as 1 ...

For conv2d() the image_shape parameter accepts a list of length 4, containing:

 ([number_images,] height, width) 

by setting height=1 or width=1 , it forces it to perform a 1D convolution.

+3
source

To be more specific, I found this to work well:

 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.

+3
source

Source: https://habr.com/ru/post/987231/


All Articles