by 0-_-0 · 6y ago · 0 comments
def boxfilter(image, N=3):
shape = image.shape
image = tf.reshape(image, [1, shape[0], shape[1], -1])
C = image.shape[-1]
conv = tf.nn.conv2d(image, tf.eye(C, C, [N, N]), 1, "SAME")[0]
return tf.reshape(conv, shape) / (N * N)
Is there a simple way to do this in Pytorch? Preferably without having to inherit from the base class for convolution. It seems to me that Pytorch is like Keras and Tensorflow is like Numpy.https://pytorch.org/docs/master/nn.functional.html#conv2d
Torch doesn't have "same" padding, so you have to manually calculate the correct padding value for your input/output shapes.