Skip to content

Commit 1a0859c

Browse files
committed
Clarify inverse matching docs and apply formatting
Signed-off-by: sewon jeon <irocks0922@gmail.com>
1 parent 98a22d3 commit 1a0859c

8 files changed

Lines changed: 40 additions & 57 deletions

File tree

monai/apps/detection/transforms/dictionary.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ def __init__(self, box_keys: KeysCollection, box_ref_image_keys: str, allow_miss
125125
super().__init__(box_keys, allow_missing_keys)
126126
box_ref_image_keys_tuple = ensure_tuple(box_ref_image_keys)
127127
if len(box_ref_image_keys_tuple) > 1:
128-
raise ValueError(
129-
"Please provide a single key for box_ref_image_keys.\
130-
All boxes of box_keys are attached to box_ref_image_keys."
131-
)
128+
raise ValueError("Please provide a single key for box_ref_image_keys.\
129+
All boxes of box_keys are attached to box_ref_image_keys.")
132130
self.box_ref_image_keys = box_ref_image_keys
133131

134132
def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> dict[Hashable, NdarrayOrTensor]:
@@ -289,10 +287,8 @@ def __init__(
289287
super().__init__(box_keys, allow_missing_keys)
290288
box_ref_image_keys_tuple = ensure_tuple(box_ref_image_keys)
291289
if len(box_ref_image_keys_tuple) > 1:
292-
raise ValueError(
293-
"Please provide a single key for box_ref_image_keys.\
294-
All boxes of box_keys are attached to box_ref_image_keys."
295-
)
290+
raise ValueError("Please provide a single key for box_ref_image_keys.\
291+
All boxes of box_keys are attached to box_ref_image_keys.")
296292
self.box_ref_image_keys = box_ref_image_keys
297293
self.image_meta_key = image_meta_key or f"{box_ref_image_keys}_{image_meta_key_postfix}"
298294
self.converter_to_image_coordinate = AffineBox()
@@ -310,10 +306,8 @@ def extract_affine(self, data: Mapping[Hashable, torch.Tensor]) -> tuple[Ndarray
310306
else:
311307
raise ValueError(f"{meta_key} is not found. Please check whether it is the correct the image meta key.")
312308
if "affine" not in meta_dict:
313-
raise ValueError(
314-
f"'affine' is not found in {meta_key}. \
315-
Please check whether it is the correct the image meta key."
316-
)
309+
raise ValueError(f"'affine' is not found in {meta_key}. \
310+
Please check whether it is the correct the image meta key.")
317311
affine: NdarrayOrTensor = meta_dict["affine"]
318312

319313
if self.affine_lps_to_ras: # RAS affine
@@ -815,16 +809,12 @@ def __init__(
815809
) -> None:
816810
box_keys_tuple = ensure_tuple(box_keys)
817811
if len(box_keys_tuple) != 1:
818-
raise ValueError(
819-
"Please provide a single key for box_keys.\
820-
All label_keys are attached to this box_keys."
821-
)
812+
raise ValueError("Please provide a single key for box_keys.\
813+
All label_keys are attached to this box_keys.")
822814
box_ref_image_keys_tuple = ensure_tuple(box_ref_image_keys)
823815
if len(box_ref_image_keys_tuple) != 1:
824-
raise ValueError(
825-
"Please provide a single key for box_ref_image_keys.\
826-
All box_keys and label_keys are attached to this box_ref_image_keys."
827-
)
816+
raise ValueError("Please provide a single key for box_ref_image_keys.\
817+
All box_keys and label_keys are attached to this box_ref_image_keys.")
828818
self.label_keys = ensure_tuple(label_keys)
829819
super().__init__(box_keys_tuple, allow_missing_keys)
830820

@@ -1091,10 +1081,8 @@ def __init__(
10911081

10921082
box_keys_tuple = ensure_tuple(box_keys)
10931083
if len(box_keys_tuple) != 1:
1094-
raise ValueError(
1095-
"Please provide a single key for box_keys.\
1096-
All label_keys are attached to this box_keys."
1097-
)
1084+
raise ValueError("Please provide a single key for box_keys.\
1085+
All label_keys are attached to this box_keys.")
10981086
self.box_keys = box_keys_tuple[0]
10991087
self.label_keys = ensure_tuple(label_keys)
11001088

monai/apps/detection/utils/anchor_utils.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,8 @@ def __init__(
124124
aspect_ratios = (aspect_ratios,) * len(self.sizes)
125125

126126
if len(self.sizes) != len(aspect_ratios):
127-
raise ValueError(
128-
"len(sizes) and len(aspect_ratios) should be equal. \
129-
It represents the number of feature maps."
130-
)
127+
raise ValueError("len(sizes) and len(aspect_ratios) should be equal. \
128+
It represents the number of feature maps.")
131129

132130
spatial_dims = len(ensure_tuple(aspect_ratios[0][0])) + 1
133131
spatial_dims = look_up_option(spatial_dims, [2, 3])
@@ -172,16 +170,12 @@ def generate_anchors(
172170
scales_t = torch.as_tensor(scales, dtype=dtype, device=device) # sized (N,)
173171
aspect_ratios_t = torch.as_tensor(aspect_ratios, dtype=dtype, device=device) # sized (M,) or (M,2)
174172
if (self.spatial_dims >= 3) and (len(aspect_ratios_t.shape) != 2):
175-
raise ValueError(
176-
f"In {self.spatial_dims}-D image, aspect_ratios for each level should be \
177-
{len(aspect_ratios_t.shape) - 1}-D. But got aspect_ratios with shape {aspect_ratios_t.shape}."
178-
)
173+
raise ValueError(f"In {self.spatial_dims}-D image, aspect_ratios for each level should be \
174+
{len(aspect_ratios_t.shape) - 1}-D. But got aspect_ratios with shape {aspect_ratios_t.shape}.")
179175

180176
if (self.spatial_dims >= 3) and (aspect_ratios_t.shape[1] != self.spatial_dims - 1):
181-
raise ValueError(
182-
f"In {self.spatial_dims}-D image, aspect_ratios for each level should has \
183-
shape (_,{self.spatial_dims - 1}). But got aspect_ratios with shape {aspect_ratios_t.shape}."
184-
)
177+
raise ValueError(f"In {self.spatial_dims}-D image, aspect_ratios for each level should has \
178+
shape (_,{self.spatial_dims - 1}). But got aspect_ratios with shape {aspect_ratios_t.shape}.")
185179

186180
# if 2d, w:h = 1:aspect_ratios
187181
if self.spatial_dims == 2:

monai/apps/reconstruction/transforms/array.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@ def __init__(
6161
real/imaginary parts.
6262
"""
6363
if len(center_fractions) != len(accelerations):
64-
raise ValueError(
65-
"Number of center fractions \
66-
should match number of accelerations"
67-
)
64+
raise ValueError("Number of center fractions \
65+
should match number of accelerations")
6866

6967
self.center_fractions = center_fractions
7068
self.accelerations = accelerations

monai/bundle/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,8 @@
124124
"run_name": None,
125125
# may fill it at runtime
126126
"save_execute_config": True,
127-
"is_not_rank0": (
128-
"$torch.distributed.is_available() \
129-
and torch.distributed.is_initialized() and torch.distributed.get_rank() > 0"
130-
),
127+
"is_not_rank0": ("$torch.distributed.is_available() \
128+
and torch.distributed.is_initialized() and torch.distributed.get_rank() > 0"),
131129
# MLFlowHandler config for the trainer
132130
"trainer": {
133131
"_target_": "MLFlowHandler",

monai/losses/dice.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,9 @@ def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
203203
self.class_weight = torch.as_tensor([self.class_weight] * num_of_classes)
204204
else:
205205
if self.class_weight.shape[0] != num_of_classes:
206-
raise ValueError(
207-
"""the length of the `weight` sequence should be the same as the number of classes.
206+
raise ValueError("""the length of the `weight` sequence should be the same as the number of classes.
208207
If `include_background=False`, the weight should not include
209-
the background category class 0."""
210-
)
208+
the background category class 0.""")
211209
if self.class_weight.min() < 0:
212210
raise ValueError("the value/values of the `weight` should be no less than 0.")
213211
# apply class_weight to loss

monai/losses/focal_loss.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,9 @@ def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
183183
self.class_weight = torch.as_tensor([self.class_weight] * num_of_classes)
184184
else:
185185
if self.class_weight.shape[0] != num_of_classes:
186-
raise ValueError(
187-
"""the length of the `weight` sequence should be the same as the number of classes.
186+
raise ValueError("""the length of the `weight` sequence should be the same as the number of classes.
188187
If `include_background=False`, the weight should not include
189-
the background category class 0."""
190-
)
188+
the background category class 0.""")
191189
if self.class_weight.min() < 0:
192190
raise ValueError("the value/values of the `weight` should be no less than 0.")
193191
# apply class_weight to loss

monai/transforms/inverse.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,12 @@ def track_transform_meta(
302302
return out_obj
303303

304304
def check_transforms_match(self, transform: Mapping) -> None:
305-
"""Check transforms are of same instance."""
305+
"""Check whether a traced transform entry matches this transform.
306+
307+
When multiprocessing uses ``spawn``, transform instances are recreated,
308+
so matching can fall back to the transform class name instead of the
309+
original instance ID.
310+
"""
306311
if self._transforms_match(transform):
307312
return
308313

@@ -317,7 +322,13 @@ def check_transforms_match(self, transform: Mapping) -> None:
317322
)
318323

319324
def _transforms_match(self, transform: Mapping) -> bool:
320-
"""Return whether a traced transform entry matches this transform instance."""
325+
"""Return whether a traced transform entry matches this transform.
326+
327+
Matching succeeds when the traced ID matches this instance, when the ID
328+
check is explicitly disabled with ``TraceKeys.NONE``, or when
329+
multiprocessing uses ``spawn`` and the traced class name matches this
330+
transform class.
331+
"""
321332
xform_id = transform.get(TraceKeys.ID, "")
322333
if xform_id == id(self):
323334
return True

versioneer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
429429
return stdout, process.returncode
430430

431431

432-
LONG_VERSION_PY[
433-
"git"
434-
] = r'''
432+
LONG_VERSION_PY["git"] = r'''
435433
# This file helps to compute a version number in source trees obtained from
436434
# git-archive tarball (such as those provided by githubs download-from-tag
437435
# feature). Distribution tarballs (built by setup.py sdist) and build

0 commit comments

Comments
 (0)