titu1994/keras-coordconv

Simplifying the coordinate grid

ahundt opened this issue · 2 comments

Can creating the coordinate grid be greatly simplified with something like the following (after a few tweaks)?

        y_shape, x_shape, c_shape = K.int_shape(input)
        y, x = tf.meshgrid(K.arange(y_shape),
                           K.arange(x_shape),
                           indexing='ij')

I'm not sure if the output should be normalized to [0,1], but that's easily achieved by dividing y by the y_shape and x by the x_shape, as long as its all been converted to floats.

BTW I think it is amazing that you implement so many of the most interesting papers within days/weeks of them being released. :-)

That is extremely convenient, but limited to TF backend only. Actually, I wouldn't even mind just sticking to TF since it has so many useful functions for this case, but since I wrote it as a Keras layer, it's only fit to support the other backends :D

There are quite a few gists out there with much more efficient forms written in TF, which I should probably compile into a TF only type layer. In that case, your version would probably be the most succinct.

Haha I've kinda slowed down these days cause I have a lot less time, so I have to be a bit more picky about what I spend my time on. This just piqued my attention cause it was far too simple to extend to a 1D case, which I felt was useful in a side project. Turns out, not much use over there.

Still, was fun to implement and extend :P