I’m trying to expand a dense tensor into a dilated one with zero weights to fill the new holes. Suppose I have a [N,K,K] tensor, where N is the number of features and K is the kernel size. A dilated kernel with dilation D will have effective kernel size L=K*(K-1)*(D-1). I want to map [N,K,K] -> [N,L,L], which is essentially blowing up the kernel along the first dimension to create the dilated pattern, while setting the newly inserted entries to zero.
Is there an easy way to perform such an operation in PyTorch? Right now I’m manually figuring out all non-zero dilation indices by looping over the effective kernel window, which is quite inefficient. I’m thinking there’s a way to do this with a smart combination of expand/reshape, but I’m not seeing it.