Utilities#

resize_img

Resize and interpolate the image to the given shape.

resize_img#

saliency_metrics.utils.resize_img(img, output_shape, **kwargs)[source]#

Resize and interpolate the image to the given shape.

This function simply calls torch.nn.functional.interpolate if img is a torch.Tensor, or cv2.resize if img is a numpy.ndarray.

Note

If img is a numpy.ndarray, then its data type must be numpy.uint8.

Parameters
  • img (TypeVar(T, Tensor, ndarray)) – Input image. Can be torch.Tensor with shape (num_samples, num_channels, height, width) or numpy.ndarray with shape (height, width, 3) or (height, width) .

  • output_shape (Tuple[int, int]) – output shape in the format of (out_height, out_width).

  • **kwargs – other interpolation arguments. See also interpolate or resize.

Return type

TypeVar(T, Tensor, ndarray)

Returns

The interpolated image.