Skip to content

Commit

Permalink
Merge branch 'fix-issue-7513' of https://github.com/hyacinth97223/MONAI
Browse files Browse the repository at this point in the history
… into fix-issue-7513

 Logs the input summary of a MONAI bundle script to the console and a local log file.
 Each rank's logs are tagged with their rank number and saved to individual log files.
 Reads the base log path from the logging.conf file and creates a separate log file for each rank.
 Add log_all_ranks as a parameter to determine whether to log all ranks or only rank 0.
  • Loading branch information
hyacinth97223 committed Sep 23, 2024
2 parents 69001d7 + a9507ad commit a4ae330
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion monai/transforms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ def weighted_patch_samples(
if not v[-1] or not isfinite(v[-1]) or v[-1] < 0: # uniform sampling
idx = r_state.randint(0, len(v), size=n_samples)
else:
r, *_ = convert_to_dst_type(r_state.random(n_samples), v)
r_samples = r_state.random(n_samples)
r, *_ = convert_to_dst_type(r_samples, v, dtype=r_samples.dtype)
idx = searchsorted(v, r * v[-1], right=True) # type: ignore
idx, *_ = convert_to_dst_type(idx, v, dtype=torch.int) # type: ignore
# compensate 'valid' mode
Expand Down
30 changes: 30 additions & 0 deletions tests/test_rand_weighted_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ def get_data(ndim):
[[63, 37], [31, 43], [66, 20]],
]
)
im = SEG1_2D
weight_map = np.zeros_like(im, dtype=np.int32)
weight_map[0, 30, 20] = 3
weight_map[0, 45, 44] = 1
weight_map[0, 60, 50] = 2
TESTS.append(
[
"int w 2d",
dict(spatial_size=(10, 12), num_samples=3),
p(im),
q(weight_map),
(1, 10, 12),
[[60, 50], [30, 20], [45, 44]],
]
)
im = SEG1_3D
weight = np.zeros_like(im)
weight[0, 5, 30, 17] = 1.1
Expand Down Expand Up @@ -149,6 +164,21 @@ def get_data(ndim):
[[32, 24, 40], [32, 24, 40], [32, 24, 40]],
]
)
im = SEG1_3D
weight_map = np.zeros_like(im, dtype=np.int32)
weight_map[0, 6, 22, 19] = 4
weight_map[0, 8, 40, 31] = 2
weight_map[0, 13, 20, 24] = 3
TESTS.append(
[
"int w 3d",
dict(spatial_size=(8, 10, 12), num_samples=3),
p(im),
q(weight_map),
(1, 8, 10, 12),
[[13, 20, 24], [6, 22, 19], [8, 40, 31]],
]
)


class TestRandWeightedCrop(CropTest):
Expand Down

0 comments on commit a4ae330

Please sign in to comment.