pytorch: torch.nn.functional.affine_grid(theta,size)

# 仍有部分疑惑

 torch.nn.functional.affine_grid(theta,size):

给定一组仿射矩阵(theta),生成一个2d的流场.通常与 grid_sample() 结合使用,用于空间变换网络.

参数:

        theta(Tensor 类型):输入的一组仿射矩阵(N*2*3)

        size(torch.Size 类型):要输出的图像的size,(N*C*H*W),比如:torch.Size((32,3,24,24))

        其中 N 是指 batch_size

返回: tensor(Tensor类型),(tensor.size=[N,H,W,2])

示例:

import torch.nn.functional as F
# Spatial transformer network forward function
def stn(self, x):
    xs = self.localization(x)
    xs = xs.view(-1, 10 * 3 * 3)
    theta = self.fc_loc(xs)
    theta = theta.view(-1, 2, 3)

    grid = F.affine_grid(theta, x.size())
    x = F.grid_sample(x, grid)

    return x

疑问1:输出tensor的物理含义是什么?经过仿射变换后的图像?还是一个新的仿射矩阵?

扫描二维码关注公众号,回复: 3754899 查看本文章

疑问2:grid 是方格的意思,affine_grid的目的是网格仿射?

应用参考:https://ptorch.com/news/139.html

 

猜你喜欢

转载自blog.csdn.net/Strive_For_Future/article/details/83244785