mindspore.ops.ResizeBicubic

class mindspore.ops.ResizeBicubic(align_corners=False, half_pixel_centers=False)[源代码]

使用双三次插值调整图像大小到指定的大小。

警告

这是一个实验性API,后续可能修改或删除。

参数:
  • align_corners (bool,可选) - 如果为True,则输入输出图像四个角像素的中心被对齐,同时保留角像素处的值。默认值:False。

  • half_pixel_centers (bool,可选) - 是否使用半像素中心对齐。如果设置为True,那么 align_corners 应该设置为False。默认值:False。

输入:
  • images (Tensor) -输入图像为四维的Tensor,其shape为 \((batch, channels, height, width)\) ,支持的数据类型有:float16、float32、float64。

  • size (Tensor) - 一维Tensor, 含有两个元素,分别为new_height、new_width,以表示输出图像的高和宽。支持的数据类型为int32。

输出:

四维Tensor,其shape为 \((batch, channels, new\_height, new\_width)\) ,且数据类型与 images 一致。

异常:
  • TypeError - images 的数据类型不支持。

  • TypeError - size 的数据类型不是int32。

  • TypeError - align_corners 不是bool类型。

  • TypeError - half_pixel_centers 不是bool类型。

  • ValueError - images 的维度不是4。

  • ValueError - size 的维度不是1。

  • ValueError - size 所含元素的个数不是2。

  • ValueError - size 中的元素不全是正数。

  • ValueError - align_cornershalf_pixel_centers 同时为True。

支持平台:

Ascend GPU CPU

样例:

>>> class NetResizeBicubic(nn.Cell):
...     def __init__(self):
...         super(NetResizeBicubic, self).__init__()
...         align_corners = False
...         half_pixel_centers = False
...         self.resize = ops.ResizeBicubic(align_corners, half_pixel_centers)
...
...     def construct(self, images, size):
...         return self.resize(images, size)
...
>>> images = Tensor(np.array([1, 2, 3, 4]).reshape(1, 1, 2, 2).astype(np.float32))
>>> size = Tensor([1, 4], mindspore.int32)
>>> resizebicubic = NetResizeBicubic()
>>> output = resizebicubic(images, size)
>>> print(output)
    [[[[1. 1.5 2. 2.09375]]]]