Skip to content

Instantly share code, notes, and snippets.

@l-bat
Created July 21, 2020 08:18
Show Gist options
  • Select an option

  • Save l-bat/0808ef5ad1866a1901bf1284f09aac29 to your computer and use it in GitHub Desktop.

Select an option

Save l-bat/0808ef5ad1866a1901bf1284f09aac29 to your computer and use it in GitHub Desktop.
def xcorr_depthwise(x, kernel):
"""
Deptwise convolution for input and weights with the same shapes
Elementwise multiplication -> GlobalAveragePooling -> scalar mul on (kernel_h * kernel_w)
"""
# batch = kernel.size(0) # in our model batch = 1
# channel = kernel.size(1)
# x = x.view(1, batch*channel, x.size(2), x.size(3)) # batch already = 1
# kernel = kernel.view(batch*channel, 1, kernel.size(2), kernel.size(3))
coeff = kernel.size(2) * kernel.size(3)
prod = coeff * x * kernel # Elementwise multiplication with coeff = kernel_h * kernel_w
pool = torch.mean(prod, dim=(2, 3), keepdim=True)
# pool = F.adaptive_avg_pool2d(prod, (kernel.size(2), kernel.size(3)))
# out = out.view(batch, channel, out.size(2), out.size(3))
return pool
@l-bat
Copy link
Author

l-bat commented Jul 21, 2020

rpn_head = MultiRPN(anchor_num=5,in_channels=[256, 256, 256],weighted=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment