美文网首页
pytoch tensor常见坑

pytoch tensor常见坑

作者: CNforinsist | 来源:发表于2021-05-08 18:20 被阅读0次

    ValueError: only one element tensors can be converted to Python scalars

    1.先创建一个list,然后list append 的元素为tensor,再将list整体转为tensor时就会出现上述错,

    解决办法:

    1.先把list的tensor转换为numpy,然后再把list转换为tensor;

    2.torch.tensor([item.cpu().detach().numpy() for item in 【list】]).to(self.device)

    相关文章

      网友评论

          本文标题:pytoch tensor常见坑

          本文链接:https://www.haomeiwen.com/subject/wsexictx.html