Skip to content

Commit

Permalink
Update monai/transforms/inverse.py
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
  • Loading branch information
KumoLiu and ericspod authored Dec 27, 2023
1 parent c06a89b commit ba82172
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions monai/transforms/inverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,14 @@ def track_transform_meta(
try:
affine = orig_affine @ to_affine_nd(len(orig_affine) - 1, affine, dtype=torch.float64)
except RuntimeError as e:
raise RuntimeError(
"mismatch affine matrix, ensured that the batch dimension is not included in the calculation."
) from e
if orig_affine.ndim > 2:
if data_t.is_batch:
msg = "Transform applied to batched tensor, should be applied to instances only"
else:
msg = "Mismatch affine matrix, ensured that the batch dimension is not included in the calculation."
raise RuntimeError(msg) from e
else:
raise
out_obj.meta[MetaKeys.AFFINE] = convert_to_tensor(affine, device=torch.device("cpu"), dtype=torch.float64)

if not (get_track_meta() and transform_info and transform_info.get(TraceKeys.TRACING)):
Expand Down

0 comments on commit ba82172

Please sign in to comment.