1.维度转换
permute(shape)函数,示例:
input = torch.rand(1, 3, 303, 303)
torch.Size([1, 3, 303, 303])
input = input.permute(0,2,1,3)
torch.Size([1, 303, 3, 303])
2.增加维度
unsqueeze(arg)函数,示例:
input = torch.rand(1, 3, 303, 303)
torch.Size([1, 3, 303, 303])
input = input.unsqueeze(4)
torch.Size([1, 3, 303, 303, 1])
3.减少维度
squeeze(arg)函数,如果维度是1 的则去掉对应维度,否则不变,示例:
input = torch.rand(1, 3, 303, 303)
torch.Size([1, 3, 303, 303])
input = input.squeeze(0)
torch.Size([ 3, 303, 303])
4.多维(3维以上)矩阵相乘
5.矩阵相加
6.将两个张量(tensor)拼接在一起
torch.cat((a,b),0)
7.Numpy转Tensor方式
(1)images = torch.tensor(images,dtype=torch.float32)
(2)images = torch.from_numpy(images)