-
Notifications
You must be signed in to change notification settings - Fork 1.5k
AffineGrid GPU tensor error #1827
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
a transform error from AffineGrid when running tutorial transforms_demo_2d
full logs: https://github.com/Project-MONAI/MONAI/runs/2172199805?check_suite_focus=true
Running ./modules/transforms_demo_2d.ipynb
Checking PEP8 compliance...
Running notebook...
Executing: 0%| | 0/20 [00:00<?, ?cell/s]
Executing: 5%|▌ | 1/20 [00:01<00:22, 1.18s/cell]
Executing: 15%|█▌ | 3/20 [00:06<00:26, 1.58s/cell]
Executing: 20%|██ | 4/20 [00:08<00:28, 1.78s/cell]
Executing: 50%|█████ | 10/20 [00:26<00:21, 2.15s/cell]
Executing: 60%|██████ | 12/20 [00:26<00:12, 1.56s/cell]
Executing: 70%|███████ | 14/20 [00:29<00:09, 1.53s/cell]
Executing: 70%|███████ | 14/20 [00:31<00:13, 2.23s/cell]
Traceback (most recent call last):
File "/opt/conda/bin/papermill", line 8, in <module>
sys.exit(papermill())
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/papermill/cli.py", line 250, in papermill
execute_notebook(
File "/opt/conda/lib/python3.8/site-packages/papermill/execute.py", line 122, in execute_notebook
raise_for_execution_errors(nb, output_path)
File "/opt/conda/lib/python3.8/site-packages/papermill/execute.py", line 234, in raise_for_execution_errors
raise error
papermill.exceptions.PapermillExecutionError:
---------------------------------------------------------------------------
Exception encountered at "In [8]":
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-63f386481380> in <module>
13 # convert both image and segmentation using different interpolation mode
14 new_img = affine(im_data, (300, 400), mode="bilinear")
---> 15 new_seg = affine(seg_data, (300, 400), mode="nearest")
16 print(new_img.shape, new_seg.shape)
/__w/MONAI/MONAI/monai/transforms/spatial/array.py in __call__(self, img, spatial_size, mode, padding_mode)
1327 """
1328 sp_size = fall_back_tuple(spatial_size or self.spatial_size, img.shape[1:])
-> 1329 grid = self.affine_grid(spatial_size=sp_size)
1330 return self.resampler(
1331 img=img, grid=grid, mode=mode or self.mode, padding_mode=padding_mode or self.padding_mode
/__w/MONAI/MONAI/monai/transforms/spatial/array.py in __call__(self, spatial_size, grid)
991 self.affine = affine
992
--> 993 self.affine = torch.as_tensor(np.ascontiguousarray(self.affine), device=self.device)
994
995 grid = torch.tensor(grid) if not isinstance(grid, torch.Tensor) else grid.detach().clone()
/opt/conda/lib/python3.8/site-packages/numpy/core/_asarray.py in ascontiguousarray(a, dtype)
175
176 """
--> 177 return array(a, dtype, copy=False, order='C', ndmin=1)
178
179
/opt/conda/lib/python3.8/site-packages/torch/tensor.py in __array__(self, dtype)
599 return handle_torch_function(Tensor.__array__, (self,), self, dtype=dtype)
600 if dtype is None:
--> 601 return self.numpy()
602 else:
603 return self.numpy().astype(dtype, copy=False)
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
context:
MONAI/monai/transforms/spatial/array.py
Line 993 in c4bb4cb
| self.affine = torch.as_tensor(np.ascontiguousarray(self.affine), device=self.device) |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working