jlevy44 / PathFlow-MixMatch

Don't mix, match! Simple utilities for improved registration of Histopathology Whole Slide Images.
10 stars 6 forks source link

RuntimeError: CUDA error: invalid device ordinal #28

Closed petoor closed 3 years ago

petoor commented 3 years ago

Hi.

Setting --gpu_device 1 yields the following error:

Loading images.
Performing registration.
Traceback (most recent call last):
  File "/home/peter/anaconda3/bin/pathflow-mixmatch", line 8, in <module>
    sys.exit(main())
  File "/home/peter/anaconda3/lib/python3.8/site-packages/pathflow_mixmatch/cli.py", line 577, in main
    fire.Fire(Commands)
  File "/home/peter/anaconda3/lib/python3.8/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/peter/anaconda3/lib/python3.8/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/peter/anaconda3/lib/python3.8/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/peter/anaconda3/lib/python3.8/site-packages/pathflow_mixmatch/cli.py", line 549, in register_images
    register_images_(im1_fname=im1,
  File "/home/peter/anaconda3/lib/python3.8/site-packages/pathflow_mixmatch/cli.py", line 476, in register_images_
    new_img=displace_image(im2,affine_register(im1, im2, gpu_device=gpu_device, lr=lr, loss_fn=loss_fn, transform_type=transform_type, iterations=iterations, opt_cm=opt_cm, sigma=sigma, order=order, pyramid=pyramid,interpolation=interpolation)[0],gpu_device=gpu_device) # new tri, output he as well
  File "/home/peter/anaconda3/lib/python3.8/site-packages/pathflow_mixmatch/cli.py", line 103, in affine_register
    fixed_image = al.utils.image.create_tensor_image_from_itk_image(sitk.GetImageFromArray(cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY)), dtype=th.float32, device=device)#al.read_image_as_tensor("./practice_reg/1.png", dtype=dtype, device=device)#th.tensor(img1,device='cuda',dtype=dtype)#
  File "/home/peter/anaconda3/lib/python3.8/site-packages/airlab/utils/image.py", line 308, in create_tensor_image_from_itk_image
    tensor_image = th.tensor(np_image, dtype=dtype, device=device).unsqueeze(0).unsqueeze(0)
RuntimeError: CUDA error: invalid device ordinal

Currently running on pytorch version 1.9

I can see the error is in airlab. If you want i can move the issue to that github repo -- however it seems to not be maintained

petoor commented 3 years ago

setting gpu_device = 0 solves the problem, and gpu_device = -1 sets the script to run on cpu