Skip to content

auto updates #7247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion monai/apps/detection/transforms/box_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def rot90_boxes(
spatial_dims: int = get_spatial_dims(boxes=boxes)
spatial_size_ = list(ensure_tuple_rep(spatial_size, spatial_dims))

axes = ensure_tuple(axes) # type: ignore
axes = ensure_tuple(axes)

if len(axes) != 2:
raise ValueError("len(axes) must be 2.")
Expand Down
4 changes: 2 additions & 2 deletions monai/data/grid_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ def __iter__(self):
raise RuntimeError(
"Cache buffer is not initialized, please call `set_data()` before epoch begins."
)
data = self._cache[cache_index] # type: ignore
other = self._cache_other[cache_index] # type: ignore
data = self._cache[cache_index]
other = self._cache_other[cache_index]

# load data from cache and execute from the first random transform
data = deepcopy(data) if self.copy_cache else data
Expand Down
2 changes: 1 addition & 1 deletion monai/data/image_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def resample_if_needed(
# convert back at the end
if isinstance(output_array, MetaTensor):
output_array.applied_operations = []
data_array, *_ = convert_data_type(output_array, output_type=orig_type) # type: ignore
data_array, *_ = convert_data_type(output_array, output_type=orig_type)
affine, *_ = convert_data_type(output_array.affine, output_type=orig_type) # type: ignore
return data_array[0], affine

Expand Down
2 changes: 1 addition & 1 deletion monai/data/wsi_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(
self.set_device(device)
self.mode = mode
self.kwargs = kwargs
self.mpp: tuple[float, float] | None = ensure_tuple_rep(mpp, 2) if mpp is not None else None # type: ignore
self.mpp: tuple[float, float] | None = ensure_tuple_rep(mpp, 2) if mpp is not None else None
self.power = power
self.mpp_rtol = mpp_rtol
self.mpp_atol = mpp_atol
Expand Down
2 changes: 1 addition & 1 deletion monai/metrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def get_mask_edges(
or_vol = seg_pred | seg_gt
if not or_vol.any():
pred, gt = lib.zeros(seg_pred.shape, dtype=bool), lib.zeros(seg_gt.shape, dtype=bool)
return (pred, gt) if spacing is None else (pred, gt, pred, gt) # type: ignore
return (pred, gt) if spacing is None else (pred, gt, pred, gt)
channel_first = [seg_pred[None], seg_gt[None], or_vol[None]]
if spacing is None and not use_cucim: # cpu only erosion
seg_pred, seg_gt, or_vol = convert_to_tensor(channel_first, device="cpu", dtype=bool)
Expand Down
6 changes: 3 additions & 3 deletions monai/networks/nets/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ def __init__(
self.conv1 = conv_type(
n_input_channels,
self.in_planes,
kernel_size=conv1_kernel_size, # type: ignore
stride=conv1_stride, # type: ignore
padding=tuple(k // 2 for k in conv1_kernel_size), # type: ignore
kernel_size=conv1_kernel_size,
stride=conv1_stride,
padding=tuple(k // 2 for k in conv1_kernel_size),
bias=False,
)
self.bn1 = norm_type(self.in_planes)
Expand Down
8 changes: 3 additions & 5 deletions monai/transforms/croppad/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def compute_slices(
if roi_slices:
if not all(s.step is None or s.step == 1 for s in roi_slices):
raise ValueError(f"only slice steps of 1/None are currently supported, got {roi_slices}.")
return ensure_tuple(roi_slices) # type: ignore
return ensure_tuple(roi_slices)
else:
if roi_center is not None and roi_size is not None:
roi_center_t = convert_to_tensor(data=roi_center, dtype=torch.int16, wrap_sequence=True, device="cpu")
Expand All @@ -408,10 +408,8 @@ def compute_slices(
roi_end_t = torch.maximum(roi_end_t, roi_start_t)
# convert to slices (accounting for 1d)
if roi_start_t.numel() == 1:
return ensure_tuple([slice(int(roi_start_t.item()), int(roi_end_t.item()))]) # type: ignore
return ensure_tuple( # type: ignore
[slice(int(s), int(e)) for s, e in zip(roi_start_t.tolist(), roi_end_t.tolist())]
)
return ensure_tuple([slice(int(roi_start_t.item()), int(roi_end_t.item()))])
return ensure_tuple([slice(int(s), int(e)) for s, e in zip(roi_start_t.tolist(), roi_end_t.tolist())])

def __call__( # type: ignore[override]
self, img: torch.Tensor, slices: tuple[slice, ...], lazy: bool | None = None
Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/spatial/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ def __init__(self, k: int = 1, spatial_axes: tuple[int, int] = (0, 1), lazy: boo
"""
LazyTransform.__init__(self, lazy=lazy)
self.k = (4 + (k % 4)) % 4 # 0, 1, 2, 3
spatial_axes_: tuple[int, int] = ensure_tuple(spatial_axes) # type: ignore
spatial_axes_: tuple[int, int] = ensure_tuple(spatial_axes)
if len(spatial_axes_) != 2:
raise ValueError(f"spatial_axes must be 2 numbers to define the plane to rotate, got {spatial_axes_}.")
self.spatial_axes = spatial_axes_
Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def __call__(self, img: NdarrayOrTensor, dtype: DtypeLike | torch.dtype = None)
TypeError: When ``img`` type is not in ``Union[numpy.ndarray, torch.Tensor]``.

"""
return convert_data_type(img, output_type=type(img), dtype=dtype or self.dtype)[0] # type: ignore
return convert_data_type(img, output_type=type(img), dtype=dtype or self.dtype)[0]


class ToTensor(Transform):
Expand Down
8 changes: 4 additions & 4 deletions monai/transforms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def correct_crop_centers(
for c, v_s, v_e in zip(centers, valid_start, valid_end):
center_i = min(max(c, v_s), v_e - 1)
valid_centers.append(int(center_i))
return ensure_tuple(valid_centers) # type: ignore
return ensure_tuple(valid_centers)


def generate_pos_neg_label_crop_centers(
Expand Down Expand Up @@ -579,7 +579,7 @@ def generate_pos_neg_label_crop_centers(
# shift center to range of valid centers
centers.append(correct_crop_centers(center, spatial_size, label_spatial_shape, allow_smaller))

return ensure_tuple(centers) # type: ignore
return ensure_tuple(centers)


def generate_label_classes_crop_centers(
Expand Down Expand Up @@ -639,7 +639,7 @@ def generate_label_classes_crop_centers(
# shift center to range of valid centers
centers.append(correct_crop_centers(center, spatial_size, label_spatial_shape, allow_smaller))

return ensure_tuple(centers) # type: ignore
return ensure_tuple(centers)


def create_grid(
Expand Down Expand Up @@ -2218,7 +2218,7 @@ def distance_transform_edt(
if not r_vals:
return None
device = img.device if isinstance(img, torch.Tensor) else None
return convert_data_type(r_vals[0] if len(r_vals) == 1 else r_vals, output_type=type(img), device=device)[0] # type: ignore
return convert_data_type(r_vals[0] if len(r_vals) == 1 else r_vals, output_type=type(img), device=device)[0]


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@

TESTS_COMPOSE_X2 = [(t[0] + " Compose", t[1], t[2], t[3], Compose(Compose(t[4:]))) for t in TESTS]

TESTS = TESTS + TESTS_COMPOSE_X2 # type: ignore
TESTS = TESTS + TESTS_COMPOSE_X2

NUM_SAMPLES = 5
N_SAMPLES_TESTS = [
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,9 @@ def equal_state_dict(st_1, st_2):
[[2.0, 0.0, 0.0, 0.0], [0.0, 2.0, 0.0, 0.0], [0.0, 0.0, 2.0, 0.0], [0.0, 0.0, 0.0, 1.0]]
)
_metatensor_creator = partial(MetaTensor, meta={"a": "b", "affine": DEFAULT_TEST_AFFINE})
TEST_NDARRAYS_NO_META_TENSOR: tuple[Callable] = (np.array,) + TEST_TORCH_TENSORS # type: ignore
TEST_NDARRAYS_NO_META_TENSOR: tuple[Callable] = (np.array,) + TEST_TORCH_TENSORS
TEST_NDARRAYS: tuple[Callable] = TEST_NDARRAYS_NO_META_TENSOR + (_metatensor_creator,) # type: ignore
TEST_TORCH_AND_META_TENSORS: tuple[Callable] = TEST_TORCH_TENSORS + (_metatensor_creator,) # type: ignore
TEST_TORCH_AND_META_TENSORS: tuple[Callable] = TEST_TORCH_TENSORS + (_metatensor_creator,)
# alias for branch tests
TEST_NDARRAYS_ALL = TEST_NDARRAYS

Expand Down