pytorch实现图像的平移

w=[]
for i in range(14):
    w1=[]
    for j in range(14):
        w1.append(j)
    w.append(w1)
w=np.array(w)
w=np.reshape(w,(1,1,14,14))
t=torch.Tensor(w)
w1=torchvision.transforms.functional.affine(t,translate=(1,0),angle=0,scale=1,shear=0)
print(w1)
输出:

tensor([[[[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.],
[ 0., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.]]]])

posted @ 2021-10-12 18:40  祥瑞哈哈哈  阅读(615)  评论(0)    收藏  举报