pooling2d

功能说明

通过不同的池化方式,对tensor_in上不同的滑动窗口进行信号的采样。

池化方式支持MAX、AVG、GMP、GAP四种:

如下图,tensor_in按照pooling_mode为MAX、padding_mode为SAME时池化结果。

其中:

您可以在“te/lang/cce/te_compute/pooling2d_compute.py”查看接口定义。

约束说明

此接口暂不支持与其他TBE DSL计算接口混合使用。

  • ub_size为UB可用大小。
  • out_w为输出结果tensor的W。
  • window_h为window的height。
  • window_w为window的width。
  • C0为tensor_in的C0。
  • SIZE_OF_FP16为float16的大小。

函数原型

te.lang.cce.pooling2d(tensor_in, window, stride, pooling_mode, padding_mode="SAME", pad = (0,0,0,0), dilation = (1,1), data_mode=1, ceil_mode=0, fusion_params=None, impl_mode="high_performance")

参数说明

返回值

res_tensor:输出tensor,tvm.tensor类型,为符合5D-NC1HWC0格式排布的tensor。

将tensor_in 的shape信息记为[N, C1, H, W, C0=16],window 的shape信息记为 [F, F],stride 信息记为 [S, S],则:

MAX and AVG 的VALID模式与SAME模式下输出tensor的shape信息计算方式分别如下所示:

GMP and GAP的VALID模式下输出tensor的shape信息计算方式如下:

支持的芯片型号

Atlas 200/300/500 推理产品

Atlas 训练系列产品

调用示例

from tbe import tvm
import te.lang.cce
shape = (1, 2, 416, 416, 16) 
input_dtype = "float16"
data = tvm.placeholder(shape, name="data", dtype=input_dtype) 
res = te.lang.cce.pooling2d(data, (3, 3), (2, 2), "AVG", "SAME")
# res.shape = (1, 2, 208, 208, 16)