crowsonkb/v-diffusion-pytorch

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

illtellyoulater opened this issue · 0 comments

Hello, when running:

python .\cfg_sample.py "something cool"
or
python .\clip_sample.py "something cool"

I get the following errors:

for cfg_sample.py

Using device: cuda:0
100%|████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:51<00:00, 10.23s/it]
  0%|                                                                                            | 0/1 [00:51<?, ?it/s]
Traceback (most recent call last):
  File ".\cfg_sample.py", line 170, in <module>
    main()
  File ".\cfg_sample.py", line 164, in main
    run_all(args.n, args.batch_size)
  File ".\cfg_sample.py", line 161, in run_all
    utils.to_pil_image(out).save(f'out_{i + j:05}.png')
  File "C:\Users\my-name\downloads\v-diffusion-pytorch\diffusion\utils.py", line 36, in to_pil_image
    return TF.to_pil_image((x.clamp(-1, 1) + 1) / 2)
  File "C:\Users\my-name\.conda\envs\v-diffusion\lib\site-packages\torchvision\transforms\functional.py", line 134, in to_pil_image
    npimg = np.transpose(pic.numpy(), (1, 2, 0))
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

for clip_sample.py

Using device: cuda:0
100%|████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:12<00:00,  2.59s/it]
  0%|                                                                                            | 0/1 [00:12<?, ?it/s]
Traceback (most recent call last):
  File ".\clip_sample.py", line 239, in <module>
    main()
  File ".\clip_sample.py", line 233, in main
    run_all(args.n, args.batch_size)
  File ".\clip_sample.py", line 230, in run_all
    utils.to_pil_image(out).save(f'out_{i + j:05}.png')
  File "C:\Users\my-name\downloads\v-diffusion-pytorch\diffusion\utils.py", line 36, in to_pil_image
    return TF.to_pil_image((x.clamp(-1, 1) + 1) / 2)
  File "C:\Users\my-name\.conda\envs\v-diffusion\lib\site-packages\torchvision\transforms\functional.py", line 134, in to_pil_image
    npimg = np.transpose(pic.numpy(), (1, 2, 0))
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

 

I tried modifying the following line in cfg_sample.py or in clip_sample.py:
for j, out in enumerate(outs):

with
for j, out in enumerate(outs.cpu()): or for j, out in enumerate(outs.detach().cpu()):

and the error goes away but then the all I get is a completely black image...

Any help?
Thanks!