mazurowski-lab / finetune-SAM

This is an official repo for fine-tuning SAM to customized medical images.
https://arxiv.org/abs/2404.09957
Apache License 2.0
114 stars 17 forks source link

CUDA not found #18

Closed jmayank23 closed 3 weeks ago

jmayank23 commented 1 month ago

I am getting the following error when I try to run train_singlegpu_demo.sh

File "/home/mayank/Projects/finetune-SAM/SingleGPU_train_finetune_noprompt.py", line 212, in train_model(trainloader,valloader,args.dir_checkpoint,args.epochs) File "/home/mayank/Projects/finetune-SAM/SingleGPU_train_finetune_noprompt.py", line 51, in train_model sam = sam_model_registryargs.arch File "/home/mayank/Projects/finetune-SAM/models/sam/build_sam.py", line 49, in build_sam_vit_b return _build_sam( File "/home/mayank/Projects/finetune-SAM/models/sam/build_sam.py", line 140, in _build_sam image_encoder=ImageEncoderViT( File "/home/mayank/Projects/finetune-SAM/models/sam/modeling/image_encoder.py", line 82, in init torch.zeros(1, img_size // patch_size, img_size // patch_size, embed_dim,dtype=torch.float, device=self.dev[0])) File "/home/mayank/anaconda3/envs/finetune-SAM/lib/python3.10/site-packages/torch/cuda/init.py", line 293, in _lazy_init torch._C._cuda_init() RuntimeError: No CUDA GPUs are available

I have two GPUs on the machine and torch.cuda.is_available outputs True. How do I fix this error?

Guhanxue commented 1 month ago

Hi, sorry for the confusion. in the train_singlegpu_demo.sh; i choose gpu ID 5 as only visiable gpu on our machine. For your case, you need to change CUDA_VISIBLE_DEVICES= '0' or '1' or '0,1'

image