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

[Fix] Fix saconv #1147

Merged
merged 5 commits into from
Jul 2, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions mmcv/ops/saconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def forward(self, x):
switch = self.switch(avg_x)
# sac
weight = self._get_weight(self.weight)
zero_bias = torch.zeros(
self.out_channels, device=weight.device, dtype=weight.dtype)

if self.use_deform:
offset = self.offset_s(avg_x)
out_s = deform_conv2d(x, offset, weight, self.stride, self.padding,
Expand All @@ -106,7 +109,8 @@ def forward(self, x):
if TORCH_VERSION < '1.5.0' or TORCH_VERSION == 'parrots':
out_s = super().conv2d_forward(x, weight)
else:
out_s = super()._conv_forward(x, weight)
# bias is a required argument of _conv_forward in torch 1.9.0
out_s = super()._conv_forward(x, weight, zero_bias)
ZwwWayne marked this conversation as resolved.
Show resolved Hide resolved
ori_p = self.padding
ori_d = self.dilation
self.padding = tuple(3 * p for p in self.padding)
Expand All @@ -120,7 +124,8 @@ def forward(self, x):
if TORCH_VERSION < '1.5.0' or TORCH_VERSION == 'parrots':
out_l = super().conv2d_forward(x, weight)
else:
out_l = super()._conv_forward(x, weight)
# bias is a required argument of _conv_forward in torch 1.9.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bias is also required by torch1.8. You can check the version of torch to handle this

out_l = super()._conv_forward(x, weight, zero_bias)
out = switch * out_s + (1 - switch) * out_l
self.padding = ori_p
self.dilation = ori_d
Expand Down