Nonlinear convolution in Theano
Asked Answered
A

0

11

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?

Arran answered 20/2, 2017 at 13:39 Comment(2)
Looks like this should be a feature request. Theano lacks a general way to define a translation-invariant (could be nonlinear) filter. But if the filter radius is small, I think converting each ROI into a row vector, then perform filtering in a matrix fashion can be a hackish solution.Chou
@Chou thanks for your reply! Would you happen to know if there is such a feature in Tensorflow or some other symbolic computation library?Arran

© 2022 - 2024 — McMap. All rights reserved.