monai-weekly 1.5.dev2509__py3-none-any.whl → 1.5.dev2511__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. monai/__init__.py +1 -1
  2. monai/_version.py +3 -3
  3. monai/apps/deepedit/interaction.py +1 -1
  4. monai/apps/deepgrow/interaction.py +1 -1
  5. monai/apps/detection/networks/retinanet_detector.py +1 -1
  6. monai/apps/detection/networks/retinanet_network.py +5 -5
  7. monai/apps/detection/utils/box_coder.py +2 -2
  8. monai/apps/generation/maisi/networks/autoencoderkl_maisi.py +4 -0
  9. monai/apps/mmars/mmars.py +1 -1
  10. monai/apps/reconstruction/networks/blocks/varnetblock.py +1 -1
  11. monai/bundle/scripts.py +3 -4
  12. monai/data/dataset.py +2 -9
  13. monai/data/utils.py +1 -1
  14. monai/data/video_dataset.py +1 -1
  15. monai/engines/evaluator.py +11 -16
  16. monai/engines/trainer.py +11 -17
  17. monai/engines/utils.py +1 -1
  18. monai/engines/workflow.py +2 -2
  19. monai/fl/client/monai_algo.py +1 -1
  20. monai/handlers/checkpoint_loader.py +1 -1
  21. monai/inferers/inferer.py +33 -13
  22. monai/inferers/merger.py +16 -13
  23. monai/losses/perceptual.py +1 -1
  24. monai/losses/sure_loss.py +1 -1
  25. monai/networks/blocks/crossattention.py +1 -6
  26. monai/networks/blocks/feature_pyramid_network.py +4 -2
  27. monai/networks/blocks/selfattention.py +1 -6
  28. monai/networks/blocks/upsample.py +3 -11
  29. monai/networks/layers/vector_quantizer.py +2 -2
  30. monai/networks/nets/hovernet.py +5 -4
  31. monai/networks/nets/resnet.py +2 -2
  32. monai/networks/nets/senet.py +1 -1
  33. monai/networks/nets/swin_unetr.py +46 -49
  34. monai/networks/nets/transchex.py +3 -2
  35. monai/networks/nets/vista3d.py +7 -7
  36. monai/networks/schedulers/__init__.py +1 -0
  37. monai/networks/schedulers/rectified_flow.py +322 -0
  38. monai/networks/utils.py +5 -4
  39. monai/transforms/intensity/array.py +1 -1
  40. monai/transforms/spatial/array.py +6 -6
  41. monai/utils/misc.py +1 -1
  42. monai/utils/state_cacher.py +1 -1
  43. {monai_weekly-1.5.dev2509.dist-info → monai_weekly-1.5.dev2511.dist-info}/METADATA +4 -3
  44. {monai_weekly-1.5.dev2509.dist-info → monai_weekly-1.5.dev2511.dist-info}/RECORD +66 -64
  45. {monai_weekly-1.5.dev2509.dist-info → monai_weekly-1.5.dev2511.dist-info}/WHEEL +1 -1
  46. tests/bundle/test_bundle_download.py +16 -6
  47. tests/config/test_cv2_dist.py +1 -2
  48. tests/inferers/test_controlnet_inferers.py +96 -32
  49. tests/inferers/test_diffusion_inferer.py +99 -1
  50. tests/inferers/test_latent_diffusion_inferer.py +217 -211
  51. tests/integration/test_integration_bundle_run.py +2 -4
  52. tests/integration/test_integration_classification_2d.py +1 -1
  53. tests/integration/test_integration_fast_train.py +2 -2
  54. tests/integration/test_integration_segmentation_3d.py +1 -1
  55. tests/metrics/test_compute_multiscalessim_metric.py +3 -3
  56. tests/metrics/test_surface_dice.py +3 -3
  57. tests/networks/nets/test_autoencoderkl.py +1 -1
  58. tests/networks/nets/test_controlnet.py +1 -1
  59. tests/networks/nets/test_diffusion_model_unet.py +1 -1
  60. tests/networks/nets/test_network_consistency.py +1 -1
  61. tests/networks/nets/test_swin_unetr.py +1 -1
  62. tests/networks/nets/test_transformer.py +1 -1
  63. tests/networks/schedulers/test_scheduler_rflow.py +105 -0
  64. tests/networks/test_save_state.py +1 -1
  65. {monai_weekly-1.5.dev2509.dist-info → monai_weekly-1.5.dev2511.dist-info}/LICENSE +0 -0
  66. {monai_weekly-1.5.dev2509.dist-info → monai_weekly-1.5.dev2511.dist-info}/top_level.txt +0 -0
@@ -128,7 +128,7 @@ class TestSWINUNETR(unittest.TestCase):
128
128
  data_spec["url"], weight_path, hash_val=data_spec["hash_val"], hash_type=data_spec["hash_type"]
129
129
  )
130
130
 
131
- ssl_weight = torch.load(weight_path)["model"]
131
+ ssl_weight = torch.load(weight_path, weights_only=True)["model"]
132
132
  net = SwinUNETR(**input_param)
133
133
  dst_dict, loaded, not_loaded = copy_model_state(net, ssl_weight, filter_func=filter_swinunetr)
134
134
  assert_allclose(dst_dict[key][:8], value, atol=1e-4, rtol=1e-4, type_test=False)
@@ -101,7 +101,7 @@ class TestDecoderOnlyTransformer(unittest.TestCase):
101
101
  weight_path = os.path.join(tmpdir, filename)
102
102
  download_url(url=url, filepath=weight_path, hash_val=hash_val, hash_type=hash_type)
103
103
 
104
- net.load_old_state_dict(torch.load(weight_path), verbose=False)
104
+ net.load_old_state_dict(torch.load(weight_path, weights_only=True), verbose=False)
105
105
 
106
106
 
107
107
  if __name__ == "__main__":
@@ -0,0 +1,105 @@
1
+ # Copyright (c) MONAI Consortium
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software
7
+ # distributed under the License is distributed on an "AS IS" BASIS,
8
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ # See the License for the specific language governing permissions and
10
+ # limitations under the License.
11
+
12
+ from __future__ import annotations
13
+
14
+ import unittest
15
+
16
+ import torch
17
+ from parameterized import parameterized
18
+
19
+ from monai.networks.schedulers import RFlowScheduler
20
+ from tests.test_utils import assert_allclose
21
+
22
+ TEST_2D_CASE = []
23
+ for sample_method in ["uniform", "logit-normal"]:
24
+ TEST_2D_CASE.append(
25
+ [{"sample_method": sample_method, "use_timestep_transform": False}, (2, 6, 16, 16), (2, 6, 16, 16)]
26
+ )
27
+
28
+ for sample_method in ["uniform", "logit-normal"]:
29
+ TEST_2D_CASE.append(
30
+ [
31
+ {"sample_method": sample_method, "use_timestep_transform": True, "spatial_dim": 2},
32
+ (2, 6, 16, 16),
33
+ (2, 6, 16, 16),
34
+ ]
35
+ )
36
+
37
+
38
+ TEST_3D_CASE = []
39
+ for sample_method in ["uniform", "logit-normal"]:
40
+ TEST_3D_CASE.append(
41
+ [{"sample_method": sample_method, "use_timestep_transform": False}, (2, 6, 16, 16, 16), (2, 6, 16, 16, 16)]
42
+ )
43
+
44
+ for sample_method in ["uniform", "logit-normal"]:
45
+ TEST_3D_CASE.append(
46
+ [
47
+ {"sample_method": sample_method, "use_timestep_transform": True, "spatial_dim": 3},
48
+ (2, 6, 16, 16, 16),
49
+ (2, 6, 16, 16, 16),
50
+ ]
51
+ )
52
+
53
+ TEST_CASES = TEST_2D_CASE + TEST_3D_CASE
54
+
55
+ TEST_FULl_LOOP = [
56
+ [{"sample_method": "uniform"}, (1, 1, 2, 2), torch.Tensor([[[[-0.786166, -0.057519], [2.442662, -0.407664]]]])]
57
+ ]
58
+
59
+
60
+ class TestRFlowScheduler(unittest.TestCase):
61
+ @parameterized.expand(TEST_CASES)
62
+ def test_add_noise(self, input_param, input_shape, expected_shape):
63
+ scheduler = RFlowScheduler(**input_param)
64
+ original_sample = torch.zeros(input_shape)
65
+ timesteps = scheduler.sample_timesteps(original_sample)
66
+ noise = torch.randn_like(original_sample)
67
+ timesteps = torch.randint(0, scheduler.num_train_timesteps, (original_sample.shape[0],)).long()
68
+ noisy = scheduler.add_noise(original_samples=original_sample, noise=noise, timesteps=timesteps)
69
+ self.assertEqual(noisy.shape, expected_shape)
70
+
71
+ @parameterized.expand(TEST_CASES)
72
+ def test_step_shape(self, input_param, input_shape, expected_shape):
73
+ scheduler = RFlowScheduler(**input_param)
74
+ model_output = torch.randn(input_shape)
75
+ sample = torch.randn(input_shape)
76
+ scheduler.set_timesteps(num_inference_steps=100, input_img_size_numel=torch.numel(sample[0, 0, ...]))
77
+ output_step = scheduler.step(model_output=model_output, timestep=500, sample=sample)
78
+ self.assertEqual(output_step[0].shape, expected_shape)
79
+ self.assertEqual(output_step[1].shape, expected_shape)
80
+
81
+ @parameterized.expand(TEST_FULl_LOOP)
82
+ def test_full_timestep_loop(self, input_param, input_shape, expected_output):
83
+ scheduler = RFlowScheduler(**input_param)
84
+ torch.manual_seed(42)
85
+ model_output = torch.randn(input_shape)
86
+ sample = torch.randn(input_shape)
87
+ scheduler.set_timesteps(50, input_img_size_numel=torch.numel(sample[0, 0, ...]))
88
+ for t in range(50):
89
+ sample, _ = scheduler.step(model_output=model_output, timestep=t, sample=sample)
90
+ assert_allclose(sample, expected_output, rtol=1e-3, atol=1e-3)
91
+
92
+ def test_set_timesteps(self):
93
+ scheduler = RFlowScheduler(num_train_timesteps=1000)
94
+ scheduler.set_timesteps(num_inference_steps=100, input_img_size_numel=16 * 16 * 16)
95
+ self.assertEqual(scheduler.num_inference_steps, 100)
96
+ self.assertEqual(len(scheduler.timesteps), 100)
97
+
98
+ def test_set_timesteps_with_num_inference_steps_bigger_than_num_train_timesteps(self):
99
+ scheduler = RFlowScheduler(num_train_timesteps=1000)
100
+ with self.assertRaises(ValueError):
101
+ scheduler.set_timesteps(num_inference_steps=2000, input_img_size_numel=16 * 16 * 16)
102
+
103
+
104
+ if __name__ == "__main__":
105
+ unittest.main()
@@ -64,7 +64,7 @@ class TestSaveState(unittest.TestCase):
64
64
  if kwargs is None:
65
65
  kwargs = {}
66
66
  save_state(src=src, path=path, create_dir=create_dir, atomic=atomic, func=func, **kwargs)
67
- ckpt = dict(torch.load(path))
67
+ ckpt = dict(torch.load(path, weights_only=True))
68
68
  for k in ckpt.keys():
69
69
  self.assertIn(k, expected_keys)
70
70