I am trying to make a function/module that takes an array of some shape and pads all pixels by a given amount:
a = torch.arange(1, 5).expand(4, -1)
print(a)
b = dilate(a)
print(b)
Output:
tensor([[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4]])
tensor([[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 2, 0, 3, 0, 4, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 2, 0, 3, 0, 4, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 2, 0, 3, 0, 4, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 2, 0, 3, 0, 4, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0])
I don’t believe this functionality exists in pytorch? How would I best implement this without “for” loops?