You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RuntimeError with SpatialPad when input is MetaTensor and padding size is the same as tensor size #7323
If this specific scenario, where the shape should be different, is not supported in case of MetaTensors, the error should be clearer. In any other scenario (dealing with normal tensors) the shape is left the same and no error occurs.
Environment
python 3.9
monai 1.3.0
pytorch 2.1.0, 1.13.1 (both have the same problem)
This issue is related to how data is being collated by the data loader when putting list-based batches together with RandSpatialCropSamplesd. We're still trying to narrow down what's going on but it's more than just the transform that's raising the error.
After cropping the samples and putting these transform into the loader, there seems to be a problem with len(orig_affine) in TraceableTransform.track_transform_meta.
@atbenmurray in case you want to have a look / help!
One thing to note in the above code is that post_transform is being applied to a whole batch of images rather than individually so the dimension of the input isn't what's expected. If the last line is image_tf = post_transform(image[0]) this example will work. The issue with the matrix multiplication is because of this batching actually but there should be some check to indicate that this is the case rather than allowing an unhelpful exception like this.
Just like Eric said, the issue is due to that the post_transform is applied on a batch of data.
One more thing you could do is that using decollate_batch.
image_tf = [post_transform(i) for i in decollate_batch(image)]
Also create a patch to add more information when raising exception.
Activity
KumoLiu commentedon Dec 15, 2023
Hi @virginiafdez, thanks for the reporting.
I can't reproduce the issue, could you please try the code below?
Thanks!
ericspod commentedon Dec 15, 2023
This issue is related to how data is being collated by the data loader when putting list-based batches together with RandSpatialCropSamplesd. We're still trying to narrow down what's going on but it's more than just the transform that's raising the error.
virginiafdez commentedon Dec 15, 2023
The following replicates the issue:
After cropping the samples and putting these transform into the loader, there seems to be a problem with len(orig_affine) in TraceableTransform.track_transform_meta.
@atbenmurray in case you want to have a look / help!
ericspod commentedon Dec 15, 2023
One thing to note in the above code is that
post_transformis being applied to a whole batch of images rather than individually so the dimension of the input isn't what's expected. If the last line isimage_tf = post_transform(image[0])this example will work. The issue with the matrix multiplication is because of this batching actually but there should be some check to indicate that this is the case rather than allowing an unhelpful exception like this.fix Project-MONAI#7323
KumoLiu commentedon Dec 18, 2023
Just like Eric said, the issue is due to that the post_transform is applied on a batch of data.
One more thing you could do is that using
decollate_batch.Also create a patch to add more information when raising exception.
vikashg commentedon Jan 4, 2024
closing as merged @KumoLiu @virginiafdez
Give more useful exception when batch is considered during matrix mul…
Give more useful exception when batch is considered during matrix mul…
Give more useful exception when batch is considered during matrix mul…
Give more useful exception when batch is considered during matrix mul…