---
title: GridSample
description: "给定一个输入Tensor x和一个输入Tensor grid网格，然后根据grid中每个位置提供的坐标信息，将x中对应位置的值填充到网格指定位置，得到最终输出Tensor y。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/aolapi/atlasoxol_09_0071.html
sourcePath: /source/zh/canncommercial/900/API/aolapi/atlasoxol_09_0071.html
indexId: d928e9d223ffa331321718fcaf92b47ae4b69ff49bf1c00fc90385cbc7c2aa1563
---
# GridSample

#### 功能

给定一个输入Tensor x和一个输入Tensor grid网格，然后根据grid中每个位置提供的坐标信息，将x中对应位置的值填充到网格指定位置，得到最终输出Tensor y。


#### 输入

- x：四维Tensor，形状为[batch, channels, height_in, width_in]，支持非连续Tensor，数据格式支持ND，数据类型：float16、float32。
- grid：四维Tensor，形状为[batch, height_out, width_out, 2]，支持非连续Tensor，数据格式支持ND，数据类型：float16、float32。


#### 属性

- interpolation_mode：数据类型string，指定插值方法的可选字符串，0：bilinear（双线性插值），1：nearest（最邻近插值），2：bicubic（双三次插值）。目前只支持bilinear和nearest，默认是0。
- padding_mode：数据类型string，指定填充模式，即当（x, y）取值超过输入特征图采样范围时，返回一个特定值，有0：zeros、1：border、2：reflection三种模式。
- align_corners：数据类型bool，默认为0，如果为“true”，则输入和输出tensor的角点像素的中心对齐。默认为“false”。


#### 输出

y：四维Tensor，形状为[batch, channels, height_out, width_out]，且数据类型与x的数据类型一致，支持非连续Tensor，数据格式支持ND，数据类型：float16, float32。


#### 约束与限制

无。


#### 支持的ONNX版本

Opset v16
