代码拉取完成,页面将自动刷新
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(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 | 功能一致 |
# 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]]]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。