Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transIII_1x1_kxk does not behave as expected #9

Closed
CoinCheung opened this issue Apr 5, 2021 · 2 comments
Closed

transIII_1x1_kxk does not behave as expected #9

CoinCheung opened this issue Apr 5, 2021 · 2 comments

Comments

@CoinCheung
Copy link

Hi,

I verified like this:

conv1 = nn.Conv2d(32, 64, 1, 1, 0, bias=True)
conv2 = nn.Conv2d(64, 128, 3, 1, 1, bias=True)
conv = nn.Conv2d(32, 128, 3, 1, 1, bias=True)

k, b = transIII_1x1_kxk(conv1.weight, conv1.bias, conv2.weight, conv2.bias, 1)
conv.weight.copy_(k)
conv.bias.copy_(b)
inten = torch.randn(2, 32, 224, 224)
out1 = conv2(conv1(inten))
out2 = conv(inten)
print((out1 - out2).abs().max())

And the output is 0.11, which is much too great. Have you noticed this ?

@CoinCheung CoinCheung changed the title transIII_1x1_kxk is not behave as expected transIII_1x1_kxk does not behave as expected Apr 5, 2021
@DingXiaoH
Copy link
Owner

This is due to the padding.
In the paper, we explained this.
Notably, for a K×K conv that zero-pads the input, Eq. 8
does not hold because F (2) does not convolve on the result
of I ~ F (1) + REP(b(1)) (but an additional circle of zero
pixels). The solution is to either A) configure the first conv
with padding and the second without, or B) pad by b(1). An
efficient implementation of the latter is customizing the first
BN to 1) batch-normalize the input as usual, 2) calculate
b(1) (Eq. 6), 3) pad the batch-normalized result with b(1),
i.e., pad every channel j with a circle of b(1) j instead of 0.

In this repo, BNAndPadLayer is designed to solve this problem.

@CoinCheung
Copy link
Author

Thanks for replying !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants