已合并
refactor: 删除 nn 仓重复的 resize 类算子 IR 原型与 ONNX 插件 (9.1.0) #9384
refactor: 删除 nn 仓重复的 resize 类算子 IR 原型与 ONNX 插件 (9.1.0) #9384
已合并
chenfeng创建于 8月27日
共 2 个文件变更+166-667
@@ -1579,113 +1579,113 @@ Processor. \n In Ascend 950 AI Processor the dilation_d dimensions must be in [1
1579 .ATTR(offset_x, Int, 0)1579 .ATTR(offset_x, Int, 0)
1580 .OP_END_FACTORY_REG(Conv3D)1580 .OP_END_FACTORY_REG(Conv3D)
1581#endif // OPS_PROTO_DEF_CONV3D1581#endif // OPS_PROTO_DEF_CONV3D
1582- /**1582+/**
1583- *@brief Computes the transpose of convolution 2d with respect to the input.1583+*@brief Computes the transpose of convolution 2d with respect to the input.
1584- *@par Inputs:1584+*@par Inputs:
1585- * Five inputs:1585+ * Five inputs:
1586- * @li input_size: A Tensor of type int32 or int64. An integer vector1586+ * @li input_size: A Tensor of type int32 or int64. An integer vector
1587- * representing the shape of input, where input is a 4-D tensor1587+ * representing the shape of input, where input is a 4-D tensor
1588- * [batch, height, width, channels] or [batch, channels, height, width].1588+ * [batch, height, width, channels] or [batch, channels, height, width].
1589- * @li x: A Tensor of type int8, float16, bfloat16. 4-D with shape [batch,1589+ * @li x: A Tensor of type int8, float16, bfloat16. 4-D with shape [batch,
1590- * out_height, out_width, out_channels] or [batch, out_channels, out_height,1590+ * out_height, out_width, out_channels] or [batch, out_channels, out_height,
1591- * out_width].1591+ * out_width].
1592- * @li filter: A Tensor of type int8, float16, bfloat16. Must have the same1592+ * @li filter: A Tensor of type int8, float16, bfloat16. Must have the same
1593- * type as "x".1593+ * type as "x".
1594- * 4-D with shape [filter_height, filter_width, in_channels, out_channels].1594+ * 4-D with shape [filter_height, filter_width, in_channels, out_channels].
1595- * or [out_channels, filter_height, filter_width, in_channels].1595+ * or [out_channels, filter_height, filter_width, in_channels].
1596- * or [out_channels, in_channel, filter_height, filter_width].1596+ * or [out_channels, in_channel, filter_height, filter_width].
1597- * @li bias: An optional 1D tensor of type float16, float32, int32.1597+ * @li bias: An optional 1D tensor of type float16, float32, int32.
1598- * Format is "ND".1598+ * Format is "ND".
1599- * @li offset_w: An optional 1D tensor of type int8 for quantized inference. Reserved.1599+ * @li offset_w: An optional 1D tensor of type int8 for quantized inference. Reserved.
1600- *\n1600+ *\n
1601- *\n1601+ *\n
1602- * The following are the supported data types and data formats:\n1602+ * The following are the supported data types and data formats:\n
1603- *\n1603+ *\n
1604- *\n1604+ *\n
1605- | Tensor | x | filter | bias | y |\n1605+ | Tensor | x | filter | bias | y |\n
1606- |-----------|---------|---------|---------|--------|\n1606+ |-----------|---------|---------|---------|--------|\n
1607- | Data Type | float16 | float16 | float16 | float16 |\n1607+ | Data Type | float16 | float16 | float16 | float16 |\n
1608- | | bfloat16| bfloat16| float32 | bfloat16|\n1608+ | | bfloat16| bfloat16| float32 | bfloat16|\n
1609- | | float16 | float16 | float32 | float32 |\n1609+ | | float16 | float16 | float32 | float32 |\n
1610- | | float32 | float32 | float32 | float32 |\n1610+ | | float32 | float32 | float32 | float32 |\n
1611- | | int8 | int8 | int32 | int32 |\n1611+ | | int8 | int8 | int32 | int32 |\n
1612- | Format | NCHW | NCHW | ND | NCHW |\n1612+ | Format | NCHW | NCHW | ND | NCHW |\n
1613- | | NHWC | HWCN | ND | NHWC |\n1613+ | | NHWC | HWCN | ND | NHWC |\n
1614- *\n1614+ *\n
1615- * int8 for x and filter is not supported in 1971.1615+ * int8 for x and filter is not supported in 1971.
1616- * When input x and filter is int8, a dequant or requant operator must be followed.1616+ * When input x and filter is int8, a dequant or requant operator must be followed.
1617- *1617+ *
1618- *@par Attributes:1618+*@par Attributes:
1619- * @li strides: A required tuple/list of 4 integers. The stride of the sliding1619+ * @li strides: A required tuple/list of 4 integers. The stride of the sliding
1620- * window for H/W dimension. The index of H/W is the same as data_format.1620+ * window for H/W dimension. The index of H/W is the same as data_format.
1621- * @li pads: A required tuple/list of 4 integers, [top, bottom, left, right]1621+ * @li pads: A required tuple/list of 4 integers, [top, bottom, left, right]
1622- * pads on feature map.1622+ * pads on feature map.
1623- * @li groups: An optional integer of blocked connections from input channels to output1623+ * @li groups: An optional integer of blocked connections from input channels to output
1624- * channels. Defaults to "1".1624+ * channels. Defaults to "1".
1625- * @li dilations: An optional tuple/list of 4 integers, The dilation factor for each1625+ * @li dilations: An optional tuple/list of 4 integers, The dilation factor for each
1626- * dimension of input. The value of N/C dimensions must be 1. Must be with shape1626+ * dimension of input. The value of N/C dimensions must be 1. Must be with shape
1627- * [1, 1, dilation_height, dilation_width] or [1, dilation_height, dilation_width, 1].1627+ * [1, 1, dilation_height, dilation_width] or [1, dilation_height, dilation_width, 1].
1628- * Defaults to [1, 1, 1, 1].1628+ * Defaults to [1, 1, 1, 1].
1629- * @li data_format: An optional string from: "NHWC", "NCHW".1629+ * @li data_format: An optional string from: "NHWC", "NCHW".
1630- * Defaults to "NHWC". Specify the data format of the input and output data.1630+ * Defaults to "NHWC". Specify the data format of the input and output data.
1631- * @li output_padding: An optional tuple/list of integers. The size will be added1631+ * @li output_padding: An optional tuple/list of integers. The size will be added
1632- * in the output shape. The value of N/C dimensions must be 1. Defaults to [0, 0, 0, 0].1632+ * in the output shape. The value of N/C dimensions must be 1. Defaults to [0, 0, 0, 0].
1633- * @li offset_x: An optional int. Input offset, used for quantized inference.1633+ * @li offset_x: An optional int. Input offset, used for quantized inference.
1634- * The negative offset added to the input image for int8 type. Ensure offset_x1634+ * The negative offset added to the input image for int8 type. Ensure offset_x
1635- * within the effective range of int8 [-128, 127]. Defaults to "0".1635+ * within the effective range of int8 [-128, 127]. Defaults to "0".
1636- *\n1636+ *\n
1637- *\n1637+ *\n
1638- * The following value range restrictions must be met:\n1638+ * The following value range restrictions must be met:\n
1639- *\n1639+ *\n
1640- *\n1640+ *\n
1641- | Name | Field | Scope |\n1641+ | Name | Field | Scope |\n
1642- |------------------|----------|--------------|\n1642+ |------------------|----------|--------------|\n
1643- | input_size | H | [1, 4096] |\n1643+ | input_size | H | [1, 4096] |\n
1644- | | W | [1, 4096] |\n1644+ | | W | [1, 4096] |\n
1645- | x (out_backprop) | H*strideH| [1, 4096] |\n1645+ | x (out_backprop) | H*strideH| [1, 4096] |\n
1646- | | W*strideW| [1, 4096] |\n1646+ | | W*strideW| [1, 4096] |\n
1647- | filter | H | [1, 255] |\n1647+ | filter | H | [1, 255] |\n
1648- | | W | [1, 255] |\n1648+ | | W | [1, 255] |\n
1649- | y (fmap) | H | [1, 4096] |\n1649+ | y (fmap) | H | [1, 4096] |\n
1650- | | W | [1, 4096] |\n1650+ | | W | [1, 4096] |\n
1651- | strides | H | [1, 63] |\n1651+ | strides | H | [1, 63] |\n
1652- | | W | [1, 63] |\n1652+ | | W | [1, 63] |\n
1653- | pads | Top | [0, 255] |\n1653+ | pads | Top | [0, 255] |\n
1654- | | Bottom | [0, 255] |\n1654+ | | Bottom | [0, 255] |\n
1655- | | Left | [0, 255] |\n1655+ | | Left | [0, 255] |\n
1656- | | Right | [0, 255] |\n1656+ | | Right | [0, 255] |\n
1657- | groups | | [1, 65535] |\n1657+ | groups | | [1, 65535] |\n
1658- | dilations | H | [1, 255] |\n1658+ | dilations | H | [1, 255] |\n
1659- | | W | [1, 255] |\n1659+ | | W | [1, 255] |\n
1660- | output_padding | N | [0, 0] |\n1660+ | output_padding | N | [0, 0] |\n
1661- | | C | [0, 0] |\n1661+ | | C | [0, 0] |\n
1662- | | H | [0, 4096] |\n1662+ | | H | [0, 4096] |\n
1663- | | W | [0, 4096] |\n1663+ | | W | [0, 4096] |\n
1664- | Offset_x | | [-128, 127] |\n1664+ | Offset_x | | [-128, 127] |\n
1665- *\n1665+ *\n
1666- * In Atlas Training Series Product, fmap or out_backprop's H and W not support 1 when\n1666+ * In Atlas Training Series Product, fmap or out_backprop's H and W not support 1 when\n
1667- * fmap_h + pad_top + pad_bottom != (filter_height - 1) * dilation_h + 11667+ * fmap_h + pad_top + pad_bottom != (filter_height - 1) * dilation_h + 1
1668- * and filter_width > fmap_width.1668+ * and filter_width > fmap_width.
1669- * If filter_h = 1 and filter_w = 1, out_backprop_w * stride_h * stride_w1669+ * If filter_h = 1 and filter_w = 1, out_backprop_w * stride_h * stride_w
1670- * < 4096. \n1670+ * < 4096. \n
1671- *1671+ *
1672- *@par Outputs:1672+*@par Outputs:
1673- * y: A Tensor. A Tensor of type float16, bfloat16, float32, int32, and has1673+ * y: A Tensor. A Tensor of type float16, bfloat16, float32, int32, and has
1674- * same format as input_size.1674+ * same format as input_size.
1675- *\n1675+ *\n
1676- * out_backprop_height = (fmap_height + pad_top + pad_bottom -1676+ * out_backprop_height = (fmap_height + pad_top + pad_bottom -
1677- * (dilation_h * (filter_height - 1) + 1) - output_padding_height)1677+ * (dilation_h * (filter_height - 1) + 1) - output_padding_height)
1678- * / stride_h + 11678+ * / stride_h + 1
1679- *\n1679+ *\n
1680- * out_backprop_width = (fmap_width + pad_left + pad_right -1680+ * out_backprop_width = (fmap_width + pad_left + pad_right -
1681- * (dilation_w * (filter_width - 1) + 1) - output_padding_width)1681+ * (dilation_w * (filter_width - 1) + 1) - output_padding_width)
1682- * / stride_w + 11682+ * / stride_w + 1
1683- *\n1683+ *\n
1684- *1684+ *
1685- */1685+*/
1686#ifndef OPS_PROTO_DEF_CONV2DTRANSPOSE1686#ifndef OPS_PROTO_DEF_CONV2DTRANSPOSE
1687#define OPS_PROTO_DEF_CONV2DTRANSPOSE1687#define OPS_PROTO_DEF_CONV2DTRANSPOSE
1688- REG_OP(Conv2DTranspose)1688+ REG_OP(Conv2DTranspose)
1689 .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))1689 .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
1690 .INPUT(x, TensorType({DT_FLOAT16, DT_INT8, DT_BF16}))1690 .INPUT(x, TensorType({DT_FLOAT16, DT_INT8, DT_BF16}))
1691 .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8, DT_BF16}))1691 .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8, DT_BF16}))
@@ -1702,73 +1702,73 @@ Processor. \n In Ascend 950 AI Processor the dilation_d dimensions must be in [1
1702 .OP_END_FACTORY_REG(Conv2DTranspose)1702 .OP_END_FACTORY_REG(Conv2DTranspose)
1703#endif1703#endif
1704 1704 
1705- /**1705+/**
1706- *@brief Computes the transpose of convolution 3d with respect to the input.1706+*@brief Computes the transpose of convolution 3d with respect to the input.
1707 1707 
1708- *@par Inputs:1708+*@par Inputs:
1709- * @li input_size: A Tensor of type int32 or int64. An integer vector1709+ * @li input_size: A Tensor of type int32 or int64. An integer vector
1710- * representing the shape of input.1710+ * representing the shape of input.
1711- * Any value of input_size must be in [1, 2147483647].1711+ * Any value of input_size must be in [1, 2147483647].
1712- * @li x: A Tensor of type float16 or bfloat16. The format1712+ * @li x: A Tensor of type float16 or bfloat16. The format
1713- * is NDHWC or NCDHW.1713+ * is NDHWC or NCDHW.
1714- * @li filter: A Tensor of type float16 or bfloat16, currently does not support int8.1714+ * @li filter: A Tensor of type float16 or bfloat16, currently does not support int8.
1715- * The format is NDHWC, NCDHW or DHWCN.1715+ * The format is NDHWC, NCDHW or DHWCN.
1716- * height (H) and width (W) dimensions must be in [1, 511].1716+ * height (H) and width (W) dimensions must be in [1, 511].
1717- * The other dimensions of filter shape must be in [1, 2147483647].1717+ * The other dimensions of filter shape must be in [1, 2147483647].
1718- * @li bias: Optional. An optional 1D tensor of type float16 and float32. When x1718+ * @li bias: Optional. An optional 1D tensor of type float16 and float32. When x
1719- * is float16, bias is float16. When x is bfloat16, bias is float32.1719+ * is float16, bias is float16. When x is bfloat16, bias is float32.
1720- * Currently bias is not supported on Atlas 200/500 A2 Inference Product and1720+ * Currently bias is not supported on Atlas 200/500 A2 Inference Product and
1721- * Atlas A2 Training Series Product/Atlas 800I A2 Inference Product/A200I A2 Box Heterogeneous Component.1721+ * Atlas A2 Training Series Product/Atlas 800I A2 Inference Product/A200I A2 Box Heterogeneous Component.
1722- Reserved.1722+Reserved.
1723- * @li offset_w: Optional. An optional 1D tensor for quantized deconvolution.1723+ * @li offset_w: Optional. An optional 1D tensor for quantized deconvolution.
1724- * Currently offset_w is not supported on Atlas 200/500 A2 Inference Product and1724+ * Currently offset_w is not supported on Atlas 200/500 A2 Inference Product and
1725- * Atlas A2 Training Series Product/Atlas 800I A2 Inference Product/A200I A2 Box Heterogeneous Component.1725+ * Atlas A2 Training Series Product/Atlas 800I A2 Inference Product/A200I A2 Box Heterogeneous Component.
1726- Reserved.1726+Reserved.
1727 1727 
1728- *@par Attributes:1728+*@par Attributes:
1729- * @li strides: Required. A tuple/list of 5 integers. Specifies the stride of1729+ * @li strides: Required. A tuple/list of 5 integers. Specifies the stride of
1730- * the sliding window for each dimension of "x".1730+ * the sliding window for each dimension of "x".
1731- * Has the same format as "x".1731+ * Has the same format as "x".
1732- * The batch(N) and channels(C) must be 1.1732+ * The batch(N) and channels(C) must be 1.
1733- * The other values of strides must be in [1, 2147483647].1733+ * The other values of strides must be in [1, 2147483647].
1734- * @li pads: Required. A tuple/list of 6 integers.1734+ * @li pads: Required. A tuple/list of 6 integers.
1735- * [front, back, top, bottom, left, right] pads on feature map.1735+ * [front, back, top, bottom, left, right] pads on feature map.
1736- * The top, bottom, left and right must be in [0, 255].1736+ * The top, bottom, left and right must be in [0, 255].
1737- * The front and back must be in [0, 2147483647].1737+ * The front and back must be in [0, 2147483647].
1738- * @li dilations: Optional. A tuple/list of 5 integers,1738+ * @li dilations: Optional. A tuple/list of 5 integers,
1739- * The dilation factor for each dimension of input.1739+ * The dilation factor for each dimension of input.
1740- * Has the same format as "x".1740+ * Has the same format as "x".
1741- * The batch(N) and channel(C) must be 1.1741+ * The batch(N) and channel(C) must be 1.
1742- * The depth(D), height(H) and width(W) must be in [1, 255].1742+ * The depth(D), height(H) and width(W) must be in [1, 255].
1743- * In graph mode, only configuration to [1, 1, 1, 1, 1] is supported.1743+ * In graph mode, only configuration to [1, 1, 1, 1, 1] is supported.
1744- * @li groups: Optional. Number of blocked connections from input channels to1744+ * @li groups: Optional. Number of blocked connections from input channels to
1745- * output channels. Defaults to 1.1745+ * output channels. Defaults to 1.
1746- * The value of groups must be in [1, 65535].1746+ * The value of groups must be in [1, 65535].
1747- * @li data_format: Optional. A string from: "NDHWC", "NCDHW".1747+ * @li data_format: Optional. A string from: "NDHWC", "NCDHW".
1748- * Defaults to "NDHWC". Specify the data format of the input and output data.1748+ * Defaults to "NDHWC". Specify the data format of the input and output data.
1749- * @li output_padding: Optional. The size will be added in the output shape.1749+ * @li output_padding: Optional. The size will be added in the output shape.
1750- * Defaults to [0, 0, 0, 0, 0].1750+ * Defaults to [0, 0, 0, 0, 0].
1751- * Currently output_padding is not supported on Atlas 200/500 A2 Inference Product and1751+ * Currently output_padding is not supported on Atlas 200/500 A2 Inference Product and
1752- * Atlas A2 Training Series Product/Atlas 800I A2 Inference Product/A200I A2 Box Heterogeneous Component.1752+ * Atlas A2 Training Series Product/Atlas 800I A2 Inference Product/A200I A2 Box Heterogeneous Component.
1753- * In graph mode, only configuration to [0, 0, 0, 0, 0] is supported.1753+ * In graph mode, only configuration to [0, 0, 0, 0, 0] is supported.
1754- * @li offset_x: Optional. Input offset_x value. Defaults to 0.1754+ * @li offset_x: Optional. Input offset_x value. Defaults to 0.
1755- * Currently offset_x is not supported on Atlas 200/500 A2 Inference Product and1755+ * Currently offset_x is not supported on Atlas 200/500 A2 Inference Product and
1756- * Atlas A2 Training Series Product/Atlas 800I A2 Inference Product/A200I A2 Box Heterogeneous Component.1756+ * Atlas A2 Training Series Product/Atlas 800I A2 Inference Product/A200I A2 Box Heterogeneous Component.
1757- Reserved.1757+Reserved.
1758 1758 
1759- *@par Outputs:1759+*@par Outputs:
1760- * y: A Tensor. Has the same format as "x", has the type float16, float32, bfloat16.1760+ * y: A Tensor. Has the same format as "x", has the type float16, float32, bfloat16.
1761- * Any dimension of y shape must be in [1, 2147483647].1761+ * Any dimension of y shape must be in [1, 2147483647].
1762 1762 
1763- *@attention Constraints:\n1763+*@attention Constraints:\n
1764- * Due to hardware resource restrictions,1764+ * Due to hardware resource restrictions,
1765- * the operator fails to be executed in scenarios of some parameter value combinations.1765+ * the operator fails to be executed in scenarios of some parameter value combinations.
1766- * Analyze and rectify the fault based on the log information.1766+ * Analyze and rectify the fault based on the log information.
1767- * If the fault persists, visit https://www.hiascend.com/support for technical support.1767+ * If the fault persists, visit https://www.hiascend.com/support for technical support.
1768- */1768+*/
1769#ifndef OPS_PROTO_DEF_CONV3DTRANSPOSE1769#ifndef OPS_PROTO_DEF_CONV3DTRANSPOSE
1770#define OPS_PROTO_DEF_CONV3DTRANSPOSE1770#define OPS_PROTO_DEF_CONV3DTRANSPOSE
1771- REG_OP(Conv3DTranspose)1771+ REG_OP(Conv3DTranspose)
1772 .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))1772 .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
1773 .INPUT(x, TensorType({DT_FLOAT16, DT_BF16}))1773 .INPUT(x, TensorType({DT_FLOAT16, DT_BF16}))
1774 .INPUT(filter, TensorType({DT_FLOAT16, DT_BF16}))1774 .INPUT(filter, TensorType({DT_FLOAT16, DT_BF16}))
@@ -2166,113 +2166,6 @@ Processor. \n In Ascend 950 AI Processor the dilation_d dimensions must be in [1
2166 .OP_END_FACTORY_REG(MatMulV2)2166 .OP_END_FACTORY_REG(MatMulV2)
2167#endif2167#endif
2168 2168 
2169- /**
2170- * @brief Resize images to size using nearest neighbor interpolation. \n
2171- 
2172- * @par Inputs:
2173- * Inputs include:
2174- * @li x: A 4-D tensor. Represents the original image. Must set the format, supported format list ["NCHW, NHWC"].
2175- * Must be one of the following types: int8, uint8, int16, uint16, int32, int64, float16, float32,
2176- * double, bfloat16.
2177- * @li size: A 1-D int32 tensor of 2 elements: new_height, new_width.
2178- * Indicates the size of the target image, which is used to determine the height and width of the output image.
2179- * Must be the type int32. \n
2180- 
2181- * @par Attributes:
2182- * @li align_corners: An optional bool. Determines whether to align the corners of the input and output images.
2183- * If set to True, the corner pixels of the input and output images are aligned,
2184- * preserving the value of the corner pixels. When set to false,
2185- * the scaling process scales according to proportions and does not strictly align the corners.
2186- * Defaults to false.
2187- * @li half_pixel_centers: An optional bool. Determines the pixel center position during interpolation.
2188- * If this parameter is set to True, the interpolation algorithm considers the center point of the pixel
2189- * to estimate the pixel value more accurately. When set to false, the pixel center is on the integer coordinate
2190- point.
2191- * Defaults to false. \n
2192- 
2193- * @li scales: An optional listfloat. Multiplier for spatial size. Defaults to {0.0f, 0.0f} .
2194- * @par Outputs:
2195- * y: A 4-D tensor. Indicates the target image. Has the same type and format as input "x".
2196- The N, C dimension must be the same as x. \n
2197- 
2198- * @par Third-party framework compatibility
2199- * Compatible with tensorflow ResizeNearestNeighbor operator.
2200- */
2201- 
2202- REG_OP(ResizeNearestNeighborV2)
2203- .INPUT(
2204- x, TensorType(
2205- {DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_BF16}))
2206- .INPUT(size, TensorType({DT_INT32}))
2207- .OUTPUT(
2208- y, TensorType(
2209- {DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_BF16}))
2210- .ATTR(align_corners, Bool, false)
2211- .ATTR(half_pixel_centers, Bool, false)
2212- .ATTR(scales, ListFloat, {0.0f, 0.0f})
2213- .OP_END_FACTORY_REG(ResizeNearestNeighborV2)
2214- 
2215- /**
2216- * @brief Resize the input tensor. \n
2217- currently, only support resize image tensor using nearest neighbor and linear interpolation.
2218- 
2219- * @par Inputs:
2220- * Input x must be a 4-D tensor. Inputs include: \n
2221- * @li x: A Tensor. Must be one of the following types: uint8, int8, int16, \n
2222- int32, int64, float16, float, double. 4-D with shape [batch, height, width, channels] \n
2223- or shape [batch, channels, height, width].
2224- * @li roi: A 1-D float Tensor. Only takes effect when attr coordinate_transformation_mode \n
2225- is "tf_crop_and_resize". Must be one of the following types: float16, float, double.
2226- * @li scales: A 1-D float Tensor, the scale array along each dimension, Only one of \n
2227- 'scales' and 'sizes' can be specified. Must be float type.
2228- * @li sizes: A 1-D int64 Tensor, The size of the output tensor. Only one of \n
2229- 'scales' and 'sizes' can be specified. If 'size' is specified, then set scales \n
2230- to empty data (zero shape) in this operator's input list. Must be one of \n
2231- the following types: int32, int64.
2232- 
2233- * @par Attributes:
2234- * @li coordinate_transformation_mode: An optional String. how to transform \n
2235- the coordinate in the resized tensor to the coordinate in the original tensor. \n
2236- options: pytorch_half_pixel, align_corners, asymmetric, \n
2237- tf_crop_and_resize.
2238- * @li cubic_coeff_a: An optional Float. Defaults to -0.75, only used in cubic interpolation. \n
2239- other optional: -0.5
2240- * @li exclude_outside: An optional Int. Defaults to 0, If set to 1, the weight of sampling \n
2241- locations outside the tensor will be set to 0 and the weight will be renormalized \n
2242- so that their sum is 1.0.
2243- * @li extrapolation_value: An optional Float. Defaults to 0.0f. When coordinate_transformation_mode \n
2244- is "tf_crop_and_resize" and x_original is outside the range [0, length_original - 1], \n
2245- this value is used as the corresponding output value.
2246- * @li mode: An optional String. Defaults to nearest. Three interpolation modes: nearest (default), \n
2247- linear and cubic.
2248- * @li nearest_mode: An optional String. Defaults to round_prefer_floor. Four modes: round_prefer_floor, \n
2249- round_prefer_ceil, floor, ceil. Only used by nearest interpolation.
2250- 
2251- * @par Outputs:
2252- * y: A Tensor. Has the same type as x.
2253- 
2254- * @attention Constraints: \n
2255- * Input x must be a 4-D tensor.
2256- 
2257- * @par Third-party framework compatibility
2258- * Compatible with tensorflow ResizeNearestNeighborV2 operator.
2259- */
2260- 
2261- REG_OP(Resize)
2262- .INPUT(x, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
2263- .OPTIONAL_INPUT(roi, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
2264- .OPTIONAL_INPUT(scales, TensorType({DT_FLOAT}))
2265- .OPTIONAL_INPUT(sizes, TensorType({DT_INT64, DT_INT32}))
2266- .OUTPUT(
2267- y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
2268- .ATTR(coordinate_transformation_mode, String, "half_pixel")
2269- .ATTR(cubic_coeff_a, Float, -0.75)
2270- .ATTR(exclude_outside, Int, 0)
2271- .ATTR(extrapolation_value, Float, 0.0)
2272- .ATTR(mode, String, "nearest")
2273- .ATTR(nearest_mode, String, "round_prefer_floor")
2274- .OP_END_FACTORY_REG(Resize)
2275- 
2276 /**2169 /**
2277 * @brief According to the indices and indices_mask, return the value.2170 * @brief According to the indices and indices_mask, return the value.
2278 2171 
@@ -1,394 +0,0 @@
1-/**
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-#include "onnx_common.h"
12-#include "op_nn_proto_extend.h"
13- 
14-using namespace ge;
15-namespace domi {
16-int INPUT_SIZES_IS_FOUR = 4;
17-int INPUT_SIZES_IS_THREE = 3;
18-int INPUT_SIZES_IS_TWO = 2;
19- 
20-static ge::Operator CreateSliceForResize(const std::string& ori_name, ge::Operator& sizes) {
21- int32_t offsets = 2;
22- int32_t size_num = 2;
23- ge::Tensor scalar_offsets = CreateScalar(offsets, ge::DT_INT32);
24- ge::Tensor scalar_size_num = CreateScalar(size_num, ge::DT_INT32);
25- 
26- auto data_offsets = op::Const((ori_name + "_data_offsets").c_str())
27- .set_attr_value(scalar_offsets);
28- auto data_size = op::Const((ori_name + "_data_size").c_str())
29- .set_attr_value(scalar_size_num);
30- 
31- return op::Slice((ori_name + "_Slice").c_str())
32- .set_input_x(sizes)
33- .set_input_offsets(data_offsets)
34- .set_input_size(data_size);
35-}
36- 
37-static Status ParseParamsResize(const Message *op_src, Operator &op_dst) {
38- const ge::onnx::NodeProto *node = reinterpret_cast<const ge::onnx::NodeProto *>(op_src);
39- if (node == nullptr) {
40- OP_LOGE(GetOpName(op_dst).c_str(), "Dynamic cast op_src to NodeProto failed.");
41- return FAILED;
42- }
43- 
44- std::string coordinate_transformation_mode_value = "half_pixel";
45- std::string mode_value = "nearest";
46- for (auto attr : node->attribute()) {
47- if (attr.name() == "coordinate_transformation_mode" &&
48- attr.type() == ge::onnx::AttributeProto::STRING) {
49- coordinate_transformation_mode_value = attr.s();
50- } else if (attr.name() == "mode" &&
51- attr.type() == ge::onnx::AttributeProto::STRING) {
52- mode_value = attr.s();
53- } else if (attr.name() == "antialias" && attr.type() == ge::onnx::AttributeProto::INT) {
54- OP_LOGW(GetOpName(op_dst).c_str(), "Current antialias unsupported; expected type: int.");
55- } else if (attr.name() == "axes" && attr.type() == ge::onnx::AttributeProto::INTS) {
56- OP_LOGW(GetOpName(op_dst).c_str(), "Current axes unsupported; expected type: ints.");
57- } else if (attr.name() == "keep_aspect_ratio_policy" && attr.type() == ge::onnx::AttributeProto::STRING) {
58- OP_LOGW(GetOpName(op_dst).c_str(), "Current keep_aspect_ratio_policy unsupported; expected type: string.");
59- }
60- }
61- 
62- if (node->input_size() < INPUT_SIZES_IS_THREE){
63- OP_LOGE(GetOpName(op_dst).c_str(), "Input size is less than 3, cannot access input_roi and input_scales.");
64- return FAILED;
65- }
66- 
67- auto input_roi = node->input(1);
68- op_dst.SetAttr("input_roi", input_roi);
69- auto input_scales = node->input(INPUT_SIZES_IS_TWO);
70- op_dst.SetAttr("input_scales", input_scales);
71- op_dst.SetAttr("name", node->name());
72- int input_size = node->input_size();
73- if (input_size == INPUT_SIZES_IS_FOUR && node->input(INPUT_SIZES_IS_THREE).empty()) {
74- input_size = INPUT_SIZES_IS_THREE;
75- }
76- op_dst.SetAttr("input_size", input_size);
77- op_dst.SetAttr("coordinate_transformation_mode", coordinate_transformation_mode_value);
78- op_dst.SetAttr("mode", mode_value);
79-
80- op_dst.DynamicInputRegister("x", input_size);
81- op_dst.DynamicOutputRegister("y", 1);
82- op_dst.SetAttr("original_type", "ai.onnx::11::Resize");
83- return SUCCESS;
84-}
85- 
86-static Status BuildNearestResize(
87- const std::string& ori_name,
88- Operator& resize_x,
89- Operator& sizes,
90- Operator& resize_roi,
91- Operator& resize_scales,
92- const std::string& input_roi,
93- const std::string& input_scales,
94- int input_size,
95- bool align_corners,
96- bool half_pixel_centers,
97- std::vector<Operator>& inputs,
98- std::vector<std::pair<Operator, std::vector<size_t>>>& output_indexs) {
99- auto size = CreateSliceForResize(ori_name, sizes);
100- inputs.push_back(size);
101- auto ret_resize_x = ChangeFormatFromOnnx(resize_x, 0, ge::FORMAT_NCHW, false);
102- if (ret_resize_x != ge::GRAPH_SUCCESS) {
103- OP_LOGE(ori_name.c_str(), "update resize_x format failed.");
104- return FAILED;
105- }
106- auto resizeout_1 = op::ResizeNearestNeighborV2((ori_name + "_ResizeNearestNeighborV2").c_str())
107- .set_input_x(resize_x)
108- .set_input_size(size)
109- .set_attr_align_corners(align_corners)
110- .set_attr_half_pixel_centers(half_pixel_centers);
111- if (!input_roi.empty()) {
112- resizeout_1.AddControlInput(resize_roi);
113- }
114- if ((input_size == INPUT_SIZES_IS_FOUR) && (!input_scales.empty())) {
115- resizeout_1.AddControlInput(resize_scales);
116- }
117- ChangeFormatFromOnnx(resizeout_1, 0, ge::FORMAT_NCHW, false);
118- ChangeFormatFromOnnx(resizeout_1, 0, ge::FORMAT_NCHW, true);
119- output_indexs.emplace_back(resizeout_1, vector<std::size_t>{0});
120- return SUCCESS;
121-}
122- 
123-static Status BuildInterpolatingResize(
124- const std::string& ori_name,
125- Operator& resize_x,
126- Operator& sizes,
127- Operator& resize_roi,
128- Operator& resize_scales,
129- Operator& data1,
130- Operator& data2,
131- const std::string& input_roi,
132- const std::string& input_scales,
133- const std::string& coordinate_transformation_mode_value,
134- const std::string& mode_value,
135- std::vector<Operator>& inputs,
136- std::vector<std::pair<Operator, std::vector<size_t>>>& output_indexs) {
137- auto resizeout_2 = op::Resize((ori_name + "_Resize").c_str())
138- .set_input_x(resize_x)
139- .set_input_sizes(sizes)
140- .set_attr_coordinate_transformation_mode(coordinate_transformation_mode_value)
141- .set_attr_mode(mode_value);
142- inputs.push_back(sizes);
143- std::vector<float> empty_vector = {};
144- ge::Tensor empty_tensor = Vec2Tensor(empty_vector, {0}, ge::DT_FLOAT, ge::FORMAT_ND);
145- if (!input_roi.empty()) {
146- inputs.push_back(data1);
147- resizeout_2.set_input_roi(resize_roi);
148- } else {
149- auto roi = op::Const((ori_name + "_roi").c_str()).set_attr_value(empty_tensor);
150- inputs.push_back(roi);
151- resizeout_2.set_input_roi(roi);
152- }
153- if (!input_scales.empty()) {
154- inputs.push_back(data2);
155- resizeout_2.set_input_scales(resize_scales);
156- } else {
157- auto scales = op::Const((ori_name + "_scales").c_str()).set_attr_value(empty_tensor);
158- inputs.push_back(scales);
159- resizeout_2.set_input_scales(scales);
160- }
161- resizeout_2.SetAttr("resize_original_type", "onnx_resize");
162- output_indexs.emplace_back(resizeout_2, vector<std::size_t>{0});
163- return SUCCESS;
164-}
165- 
166-static Status ParseResizeModeAttrs(
167- const Operator& op,
168- std::string& coordinate_transformation_mode_value,
169- bool& half_pixel_centers,
170- bool& align_corners,
171- std::string& mode_value) {
172- coordinate_transformation_mode_value = "pytorch_half_pixel";
173- if (op.GetAttr("coordinate_transformation_mode", coordinate_transformation_mode_value) != GRAPH_SUCCESS) {
174- OP_LOGW(GetOpName(op).c_str(), "Get attr coordinate transformation mode failed, set to default.");
175- }
176- half_pixel_centers = false;
177- align_corners = false;
178- if (coordinate_transformation_mode_value == "pytorch_half_pixel" ||
179- coordinate_transformation_mode_value == "half_pixel") {
180- half_pixel_centers = true;
181- } else if (coordinate_transformation_mode_value == "align_corners") {
182- align_corners = true;
183- }
184- 
185- if (op.GetAttr("mode", mode_value) != GRAPH_SUCCESS) {
186- OP_LOGE(GetOpName(op).c_str(), "Get attr mode failed, set to default.");
187- return FAILED;
188- }
189- return SUCCESS;
190-}
191- 
192-static Status BuildResizeSizesFromInputs(
193- const std::string& ori_name,
194- int input_size,
195- ge::Operator& resize_x,
196- ge::Operator& resize_scales,
197- ge::Operator& resize_sizes,
198- ge::Operator& sizes) {
199- if (input_size == INPUT_SIZES_IS_FOUR) {
200- sizes = op::Cast((ori_name + "_Cast0").c_str()).set_input_x(resize_sizes).set_attr_dst_type(ge::DT_INT32);
201- } else if (input_size == INPUT_SIZES_IS_THREE) {
202- int dtype = 0; // DT_INT32
203- int sizes_type = 3; // e.g., DT_INT64
204- auto resize = op::Shape((ori_name + "_Shape").c_str()).set_input_x(resize_x);
205- auto resize_cast = op::Cast((ori_name + "_Cast0").c_str()).set_input_x(resize).set_attr_dst_type(dtype);
206- auto mul_sizes = op::Mul((ori_name + "_Mul").c_str()).set_input_x1(resize_cast).set_input_x2(resize_scales);
207- sizes = op::Cast((ori_name + "_Cast1").c_str()).set_input_x(mul_sizes).set_attr_dst_type(sizes_type);
208- } else {
209- OP_LOGE("ParseOpToGraphResize", "The input_size is error.");
210- return FAILED;
211- }
212- return SUCCESS;
213-}
214- 
215-static Status ParseOpToGraphResize(const Operator& op, Graph& graph) {
216- std::string ori_name;
217- if (op.GetAttr("name", ori_name) != SUCCESS) {
218- OP_LOGE(GetOpName(op).c_str(), "get name from op failed.");
219- return FAILED;
220- }
221- std::string input_roi, input_scales;
222- op.GetAttr("input_roi", input_roi); // intentionally unchecked
223- op.GetAttr("input_scales", input_scales);
224- auto data0 = op::Data((ori_name + "_data0").c_str()).set_attr_index(0);
225- auto resize_x = op::Identity((ori_name + "_x").c_str()).set_input_x(data0);
226- auto data1 = op::Data((ori_name + "_data1").c_str()).set_attr_index(1);
227- auto resize_roi = op::Identity((ori_name + "_roi").c_str()).set_input_x(data1);
228- auto data2 = op::Data((ori_name + "_data2").c_str()).set_attr_index(2);
229- auto resize_scales = op::Identity((ori_name + "_scales").c_str()).set_input_x(data2);
230- auto data3 = op::Data((ori_name + "_data3").c_str()).set_attr_index(3);
231- auto resize_sizes = op::Identity((ori_name + "_sizes").c_str()).set_input_x(data3);
232- int input_size = 0;
233- if (op.GetAttr("input_size", input_size) != SUCCESS) {
234- OP_LOGE(GetOpName(op).c_str(), "get input_size from op failed");
235- return FAILED;
236- }
237- std::string coordinate_transformation_mode_value;
238- bool half_pixel_centers = false, align_corners = false;
239- std::string mode_value;
240- if (ParseResizeModeAttrs(op, coordinate_transformation_mode_value, half_pixel_centers, align_corners, mode_value) != SUCCESS) {
241- return FAILED;
242- }
243- ge::Operator sizes;
244- if (BuildResizeSizesFromInputs(ori_name, input_size, resize_x, resize_scales, resize_sizes, sizes) != SUCCESS) {
245- return FAILED;
246- }
247- std::vector<Operator> inputs{data0};
248- std::vector<std::pair<Operator, std::vector<size_t>>> output_indexs;
249- if (mode_value == "nearest") {
250- auto status = BuildNearestResize(ori_name, resize_x, sizes, resize_roi, resize_scales,
251- input_roi, input_scales, input_size, align_corners, half_pixel_centers, inputs, output_indexs);
252- if (status != SUCCESS) return status;
253- } else if (mode_value == "linear" || mode_value == "cubic") {
254- auto status = BuildInterpolatingResize(ori_name, resize_x, sizes, resize_roi, resize_scales,
255- data1, data2, input_roi, input_scales, coordinate_transformation_mode_value, mode_value, inputs, output_indexs);
256- if (status != SUCCESS) return status;
257- } else {
258- OP_LOGE(GetOpName(op).c_str(), "Unsupported interpolation mode.");
259- return FAILED;
260- }
261- graph.SetInputs(inputs).SetOutputs(output_indexs);
262- return SUCCESS;
263-}
264- 
265-static Status ParseParamsResizeV10(const Message *op_src, Operator &op_dst) {
266- const ge::onnx::NodeProto *node = reinterpret_cast<const ge::onnx::NodeProto *>(op_src);
267- if (node == nullptr) {
268- OP_LOGE(GetOpName(op_dst).c_str(), "Dynamic cast op_src to NodeProto failed.");
269- return FAILED;
270- }
271- 
272- std::string mode_value = "nearest";
273- for (auto attr : node->attribute()) {
274- if (attr.name() == "mode" && attr.type() == ge::onnx::AttributeProto::STRING) {
275- mode_value = attr.s();
276- }
277- }
278- op_dst.SetAttr("mode", mode_value);
279- op_dst.SetAttr("name", node->name());
280- op_dst.DynamicInputRegister("x", INPUT_SIZES_IS_TWO);
281- op_dst.DynamicOutputRegister("y", 1);
282- op_dst.SetAttr("original_type", "ai.onnx::10::Resize");
283- return SUCCESS;
284-}
285- 
286-static Status BuildNearestResizeV10(
287- const std::string& ori_name,
288- Operator& resize_x,
289- Operator& sizes,
290- std::vector<Operator>& inputs,
291- std::vector<std::pair<Operator, std::vector<size_t>>>& output_indexs) {
292- auto size = CreateSliceForResize(ori_name, sizes);
293- inputs.push_back(size);
294- auto ret_resize_x = ChangeFormatFromOnnx(resize_x, 0, ge::FORMAT_NCHW, false);
295- if (ret_resize_x != ge::GRAPH_SUCCESS) {
296- OP_LOGE(ori_name.c_str(), "update resize_x format failed.");
297- return FAILED;
298- }
299- bool half_pixel_centers = false;
300- bool align_corners = false;
301- auto resizeout_1 = op::ResizeNearestNeighborV2((ori_name + "_ResizeNearestNeighborV2").c_str())
302- .set_input_x(resize_x)
303- .set_input_size(size)
304- .set_attr_align_corners(align_corners)
305- .set_attr_half_pixel_centers(half_pixel_centers);
306- ChangeFormatFromOnnx(resizeout_1, 0, ge::FORMAT_NCHW, false);
307- ChangeFormatFromOnnx(resizeout_1, 0, ge::FORMAT_NCHW, true);
308- output_indexs.emplace_back(resizeout_1, vector<std::size_t>{0});
309- return SUCCESS;
310-}
311- 
312-static Status BuildLinearResizeV10(
313- const std::string& ori_name,
314- Operator& resize_x,
315- Operator& sizes,
316- const std::string& mode_value,
317- std::vector<Operator>& inputs,
318- std::vector<std::pair<Operator, std::vector<size_t>>>& output_indexs) {
319- auto data2 = op::Const((ori_name + "_data2").c_str()).set_attr_value(0);
320- auto data3 = op::Const((ori_name + "_data3").c_str()).set_attr_value(0);
321- auto resizeout_2 = op::Resize((ori_name + "_Resize").c_str())
322- .set_input_x(resize_x)
323- .set_input_sizes(sizes)
324- .set_input_roi(data2)
325- .set_input_scales(data3)
326- .set_attr_mode(mode_value);
327- inputs.push_back(data2);
328- inputs.push_back(data3);
329- resizeout_2.SetAttr("resize_original_type", "onnx_resize");
330- output_indexs.emplace_back(resizeout_2, vector<std::size_t>{0});
331- return SUCCESS;
332-}
333- 
334-static Status ParseOpToGraphResizeV10(const Operator& op, Graph& graph) {
335- std::string ori_name;
336- if (op.GetAttr("name", ori_name) != SUCCESS) {
337- OP_LOGE(GetOpName(op).c_str(), "get name from op failed.");
338- return FAILED;
339- }
340- 
341- auto data0 = op::Data((ori_name + "_data0").c_str()).set_attr_index(0);
342- auto data1 = op::Data((ori_name + "_data1").c_str()).set_attr_index(1);
343- auto resize_x = op::Identity((ori_name + "_Identity").c_str()).set_input_x(data0);
344-
345- int dtype = 0;
346- int sizes_type = 3;
347- auto resize = op::Shape((ori_name + "_Shape").c_str()).set_input_x(resize_x);
348- auto resize_cast = op::Cast((ori_name + "_Cast0").c_str()).set_input_x(resize).set_attr_dst_type(dtype);
349- auto mul_sizes = op::Mul((ori_name + "_Mul").c_str()).set_input_x1(resize_cast).set_input_x2(data1);
350- auto sizes = op::Cast((ori_name + "_Cast1").c_str()).set_input_x(mul_sizes).set_attr_dst_type(sizes_type);
351- 
352- std::string mode_value;
353- if (op.GetAttr("mode", mode_value) != GRAPH_SUCCESS) {
354- OP_LOGE(GetOpName(op).c_str(), "Get attr mode failed, set to default.");
355- return FAILED;
356- }
357- 
358- std::vector<Operator> inputs{data0, data1};
359- std::vector<std::pair<Operator, std::vector<size_t> > > output_indexs;
360- if (mode_value == "nearest") {
361- auto status = BuildNearestResizeV10(ori_name, resize_x, sizes, inputs, output_indexs);
362- if (status != SUCCESS) return status;
363- } else if (mode_value == "linear") {
364- auto status = BuildLinearResizeV10(ori_name, resize_x, sizes, mode_value, inputs, output_indexs);
365- if (status != SUCCESS) return status;
366- } else {
367- OP_LOGE(GetOpName(op).c_str(), "Unsupported interpolation mode.");
368- return FAILED;
369- }
370- graph.SetInputs(inputs).SetOutputs(output_indexs);
371- return SUCCESS;
372-}
373- 
374-REGISTER_CUSTOM_OP("PartitionedCall")
375- .FrameworkType(ONNX)
376- .OriginOpType({ge::AscendString("ai.onnx::11::Resize"),
377- ge::AscendString("ai.onnx::12::Resize"),
378- ge::AscendString("ai.onnx::13::Resize"),
379- ge::AscendString("ai.onnx::14::Resize"),
380- ge::AscendString("ai.onnx::15::Resize"),
381- ge::AscendString("ai.onnx::16::Resize"),
382- ge::AscendString("ai.onnx::17::Resize"),
383- ge::AscendString("ai.onnx::18::Resize")})
384- .ParseParamsFn(ParseParamsResize)
385- .ParseOpToGraphFn(ParseOpToGraphResize)
386- .ImplyType(ImplyType::TVM);
387- 
388-REGISTER_CUSTOM_OP("PartitionedCall")
389- .FrameworkType(ONNX)
390- .OriginOpType({ge::AscendString("ai.onnx::10::Resize")})
391- .ParseParamsFn(ParseParamsResizeV10)
392- .ParseOpToGraphFn(ParseOpToGraphResizeV10)
393- .ImplyType(ImplyType::TVM);
394-} // namespace domi