Skip to content
Merged
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
rev: v2.38.2
hooks:
- id: pyupgrade
args: [--py37-plus]
Expand All @@ -40,7 +40,7 @@ repos:
)$

- repo: https://github.com/asottile/yesqa
rev: v1.3.0
rev: v1.4.0
hooks:
- id: yesqa
name: Unused noqa
Expand All @@ -58,7 +58,7 @@ repos:
)$

- repo: https://github.com/hadialqattan/pycln
rev: v1.3.5
rev: v2.1.1
hooks:
- id: pycln
args: [--config=pyproject.toml]
Expand Down
2 changes: 1 addition & 1 deletion monai/bundle/config_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_component_module_name(self, name: str) -> Optional[Union[List[str], str]
# init component and module mapping table
self._components_table = self._find_classes_or_functions(self._find_module_names())

mods: Optional[Union[List[str], str]] = self._components_table.get(name, None)
mods: Optional[Union[List[str], str]] = self._components_table.get(name)
if isinstance(mods, list) and len(mods) == 1:
mods = mods[0]
return mods
Expand Down
2 changes: 1 addition & 1 deletion monai/data/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, dataset: Dataset, num_workers: int = 0, **kwargs) -> None:
# when num_workers > 0, random states are determined by worker_init_fn
# this is to make the behavior consistent when num_workers == 0
# torch.int64 doesn't work well on some versions of windows
_g = torch.random.default_generator if kwargs.get("generator", None) is None else kwargs["generator"]
_g = torch.random.default_generator if kwargs.get("generator") is None else kwargs["generator"]
init_seed = _g.initial_seed()
_seed = torch.empty((), dtype=torch.int64).random_(generator=_g).item()
set_rnd(dataset, int(_seed))
Expand Down
6 changes: 0 additions & 6 deletions monai/data/wsi_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,6 @@ class OpenSlideWSIReader(BaseWSIReader):
supported_suffixes = ["tif", "tiff", "svs"]
backend = "openslide"

def __init__(self, level: int = 0, channel_dim: int = 0, **kwargs):
super().__init__(level, channel_dim, **kwargs)

@staticmethod
def get_level_count(wsi) -> int:
"""
Expand Down Expand Up @@ -702,9 +699,6 @@ class TiffFileWSIReader(BaseWSIReader):
supported_suffixes = ["tif", "tiff", "svs"]
backend = "tifffile"

def __init__(self, level: int = 0, channel_dim: int = 0, **kwargs):
super().__init__(level, channel_dim, **kwargs)

@staticmethod
def get_level_count(wsi) -> int:
"""
Expand Down
2 changes: 1 addition & 1 deletion monai/networks/blocks/feature_pyramid_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,6 @@ def forward(self, x: Dict[str, Tensor]) -> Dict[str, Tensor]:
results, names = self.extra_blocks(results, x_values, names)

# make it back an OrderedDict
out = OrderedDict([(k, v) for k, v in zip(names, results)])
out = OrderedDict(list(zip(names, results)))

return out
12 changes: 6 additions & 6 deletions monai/networks/blocks/fft_utils_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ def ifftn_centered_t(ksp: Tensor, spatial_dims: int, is_complex: bool = True) ->
output2 = ifftn_centered(ksp, spatial_dims=2, is_complex=True)
"""
# define spatial dims to perform ifftshift, fftshift, and ifft
shift = [i for i in range(-spatial_dims, 0)] # noqa: C416
shift = list(range(-spatial_dims, 0))
if is_complex:
if ksp.shape[-1] != 2:
raise ValueError(f"ksp.shape[-1] is not 2 ({ksp.shape[-1]}).")
shift = [i for i in range(-spatial_dims - 1, -1)] # noqa: C416
dims = [i for i in range(-spatial_dims, 0)] # noqa: C416
shift = list(range(-spatial_dims - 1, -1))
dims = list(range(-spatial_dims, 0))

x = ifftshift(ksp, shift)

Expand Down Expand Up @@ -187,12 +187,12 @@ def fftn_centered_t(im: Tensor, spatial_dims: int, is_complex: bool = True) -> T
output2 = fftn_centered(im, spatial_dims=2, is_complex=True)
"""
# define spatial dims to perform ifftshift, fftshift, and fft
shift = [i for i in range(-spatial_dims, 0)] # noqa: C416
shift = list(range(-spatial_dims, 0))
if is_complex:
if im.shape[-1] != 2:
raise ValueError(f"img.shape[-1] is not 2 ({im.shape[-1]}).")
shift = [i for i in range(-spatial_dims - 1, -1)] # noqa: C416
dims = [i for i in range(-spatial_dims, 0)] # noqa: C416
shift = list(range(-spatial_dims - 1, -1))
dims = list(range(-spatial_dims, 0))

x = ifftshift(im, shift)

Expand Down
2 changes: 1 addition & 1 deletion monai/networks/layers/weight_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def trunc_normal_(tensor, mean=0.0, std=1.0, a=-2.0, b=2.0):
b: the maximum cutoff value
"""

if not std > 0:
if std <= 0:
raise ValueError("the standard deviation should be greater than zero.")

if a >= b:
Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/utility/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def __call__(
output = []
results = [self.splitter(d[key]) for key in all_keys]
for row in zip(*results):
new_dict = {k: v for k, v in zip(all_keys, row)}
new_dict = dict(zip(all_keys, row))
# fill in the extra keys with unmodified data
for k in set(d.keys()).difference(set(all_keys)):
new_dict[k] = deepcopy(d[k])
Expand Down
2 changes: 0 additions & 2 deletions monai/transforms/utils_create_transform_ims.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,6 @@ def create_transform_im(
seed = seed + 1 if isinstance(transform, MapTransform) else seed
transform.set_random_state(seed)

from monai.utils.misc import MONAIEnvVars

out_dir = MONAIEnvVars.doc_images()
if out_dir is None:
raise RuntimeError(
Expand Down
4 changes: 2 additions & 2 deletions monai/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class MONAIEnvVars:

@staticmethod
def data_dir() -> Optional[str]:
return os.environ.get("MONAI_DATA_DIRECTORY", None)
return os.environ.get("MONAI_DATA_DIRECTORY")

@staticmethod
def debug() -> bool:
Expand All @@ -406,7 +406,7 @@ def debug() -> bool:

@staticmethod
def doc_images() -> Optional[str]:
return os.environ.get("MONAI_DOC_IMAGES", None)
return os.environ.get("MONAI_DOC_IMAGES")


class ImageMetaKey:
Expand Down
1 change: 0 additions & 1 deletion tests/test_apply_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def test_3d(self):
],
]
)
expected = expected
# testing shapes
k = torch.tensor([[[1, 1, 1], [1, 1, 1], [1, 1, 1]]])
for kernel in (k, k[None], k[None][None]):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_fpn_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.networks.blocks.feature_pyramid_network import FeaturePyramidNetwork
from monai.networks.nets.resnet import resnet50
from monai.utils import optional_import
from tests.utils import test_script_save
from tests.utils import SkipIfBeforePyTorchVersion, test_script_save

_, has_torchvision = optional_import("torchvision")

Expand Down Expand Up @@ -53,6 +53,7 @@ def test_fpn_block(self, input_param, input_shape, expected_shape):
self.assertEqual(result["feat1"].shape, expected_shape[1])

@parameterized.expand(TEST_CASES)
@SkipIfBeforePyTorchVersion((1, 9, 1))
def test_script(self, input_param, input_shape, expected_shape):
# test whether support torchscript
net = FeaturePyramidNetwork(**input_param)
Expand All @@ -73,6 +74,7 @@ def test_fpn(self, input_param, input_shape, expected_shape):
self.assertEqual(result["pool"].shape, expected_shape[1])

@parameterized.expand(TEST_CASES2)
@SkipIfBeforePyTorchVersion((1, 9, 1))
def test_script(self, input_param, input_shape, expected_shape):
# test whether support torchscript
net = _resnet_fpn_extractor(backbone=resnet50(), spatial_dims=input_param["spatial_dims"], returned_layers=[1])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
@skip_if_no_cuda
class GMMTestCase(unittest.TestCase):
def setUp(self):
self._var = os.environ.get("TORCH_EXTENSIONS_DIR", None)
self._var = os.environ.get("TORCH_EXTENSIONS_DIR")
self.tempdir = tempfile.mkdtemp()
os.environ["TORCH_EXTENSIONS_DIR"] = self.tempdir

Expand Down
2 changes: 1 addition & 1 deletion tests/test_k_space_spike_noised.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_data(im_shape, im_type):
create_test_image = create_test_image_2d if len(im_shape) == 2 else create_test_image_3d
ims = create_test_image(*im_shape, rad_max=20, noise_max=0.0, num_seg_classes=5)
ims = [im_type(im[None]) for im in ims]
return {k: v for k, v in zip(KEYS, ims)}
return dict(zip(KEYS, ims))

@parameterized.expand(TESTS)
def test_same_result(self, im_shape, im_type):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_monai_env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestMONAIEnvVars(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(__class__, cls).setUpClass()
cls.orig_value = os.environ.get("MONAI_DEBUG", None)
cls.orig_value = os.environ.get("MONAI_DEBUG")

@classmethod
def tearDownClass(cls):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rand_k_space_spike_noised.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_data(im_shape, im_type):
create_test_image = create_test_image_2d if len(im_shape) == 2 else create_test_image_3d
ims = create_test_image(*im_shape, rad_max=20, noise_max=0.0, num_seg_classes=5)
ims = [im_type(im[None]) for im in ims]
return {k: v for k, v in zip(KEYS, ims)}
return dict(zip(KEYS, ims))

@parameterized.expand(TESTS)
def test_same_result(self, im_shape, im_type):
Expand Down
1 change: 0 additions & 1 deletion tests/test_separable_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def test_3d(self):
],
]
)
expected = expected
# testing shapes
k = torch.tensor([1, 1, 1])
for kernel in (k, [k] * 3):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestTransform(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(__class__, cls).setUpClass()
cls.orig_value = os.environ.get("MONAI_DEBUG", None)
cls.orig_value = os.environ.get("MONAI_DEBUG")

@classmethod
def tearDownClass(cls):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_varnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from monai.apps.reconstruction.networks.nets.complex_unet import ComplexUnet
from monai.apps.reconstruction.networks.nets.varnet import VariationalNetworkModel
from monai.networks import eval_mode
from tests.utils import test_script_save
from tests.utils import SkipIfBeforePyTorchVersion, test_script_save

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
coil_sens_model = CoilSensitivityModel(spatial_dims=2, features=[8, 16, 32, 64, 128, 8])
Expand All @@ -43,6 +43,7 @@ def test_shape(self, coil_sens_model, refinement_model, num_cascades, input_shap
self.assertEqual(result.shape, expected_shape)

@parameterized.expand(TESTS)
@SkipIfBeforePyTorchVersion((1, 9, 1))
def test_script(self, coil_sens_model, refinement_model, num_cascades, input_shape, expected_shape):
net = VariationalNetworkModel(coil_sens_model, refinement_model, num_cascades)

Expand Down