I'm trying to make a "custom" convolutional layer in Theano
, where instead of linear filters convoluted with an image, I'm applying sup- or inf- convolutions (essentially dilations and erosions). How would I go in writing such a convolution in an efficient way?
Given a tensor X
intended to contain a set of vectors as inputs, its dilation with a filter W
can be written as
dil, _ = theano.scan(fn = lambda x: T.max(W + x), sequences=[X])
The problem is that I don't know how to properly apply this operation to subregions of an image taking into account padding, tensor slicing etc. for filters of arbitrary size. I also read in the documentation that using scan
to implement convolutions is pretty inefficient. Any idea on how to do this?