arcadelab / deepdrr

Code for "DeepDRR: A Catalyst for Machine Learning in Fluoroscopy-guided Procedures". https://arxiv.org/abs/1803.08606

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type Error: Can't convert CUDA tensor to numpy

sainatarajan opened this issue · comments

Issue: So, this is another error that occurred when we ran the code in Google Colab. This occurs when assigning the value to the output_tensor variable on line 60 of segmentation.py file.

Solution: Just move the current_block_tensor to CPU and also the output that is returned by self.model.forward(). Modify this line from:

output_tensor = np.array(self.model.forward(Variable(curren_block_tensor,requires_grad = False)).data)
to
output_tensor = np.array(self.model.forward(Variable(curren_block_tensor.cpu(),requires_grad = False)).cpu().data)

The reason is that we need to convert the operations to CPU. This is because numpy doesn't support CUDA. So, we cannot use the GPU memory without copying the numpy object to the CPU first.

Thanks. This fix is now reflected in the readme.