Created
July 21, 2020 08:18
-
-
Save l-bat/0808ef5ad1866a1901bf1284f09aac29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rpn_head = MultiRPN(anchor_num=5,in_channels=[256, 256, 256],weighted=False)