Contents

resizeNearest(_:sizeTensor:nearestRoundingMode:centerResult:alignCorners:layout:name:)

Resamples input images to given size using nearest neighbor sampling.

Declaration

func resizeNearest(_ imagesTensor: MPSGraphTensor, sizeTensor size: MPSGraphTensor, nearestRoundingMode: MPSGraphResizeNearestRoundingMode, centerResult: Bool, alignCorners: Bool, layout: MPSGraphTensorNamedDataLayout, name: String?) -> MPSGraphTensor

Parameters

  • imagesTensor:

    Tensor containing input images.

  • size:

    1D Int32 or Int64 tensor. A 2-element shape as [newHeight, newWidth]

  • nearestRoundingMode:

    The rounding mode to use when using nearest resampling. Default is roundPreferCeil.

  • centerResult:

    Controls if the result image is centered on the input image. When NO, the result will have the top left corner aligned

  • alignCorners:

    When YES, the result image will have the same value as the input image in the corners

  • layout:

    Specifies what layout the provided tensor is in. The returned tensor will follow the same layout. Valid layouts are NHWC, NCHW, HWC, CHW, and HW.

  • name:

    The name for the operation.

Return Value

A valid MPSGraphTensor object

Discussion

This API allows for the rounding mode to be specified. Resamples input images to given size. Result images will be distorted if size is of different aspect ratio. Resize supports the following modes: Nearest Neighbor - values are interpolated using the closest neighbor pixel Bilinear - values are computed using bilinear interpolation of 4 neighboring pixels Destination indices are computed using direct index scaling by default, with no offset added. If the centerResult parameter is true, the destination indices will be scaled and shifted to be centered on the input image. If the alignCorners parameter is true, the corners of the result images will match the input images. Scaling will be modified to a factor of (size - 1) / (inputSize - 1). When alignCorners is true, the centerResult parameter does nothing. In order to achieve the same behavior as OpenCV’s resize and TensorFlowV2’s resize,

centerResult = YES;
alginCorners = NO;

To achieve the same behavior as TensorFlowV1 resize

centerResult = NO;