Skip to content

Commit

Permalink
Merge branch 'dev' into numpy2_reintro
Browse files Browse the repository at this point in the history
  • Loading branch information
ericspod authored Feb 12, 2025
2 parents 1689c12 + af9e8f9 commit 7b75792
Show file tree
Hide file tree
Showing 841 changed files with 1,412 additions and 1,324 deletions.
1 change: 0 additions & 1 deletion monai/transforms/io/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"""
A collection of "vanilla" transforms for IO functions.
"""

from __future__ import annotations

import inspect
Expand Down
4 changes: 2 additions & 2 deletions runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ if [ $doDistTests = true ]
then
echo "${separator}${blue}run distributed unit test cases${noColor}"
torch_validate
for i in tests/test_*_dist.py
for i in $(find ./tests/ -name "*_dist.py")
do
echo "$i"
${cmdPrefix}${cmd} "$i"
Expand All @@ -740,7 +740,7 @@ if [ $doNetTests = true ]
then
set +e # disable exit on failure so that diagnostics can be given on failure
echo "${separator}${blue}integration${noColor}"
for i in tests/*integration_*.py
for i in tests/integration/*.py
do
echo "$i"
${cmdPrefix}${cmd} "$i"
Expand Down
10 changes: 10 additions & 0 deletions tests/apps/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
10 changes: 10 additions & 0 deletions tests/apps/deepedit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/apps/deepgrow/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/apps/deepgrow/transforms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/apps/detection/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
10 changes: 10 additions & 0 deletions tests/apps/detection/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/apps/detection/networks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from monai.networks import eval_mode
from monai.networks.nets import resnet10, resnet18, resnet34, resnet50, resnet101, resnet152, resnet200
from monai.utils import ensure_tuple, optional_import
from tests.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_onnx_save, test_script_save
from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_onnx_save, test_script_save

_, has_torchvision = optional_import("torchvision")

Expand Down Expand Up @@ -101,7 +101,6 @@
@unittest.skipUnless(has_torchvision, "Requires torchvision")
@skip_if_quick
class TestRetinaNet(unittest.TestCase):

@parameterized.expand(TEST_CASES)
def test_retina_shape(self, model, input_param, input_shape):
backbone = model(**input_param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from monai.apps.detection.utils.anchor_utils import AnchorGeneratorWithAnchorShape
from monai.networks import eval_mode, train_mode
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save
from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save

_, has_torchvision = optional_import("torchvision")

Expand Down Expand Up @@ -93,7 +93,6 @@


class NaiveNetwork(torch.nn.Module):

def __init__(self, spatial_dims, num_classes, **kwargs):
super().__init__()
self.spatial_dims = spatial_dims
Expand All @@ -115,7 +114,6 @@ def forward(self, images):
@unittest.skipUnless(has_torchvision, "Requires torchvision")
@skip_if_quick
class TestRetinaNetDetector(unittest.TestCase):

@parameterized.expand(TEST_CASES)
def test_retina_detector_resnet_backbone_shape(self, input_param, input_shape):
returned_layers = [1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)
from monai.data.meta_tensor import MetaTensor
from monai.transforms import CastToTyped, Invertd
from tests.utils import TEST_NDARRAYS, assert_allclose
from tests.test_utils import TEST_NDARRAYS, assert_allclose

TESTS_3D = []
boxes = [[0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 3, 3], [0, 1, 1, 2, 3, 4]]
Expand Down Expand Up @@ -79,7 +79,6 @@


class TestBoxTransform(unittest.TestCase):

@parameterized.expand(TESTS_2D_mask)
def test_value_2d_mask(self, mask, expected_box_label):
box_label = convert_mask_to_box(mask)
Expand Down
10 changes: 10 additions & 0 deletions tests/apps/detection/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from monai.apps.detection.utils.anchor_utils import AnchorGenerator, AnchorGeneratorWithAnchorShape
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion, assert_allclose, test_script_save
from tests.test_utils import SkipIfBeforePyTorchVersion, assert_allclose, test_script_save

_, has_torchvision = optional_import("torchvision")

Expand All @@ -42,7 +42,6 @@
@SkipIfBeforePyTorchVersion((1, 11))
@unittest.skipUnless(has_torchvision, "Requires torchvision")
class TestAnchorGenerator(unittest.TestCase):

@parameterized.expand(TEST_CASES_2D)
def test_anchor_2d(self, input_param, image_shape, feature_maps_shapes):
torch_anchor_utils, _ = optional_import("torchvision.models.detection.anchor_utils")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from monai.apps.detection.utils.ATSS_matcher import ATSSMatcher
from monai.data.box_utils import box_iou
from tests.utils import assert_allclose
from tests.test_utils import assert_allclose

TEST_CASES = [
[
Expand All @@ -33,7 +33,6 @@


class TestATSS(unittest.TestCase):

@parameterized.expand(TEST_CASES)
def test_atss(self, input_param, boxes, anchors, num_anchors_per_level, num_anchors_per_loc, expected_matches):
matcher = ATSSMatcher(**input_param, debug=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

from monai.apps.detection.utils.box_coder import BoxCoder
from monai.transforms import CastToType
from tests.utils import assert_allclose
from tests.test_utils import assert_allclose


class TestBoxTransform(unittest.TestCase):

def test_value(self):
box_coder = BoxCoder(weights=[1, 1, 1, 1, 1, 1])
test_dtype = [torch.float32, torch.float16]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.apps.detection.utils.box_selector import BoxSelector
from tests.utils import assert_allclose
from tests.test_utils import assert_allclose

device = "cuda" if torch.cuda.is_available() else "cpu"
num_anchors = 7
Expand Down Expand Up @@ -56,7 +56,6 @@


class TestBoxSelector(unittest.TestCase):

@parameterized.expand(TEST_CASE)
def test_box_selector(self, input_param, boxes, logits, image_shape, expected_results):
box_selector = BoxSelector(**input_param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from monai.apps.detection.utils.detector_utils import preprocess_images
from monai.utils import ensure_tuple
from tests.utils import assert_allclose
from tests.test_utils import assert_allclose

TEST_CASE_1 = [ # 3D, batch 3, 2 input channel
{
Expand Down Expand Up @@ -79,7 +79,6 @@


class TestDetectorUtils(unittest.TestCase):

@parameterized.expand(TEST_CASES)
def test_detector_utils(self, input_param, input_shape, expected_shape):
size_divisible = 32 * ensure_tuple(input_param["conv1_t_stride"])[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from parameterized import parameterized

from monai.apps.detection.utils.hard_negative_sampler import HardNegativeSampler
from tests.utils import assert_allclose
from tests.test_utils import assert_allclose

TEST_CASE = [
[[], [], [], [torch.tensor([]), torch.tensor([])], [torch.tensor([]), torch.tensor([])]],
Expand All @@ -37,7 +37,6 @@


class TestSampleSlices(unittest.TestCase):

@parameterized.expand(TEST_CASE)
def test_shape(self, target_label0, target_label1, concat_fg_probs, expected_result_pos, expected_result_neg):
compute_dtypes = [torch.float16, torch.float32]
Expand Down
10 changes: 10 additions & 0 deletions tests/apps/maisi/networks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.apps.generation.maisi.networks.autoencoderkl_maisi import AutoencoderKlMaisi
from monai.networks import eval_mode
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion
from tests.test_utils import SkipIfBeforePyTorchVersion

tqdm, has_tqdm = optional_import("tqdm", name="tqdm")
_, has_einops = optional_import("einops")
Expand Down Expand Up @@ -77,7 +77,6 @@


class TestAutoencoderKlMaisi(unittest.TestCase):

@parameterized.expand(CASES)
def test_shape(self, input_param, input_shape, expected_shape, expected_latent_shape):
net = AutoencoderKlMaisi(**input_param).to(device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from monai.apps.generation.maisi.networks.controlnet_maisi import ControlNetMaisi
from monai.networks import eval_mode
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion
from tests.test_utils import SkipIfBeforePyTorchVersion

_, has_einops = optional_import("einops")

Expand Down Expand Up @@ -129,7 +129,6 @@

@SkipIfBeforePyTorchVersion((2, 0))
class TestControlNet(unittest.TestCase):

@parameterized.expand(TEST_CASES)
@skipUnless(has_einops, "Requires einops")
def test_shape_unconditioned_models(self, input_param, expected_num_down_blocks_residuals, expected_shape):
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/apps/nuclick/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/apps/pathology/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
10 changes: 10 additions & 0 deletions tests/apps/pathology/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from parameterized import parameterized

from monai.apps.pathology.handlers.utils import from_engine_hovernet
from tests.utils import assert_allclose
from tests.test_utils import assert_allclose

TEST_CASE_0 = [
[{"A": {"C": 1, "D": 2}, "B": {"C": 2, "D": 2}}, {"A": {"C": 3, "D": 2}, "B": {"C": 4, "D": 2}}],
Expand All @@ -28,7 +28,6 @@


class TestFromEngineHovernet(unittest.TestCase):

@parameterized.expand(CASES)
def test_results(self, input, expected):
output = from_engine_hovernet(keys=["A", "B"], nested_key="C")(input)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from monai.apps.pathology.engines import PrepareBatchHoVerNet
from monai.engines import SupervisedEvaluator
from monai.utils.enums import HoVerNetBranch
from tests.utils import assert_allclose
from tests.test_utils import assert_allclose

TEST_CASE_0 = [
{"extra_keys": ["extra_label1", "extra_label2"]},
Expand All @@ -35,7 +35,6 @@ def forward(self, x: torch.Tensor):


class TestPrepareBatchHoVerNet(unittest.TestCase):

@parameterized.expand([TEST_CASE_0])
def test_content(self, input_args, expected_value):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from monai.data import MetaTensor
from monai.inferers import sliding_window_inference
from monai.utils import optional_import
from tests.test_sliding_window_inference import TEST_CASES
from tests.inferers.test_sliding_window_inference import TEST_CASES

_, has_tqdm = optional_import("tqdm")

Expand All @@ -36,7 +36,6 @@


class TestSlidingWindowHoVerNetInference(unittest.TestCase):

@parameterized.expand(TEST_CASES_PADDING)
def test_sliding_window_with_padding(
self, key, image_shape, roi_shape, sw_batch_size, overlap, mode, device, extra_input_padding
Expand Down
Loading

0 comments on commit 7b75792

Please sign in to comment.