zoukankan      html  css  js  c++  java
  • 【E-13】TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

    一、问题源头

    定位:print(np.array(str_reparametrize).shape)

    二、原因

    numpy不能读取CUDA tensor 需要将它转化为 CPU tensor。

       

    三、解决方案

    转换成CPU tenor后即可

    本文采用

    print(str_reparametrize.cuda().data.cpu().numpy())

       

    四、建议

    Pytorch代码运行在cpu中,原来的写是对的。

    用GPU中代码运行,因为numpy在cuda中没有这种表达,需要将cuda中的数据转换到cpu中,再去使用numpy。

  • 相关阅读:
    p1706 全排列
    2089烤鸡(类似于选数问题)
    1036选数
    bfs
    A-E
    A-3
    百题A-2
    百题A-1
    二级概念题
    随记
  • 原文地址:https://www.cnblogs.com/yifanrensheng/p/13582798.html
Copyright © 2011-2022 走看看