Skip to content
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

Fix Incompatible types in assignment issue #7950

Merged
merged 5 commits into from
Jul 25, 2024
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/auto3dseg/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def __call__(self, data: Mapping[Hashable, MetaTensor]) -> dict[Hashable, MetaTe

unique_label = unique(ndas_label)
KumoLiu marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(ndas_label, (MetaTensor, torch.Tensor)):
unique_label = unique_label.data.cpu().numpy()
unique_label = unique_label.data.cpu().numpy() # type: ignore[assignment]

unique_label = unique_label.astype(np.int16).tolist()

Expand Down
2 changes: 2 additions & 0 deletions monai/metrics/cumulative_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def get_current(self, to_numpy: bool = True) -> NdarrayOrTensor:
if self.val is None:
return 0

val: NdarrayOrTensor
val = self.val.clone()
KumoLiu marked this conversation as resolved.
Show resolved Hide resolved
val[~torch.isfinite(val)] = 0

Expand Down Expand Up @@ -96,6 +97,7 @@ def aggregate(self, to_numpy: bool = True) -> NdarrayOrTensor:
dist.all_reduce(sum)
dist.all_reduce(count)

val: NdarrayOrTensor
val = torch.where(count > 0, sum / count, sum)

if to_numpy:
Expand Down
2 changes: 1 addition & 1 deletion monai/metrics/panoptic_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def _get_paired_iou(

return paired_iou, paired_true, paired_pred

pairwise_iou = pairwise_iou.cpu().numpy()
KumoLiu marked this conversation as resolved.
Show resolved Hide resolved
pairwise_iou = pairwise_iou.cpu().numpy() # type: ignore[assignment]
paired_true, paired_pred = linear_sum_assignment(-pairwise_iou)
paired_iou = pairwise_iou[paired_true, paired_pred]
paired_true = torch.as_tensor(list(paired_true[paired_iou > match_iou_threshold] + 1), device=device)
Expand Down
4 changes: 2 additions & 2 deletions monai/metrics/rocauc.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def _calculate(y_pred: torch.Tensor, y: torch.Tensor) -> float:

n = len(y)
indices = y_pred.argsort()
y = y[indices].cpu().numpy()
KumoLiu marked this conversation as resolved.
Show resolved Hide resolved
y_pred = y_pred[indices].cpu().numpy()
y = y[indices].cpu().numpy() # type: ignore[assignment]
y_pred = y_pred[indices].cpu().numpy() # type: ignore[assignment]
nneg = auc = tmp_pos = tmp_neg = 0.0

for i in range(n):
Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/croppad/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _np_pad(img: NdarrayTensor, pad_width: list[tuple[int, int]], mode: str, **k
warnings.warn(f"Padding: moving img {img.shape} from cuda to cpu for dtype={img.dtype} mode={mode}.")
img_np = img.detach().cpu().numpy()
else:
img_np = img
img_np = np.asarray(img)
mode = convert_pad_mode(dst=img_np, mode=mode).value
if mode == "constant" and "value" in kwargs:
kwargs["constant_values"] = kwargs.pop("value")
Expand Down
4 changes: 3 additions & 1 deletion monai/visualize/img2tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def plot_2d_or_3d_image(
# as the `d` data has no batch dim, reduce the spatial dim index if positive
frame_dim = frame_dim - 1 if frame_dim > 0 else frame_dim

d: np.ndarray = data_index.detach().cpu().numpy() if isinstance(data_index, torch.Tensor) else data_index
d: np.ndarray = (
data_index.detach().cpu().numpy() if isinstance(data_index, torch.Tensor) else np.asarray(data_index)
)

if d.ndim == 2:
d = rescale_array(d, 0, 1) # type: ignore
Expand Down
Loading