学习Pytorch遇到的问题

一.数据类型转换    

1.pytorch的tensor类型转numpy类型

    numpy数据类型=tensor.numpy(tensor数据类型)

2.numpy类型转pytorch的tensor类型

    tensor数据类型=torch.from_numpy(numpy数据类型)

3.python的list类型转pytorch的tensor类型

    暂时还没有遇到

4.pytorch的tensor类型转python的list类型

    tensor数据类型=torch.Tensor(list数据类型)

5.tensor数据类型的device由cpu转cuda

    tensor(cpu中数据)=tensor数据类型.cpu()

6.tensor数据类型的device由cuda转cpu

    tensor(cuda中数据)=tensor数据类型.cuda()

二.数据维度

1.图像image,[1, 3, 500, 355] ---> [3, 500, 355],对数据维度进行压缩

    image = image[0]

2.图像image,[3, 500, 355] ---> [1, 3, 500, 355],对数据维度进行扩充

   image = image.unsqueenze_()

猜你喜欢

转载自blog.csdn.net/qq_35975447/article/details/86588650