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

SamePad() for even sized filters. #2431

Open
JohnAshburner opened this issue May 1, 2024 · 0 comments
Open

SamePad() for even sized filters. #2431

JohnAshburner opened this issue May 1, 2024 · 0 comments

Comments

@JohnAshburner
Copy link

Motivation and description

It would be nice if (strided) Conv and ConvTranspose were the adjoint of each other when SamePad() is used. This is not the case for even-sized filters - unless the padding is manually specified for Conv.

x = randn(Float32,8,8,1,1);
y = randn(Float32,16,16,1,1);

w  = [0.2500, 0.7500, 0.7500, 0.2500];
d  = length(w);

P  = ConvTranspose((d,d),1=>1; pad=SamePad(), stride=2);
P.weight[:,:,1,1] .= w*w';

R = Conv((d,d),1=>1; pad=SamePad(), stride=2);
R.weight[:,:,1,1] .= w*w';

# Should be 0 if one is the adjoint of the other
sum(y.*P(x)) - sum(x.*R(y)) # Incorrect

# Assess whether the positioning is treated symmetrically at the left vs right edges.
Px = P(ones(Float32,size(x)));
Ry = R(ones(Float32,size(y)));
sum((Px .- reverse(Px)).^2) # All good
sum((Ry .- reverse(Ry)).^2) # Not symmetric


# Manually specified padding
R = Conv((d,d),1=>1; pad=(1,2,1,2), stride=2);
R.weight[:,:,1,1] .= w*w';

sum(y.*P(x)) - sum(x.*R(y)) # Better

Ry = R(ones(Float32,size(y)));
sum((Ry .- reverse(Ry)).^2) # All good

Possible Implementation

No response

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

1 participant