Pytorch
Pytorch的使用经验记录~
Small_Lemon_Tree
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
tensor.squeeze()和tensor.unsqueeze()
示例文件 test.pyimport torchA = torch.arange(6)A = A.reshape(1, 1, 2, 3, -1)B = A.squeeze()print(A)print(B)C = B.unsqueeze(0)D = B.unsqueeze(1)E = B.unsqueeze(2)print(C)print(D)print(E)终端命令行和运行结果<user>python test.pytensor([[[[[0],原创 2020-07-11 22:28:23 · 2307 阅读 · 0 评论 -
tensor.view()和tensor.reshape()和tensor.resize_()
tensor.view()和tensor.reshape()示例文件 test.pyimport torcha = torch.randint(0, 10, (3, 4))b = a.view(2, 6)c = a.reshape(2, 6)print(id(a)==id(b), id(a)==id(c), id(b)==id(c))print(id(a.storage())==id(b.storage()), id(a.storage())==id(c.storage()),原创 2020-07-11 09:29:01 · 10676 阅读 · 0 评论 -
tensor.permute()和tensor.transpose()
示例文件 test.pyimport torchcor1 = torch.arange(5).float()cor2 = torch.arange(4).float()print(cor1)print(cor2)X, Y = torch.meshgrid(cor1, cor2)print(X)print(X.permute(0, 1))print(X.permute(1, 0))print(X.transpose(0, 1))print(X.transpose(1, 0))终端原创 2020-07-10 23:55:59 · 4848 阅读 · 0 评论 -
torch.meshgrid()三维
示例文件 test.pyimport torchcor1 = torch.arange(5).float()cor2 = torch.arange(4).float()print(cor1)print(cor2)X, Y = torch.meshgrid(cor1, cor2)print(X)print(Y)cor1 = torch.arange(3).float()cor2 = torch.arange(5).float()cor3 = torch.arange(4).floa原创 2020-07-10 23:20:17 · 1553 阅读 · 0 评论 -
torch.meshgrid()
示例文件 test.pyimport torchcor1 = torch.arange(5).float()cor2 = torch.arange(4).float()print(cor1)print(cor2)X, Y = torch.meshgrid(cor1, cor2)print(X)print(Y)终端命令行及运行结果<user>python test.pytensor([0., 1., 2., 3., 4.])tensor([0., 1., 2., 3.原创 2020-07-10 20:56:14 · 271 阅读 · 0 评论 -
torch.range()和torch.arange()
示例文件 test.pyimport torchx = torch.arange(0, 6)print(x)print(x.type())y = torch.range(0, 6)print(y)print(y.type())终端命令行和运行结果<user>python test.pytensor([0, 1, 2, 3, 4, 5])torch.LongTensortensor([0., 1., 2., 3., 4., 5., 6.])torch.FloatTen原创 2020-07-10 20:24:04 · 1669 阅读 · 0 评论 -
基本张量类型的转换
Tensor类型的转换Pytorch数据类型的转换可以通过三个方式:1)调用Tensor成员函数long(),int(),double(),float(),byte()2)调用Tensor成员函数type(),传入数据类型3)调用Tensor成员函数type_as(),传入实例对象示例文件 test.pyimport torcha = torch.randn(2, 3)print(a.type())b = a.int()c = a.type(torch.LongTensor)pri原创 2020-07-10 17:44:27 · 1845 阅读 · 0 评论 -
基本张量类型及检测
基本类型Data typeCPU tensorGPU tensor32-bit floating pointtorch.FloatTensortorch.cuda.FloatTensor64-bit floating pointtorch.DoubleTensortorch.cuda.DoubleTensor16-bit floating pointN/Atorch.cuda.HalfTensor8-bit integer(unsigned)torch原创 2020-07-10 17:22:47 · 466 阅读 · 0 评论 -
CPU和GPU张量类型转换
(1) CPU张量 ----> GPU张量,使用Tensor.cuda()(2) GPU张量 ----> CPU张量,使用Tensor.cpu()我们可以通过torch.cuda.is_available()函数来判断当前的环境是否支持GPU,如果支持,则返回GPU类型,否则返回CPU类型。def commonType(Tensor): if torch.cuda.is_available(): cuda = "cuda:0" return Tens原创 2020-07-10 16:57:36 · 1407 阅读 · 0 评论
分享