335 Star 1.5K Fork 861

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
grid_sample.md 2.73 KB
一键复制 编辑 原始数据 按行查看 历史
luojianing 提交于 2023-07-21 15:16 . replace target=blank

比较与torch.nn.functional.grid_sample的功能差异

查看源文件

torch.nn.functional.grid_sample

torch.nn.functional.grid_sample(input, grid, mode='bilinear', padding_mode='zero', align_corners=None) -> Tensor

更多内容详见torch.nn.functional.grid_sample

mindspore.ops.grid_sample

mindspore.ops.grid_sample(input, grid, mode='bilinear', padding_mode='zeros', align_corners=False)

更多内容详见mindspore.ops.grid_sample

差异对比

PyTorch:给定一个输入和一个网格,使用网格中的输入值和像素位置计算输出。input 只支持4-D(GridSampler2D)和5-D(GridSampler3D)。

MindSpore:MindSpore此API实现功能与PyTorch基本一致,不过暂不支持mode为“bicubic”。

分类 子类 PyTorch MindSpore 差异
参数 参数1 input input 功能一致
参数2 grid grid 功能一致
参数3 mode mode 功能一致,MindSpore暂不支持“bicubic”
参数4 padding_mode padding_mode 功能一致
参数5 align_corners align_corners 功能一致

代码示例1

# PyTorch
import torch
from torch import tensor
import numpy as np
input_x = tensor(np.arange(16).reshape((2, 2, 2, 2)).astype(np.float32))
grid = tensor(np.arange(0.2, 1, 0.1).reshape((2, 2, 1, 2)).astype(np.float32))
output = torch.nn.functional.grid_sample(input_x, grid)
print(output)
#tensor([[[[ 2.3000],
#          [ 2.9000]],
#
#         [[ 6.3000],
#          [ 6.9000]]],
#
#
#        [[[ 7.9200],
#          [ 4.6200]],
#
#         [[10.8000],
#          [ 6.3000]]]])

# MindSpore
from mindspore import Tensor
import mindspore.ops as ops
import numpy as np
input_x = Tensor(np.arange(16).reshape((2, 2, 2, 2)).astype(np.float32))
grid = Tensor(np.arange(0.2, 1, 0.1).reshape((2, 2, 1, 2)).astype(np.float32))
output = ops.grid_sample(input_x, grid, mode='bilinear', padding_mode='zeros', align_corners=False)
print(output)
#[[[[ 2.3      ]
#   [ 2.8999999]]
#
#  [[ 6.3      ]
#   [ 6.8999996]]]
#
#
# [[[ 7.919999 ]
#   [ 4.6200004]]
#
#  [[10.799998 ]
#   [ 6.3000007]]]]
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r2.0

搜索帮助