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

Error in validation, Shape mismatch, can't divide axis of length X in chunks of Y #126

Open
rafiibnsultan opened this issue Sep 4, 2024 · 0 comments

Comments

@rafiibnsultan
Copy link

rafiibnsultan commented Sep 4, 2024

Although there is no issue in training, but in validation stage I always get this type of error for BTCV dataset, on default processing:

Traceback (most recent call last):
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/transform.py", line 141, in apply_transform
return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/transform.py", line 98, in _apply_transform
return transform(data, lazy=lazy) if isinstance(transform, LazyTrait) else transform(data)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/io/dictionary.py", line 164, in call
data = self._loader(d[key], reader)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/io/array.py", line 302, in call
img = EnsureChannelFirst()(img)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/utility/array.py", line 204, in call
raise ValueError(msg)
ValueError: Metadata not available and channel_dim=None, EnsureChannelFirst is not in use.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/transform.py", line 141, in apply_transform
return _apply_transform(transform, data, unpack_items, lazy, overrides, log_stats)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/transform.py", line 98, in _apply_transform
return transform(data, lazy=lazy) if isinstance(transform, LazyTrait) else transform(data)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/compose.py", line 322, in call
result = execute_compose(
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/compose.py", line 111, in execute_compose
data = apply_transform(
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/transform.py", line 171, in apply_transform
raise RuntimeError(f"applying transform {transform}") from e
RuntimeError: applying transform <monai.transforms.io.dictionary.LoadImaged object at 0x7feb3cdd5d90>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/threading.py", line 980, in _bootstrap_inner
self.run()
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/data/thread_buffer.py", line 49, in enqueue_values
for src_val in self.src:
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 630, in next
data = self._next_data()
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 673, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 52, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/data/dataset.py", line 109, in getitem
return self._transform(index)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/data/dataset.py", line 908, in _transform
return super()._transform(index)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/data/dataset.py", line 95, in _transform
return apply_transform(self.transform, data_i) if self.transform is not None else data_i
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/monai/transforms/transform.py", line 171, in apply_transform
raise RuntimeError(f"applying transform {transform}") from e
RuntimeError: applying transform <monai.transforms.compose.Compose object at 0x7feb3cdd5700>
Traceback (most recent call last):
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/einops/einops.py", line 523, in reduce
return _apply_recipe(
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/einops/einops.py", line 234, in _apply_recipe
init_shapes, axes_reordering, reduced_axes, added_axes, final_shapes, n_axes_w_added = _reconstruct_from_shape(
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/einops/einops.py", line 187, in _reconstruct_from_shape_uncached
raise EinopsError(f"Shape mismatch, can't divide axis of length {length} in chunks of {known_product}")
einops.EinopsError: Shape mismatch, can't divide axis of length 311 in chunks of 96

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/hm4013/Medical-SAM-Adapter/val.py", line 102, in
main()
File "/home/hm4013/Medical-SAM-Adapter/val.py", line 94, in main
tol, (eiou, edice) = function.validation_sam(args, nice_test_loader, start_epoch, net)
File "/home/hm4013/Medical-SAM-Adapter/function.py", line 306, in validation_sam
imge= net.image_encoder(imgs)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
File "/home/hm4013/Medical-SAM-Adapter/models/sam/modeling/image_encoder.py", line 134, in forward
x = blk(x)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
File "/home/hm4013/Medical-SAM-Adapter/models/ImageEncoder/vit/adapter_block.py", line 87, in forward
xd = rearrange(x, '(b d) h w c -> (b h w) d c ', d=depth)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/einops/einops.py", line 591, in rearrange
return reduce(tensor, pattern, reduction="rearrange", **axes_lengths)
File "/home/hm4013/.conda/envs/mul2/lib/python3.9/site-packages/einops/einops.py", line 533, in reduce
raise EinopsError(message + "\n {}".format(e))
einops.EinopsError: Error while processing rearrange-reduction pattern "(b d) h w c -> (b h w) d c ".
Input tensor shape: torch.Size([311, 14, 14, 768]). Additional info: {'d': 96}.
Shape mismatch, can't divide axis of length 311 in chunks of 96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant