Medical-SAM2
Medical-SAM2 copied to clipboard
RuntimeError: "view size is not compatible with input tensor's size and stride" during 2D training on Google Colab
I encountered an issue while training the 2D case on Google Colab. Here's the error message:
`/content/Medical-SAM2/sam2_train/modeling/sam/transformer.py:22: UserWarning: Flash Attention is disabled as it requires a GPU with Ampere (8.0) CUDA capability.
OLD_GPU, USE_FLASH_ATTN, MATH_KERNEL_ON = get_sdpa_settings()
INFO:root:Namespace(net='sam2', encoder='vit_b', exp_name='REFUGE_MedSAM2', vis=True, train_vis=False, prompt='bbox', prompt_freq=2, pretrain=None, val_freq=1, gpu=True, gpu_device=0, image_size=1024, out_size=1024, distributed='none', dataset='REFUGE', sam_ckpt='./checkpoints/sam2_hiera_small.pt', sam_config='sam2_hiera_s', video_length=2, b=4, lr=0.0001, weights=0, multimask_output=1, memory_bank_size=16, data_path='/content/Medical-SAM2/REFUGE', path_helper={'prefix': 'logs/REFUGE_MedSAM2_2024_09_30_12_34_25', 'ckpt_path': 'logs/REFUGE_MedSAM2_2024_09_30_12_34_25/Model', 'log_path': 'logs/REFUGE_MedSAM2_2024_09_30_12_34_25/Log', 'sample_path': 'logs/REFUGE_MedSAM2_2024_09_30_12_34_25/Samples'})
Namespace(net='sam2', encoder='vit_b', exp_name='REFUGE_MedSAM2', vis=True, train_vis=False, prompt='bbox', prompt_freq=2, pretrain=None, val_freq=1, gpu=True, gpu_device=0, image_size=1024, out_size=1024, distributed='none', dataset='REFUGE', sam_ckpt='./checkpoints/sam2_hiera_small.pt', sam_config='sam2_hiera_s', video_length=2, b=4, lr=0.0001, weights=0, multimask_output=1, memory_bank_size=16, data_path='/content/Medical-SAM2/REFUGE', path_helper={'prefix': 'logs/REFUGE_MedSAM2_2024_09_30_12_34_25', 'ckpt_path': 'logs/REFUGE_MedSAM2_2024_09_30_12_34_25/Model', 'log_path': 'logs/REFUGE_MedSAM2_2024_09_30_12_34_25/Log', 'sample_path': 'logs/REFUGE_MedSAM2_2024_09_30_12_34_25/Samples'})
Traceback (most recent call last):
File "/content/Medical-SAM2/train_2d.py", line 124, in <module>
main()
File "/content/Medical-SAM2/train_2d.py", line 97, in main
tol, (eiou, edice) = function.validation_sam(args, nice_test_loader, epoch, net, writer)
File "/content/Medical-SAM2/func_2d/function.py", line 335, in validation_sam
vision_feats_temp = vision_feats[-1].permute(1, 0, 2).view(B, -1, 64, 64)
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.`
Could you provide guidance on how to resolve this issue or any suggestions to address this dimensionality problem?
Thanks for your support.
I get the same error. Did you fix that?
vision_feats_temp = vision_feats[-1].permute(1, 0, 2).reshape(B, -1, 64, 64)