meshgrid生成坐标

  1. 例如生成2D卷积核坐标
    \left[ \begin{matrix} (-1,-1)&(-1,0)&(-1,1)\\ (0,-1)&(0,0)&(0,1)\\ (1,-1)&(1,0)&(1,1) \end{matrix} \right]

    x, y = torch.meshgrid(torch.linspace(-1, 1, 3),
                          torch.linspace(-1, 1, 3))
    # x.size() is [3, 3]
    n_x_y = torch.cat((x.reshape(-1,1), y.reshape(-1,1)),
                  1)
    
    • 得到的坐标为行索引坐标
  2. 生成3D卷积坐标
    \left[ \begin{matrix} (-1,-1,1)&(-1,0,1)&(-1,1,1)\\ (0,-1,1)&(0,0,1)&(0,1,1)\\ (1,-1,1)&(1,0,1)&(1,1,1) \end{matrix} \right] \left[ \begin{matrix} (-1,-1,2)&(-1,0,2)&(-1,1,2)\\ (0,-1,2)&(0,0,2)&(0,1,2)\\ (1,-1,2)&(1,0,2)&(1,1,2) \end{matrix} \right]

x, y, z = torch.meshgrid(torch.linspace(-1,1,3),
                         torch.linspace(-1,1,3),
                         torch.linspace(1,2,2))
# x.size() is [3, 3, 2]
# z.size() is [3, 3, 2]
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。