wengong-jin / hgraph2graph

Hierarchical Generation of Molecular Graphs using Structural Motifs
MIT License
367 stars 108 forks source link

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first #40

Open amir-tagh opened 2 years ago

amir-tagh commented 2 years ago

Hello,

I am using the finetune_generator.py and I am getting the following error. does anybody know how to solve this.

Thanks,

Loading from checkpoint ckpt/inforna-pretrained/model.ckpt.5000 After pruning 257 -> 257 Epoch 0 training... 0%| | 0/13 [00:25<?, ?it/s] Traceback (most recent call last): File "/apps/hgraph2graph/20210428/hgraph2graph/finetune_generator.py", line 152, in meters = meters + np.array([kl_div, loss.item(), wacc 100, iacc 100, tacc 100, sacc 100]) File "/apps/hgraph2graph/20210428/lib/python3.7/site-packages/torch/_tensor.py", line 732, in array return self.numpy() TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

dbhaskar92 commented 2 years ago

In train_generator.py, change line 96 to:

meters = meters + np.array([kl_div, loss.item(), wacc.cpu() 100, iacc.cpu() 100, tacc.cpu() 100, sacc.cpu() 100])

amir-tagh commented 2 years ago

Thanks.