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] Check the version of torchvision in __init__ of DCN #2556

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 4 additions & 6 deletions mmcv/ops/deform_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,9 @@ def _load_from_state_dict(self, state_dict, prefix, local_metadata, strict,

if IS_MLU_AVAILABLE:
import torchvision
from torchvision.ops import deform_conv2d as tv_deform_conv2d

from mmcv.utils import digit_version
assert digit_version(torchvision.__version__) >= digit_version(
'0.10.0a0'), 'the version of torchvision should be >= 0.10.0'

from torchvision.ops import deform_conv2d as tv_deform_conv2d

@CONV_LAYERS.register_module('DCN', force=True)
class DeformConv2dPack_MLU(DeformConv2d):
Expand Down Expand Up @@ -471,6 +468,8 @@ class DeformConv2dPack_MLU(DeformConv2d):
"""

def __init__(self, *args, **kwargs):
assert digit_version(torchvision.__version__) >= digit_version(
'0.10.0a0'), 'the version of torchvision should be >= 0.10.0'
super().__init__(*args, **kwargs)

self.conv_offset = nn.Conv2d(
Expand All @@ -494,7 +493,6 @@ def forward(self, x: Tensor) -> Tensor: # type: ignore
) == 0, 'batch size must be divisible by im2col_step'
offset = self.conv_offset(x)
x = x.type_as(offset)
weight = self.weight
weight = weight.type_as(x)
weight = self.weight.type_as(x)
return tv_deform_conv2d(x, offset, weight, None, self.stride,
self.padding, self.dilation)
6 changes: 3 additions & 3 deletions mmcv/ops/modulated_deform_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,9 @@ def _load_from_state_dict(self, state_dict, prefix, local_metadata, strict,

if IS_MLU_AVAILABLE:
import torchvision
from torchvision.ops import deform_conv2d as tv_deform_conv2d

from mmcv.utils import digit_version
assert digit_version(torchvision.__version__) >= digit_version(
'0.10.0a0'), 'the version of torchvision should be >= 0.10.0'
from torchvision.ops import deform_conv2d as tv_deform_conv2d

@CONV_LAYERS.register_module('DCNv2', force=True)
class ModulatedDeformConv2dPack_MLU(ModulatedDeformConv2d):
Expand All @@ -383,6 +381,8 @@ class ModulatedDeformConv2dPack_MLU(ModulatedDeformConv2d):
"""

def __init__(self, *args, **kwargs):
assert digit_version(torchvision.__version__) >= digit_version(
'0.10.0a0'), 'the version of torchvision should be >= 0.10.0'
super().__init__(*args, **kwargs)
self.conv_offset = nn.Conv2d(
self.in_channels,
Expand Down