Merge pull request #2362 from MengzhangLI/scipy_1.x

[Enhance] Make scipy as a default dependency in runtime in dev-1.x
This commit is contained in:
Miao Zheng 2022-11-30 23:14:01 +08:00 committed by GitHub
commit 383826fec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 9 deletions

View File

@ -11,6 +11,7 @@ from mmengine.model import BaseModule, ModuleList
from mmengine.model.weight_init import (constant_init, kaiming_init,
trunc_normal_)
from mmengine.runner.checkpoint import _load_checkpoint
from scipy import interpolate
from torch.nn.modules.batchnorm import _BatchNorm
from torch.nn.modules.utils import _pair as to_2tuple
@ -18,11 +19,6 @@ from mmseg.registry import MODELS
from ..utils import PatchEmbed
from .vit import TransformerEncoderLayer as VisionTransformerEncoderLayer
try:
from scipy import interpolate
except ImportError:
interpolate = None
class BEiTAttention(BaseModule):
"""Window based multi-head self-attention (W-MSA) module with relative

View File

@ -3,3 +3,4 @@ mmcls>=1.0.0rc0
numpy
packaging
prettytable
scipy

View File

@ -140,6 +140,9 @@ def test_beit_init():
}
}
model = BEiT(img_size=(512, 512))
# If scipy is installed, this AttributeError would not be raised.
from mmengine.utils import is_installed
if not is_installed('scipy'):
with pytest.raises(AttributeError):
model.resize_rel_pos_embed(ckpt)

View File

@ -138,6 +138,9 @@ def test_mae_init():
}
}
model = MAE(img_size=(512, 512))
# If scipy is installed, this AttributeError would not be raised.
from mmengine.utils import is_installed
if not is_installed('scipy'):
with pytest.raises(AttributeError):
model.resize_rel_pos_embed(ckpt)