MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / resize

Function resize

imperative/python/megengine/functional/vision.py:779–815  ·  view source on GitHub ↗

r"""Resize the input image to the given size. Args: inp(Tensor): input images. size(Tensor): Desired output size. format(str, optional): default="NCHW", "NHWC" is also supported. imode(str, optional): interpolation mode, default="bilinear", "nearest" and "bicubic

(
    inp: Tensor,
    size: Iterable[int],
    format: str = "NCHW",
    imode: str = "bilinear",
    max_size: Optional[int] = None,
)

Source from the content-addressed store, hash-verified

777
778
779def resize(
780 inp: Tensor,
781 size: Iterable[int],
782 format: str = "NCHW",
783 imode: str = "bilinear",
784 max_size: Optional[int] = None,
785) -> Tensor:
786 r"""Resize the input image to the given size.
787
788 Args:
789 inp(Tensor): input images.
790 size(Tensor): Desired output size.
791 format(str, optional): default="NCHW", "NHWC" is also supported.
792 imode(str, optional): interpolation mode, default="bilinear", "nearest" and "bicubic" are also supported.
793 max_size(int, optional): The maximum allowed for the longer edge of the resized image. If the longer edge
794 of the image is greater than ``max_size`` after being resized according to ``size``, ``size`` will be
795 overruled so that the longer edge is equal to ``max_size``.
796 Returns:
797 resized result.
798
799 Examples:
800 >>> import numpy as np
801 >>> x = Tensor(np.arange(0, 16, dtype=np.float32).reshape(1, 1, 4, 4))
802 >>> size = Tensor([2, 2])
803 >>> y = F.vision.resize(x, size)
804 >>> y.numpy()
805 array([[[[ 2.5, 4.5],
806 [10.5, 12.5]]]], dtype=float32)
807 """
808 if imode in ["bilinear", "bicubic"]:
809 imode = imode[2:]
810 op = builtin.Resize(format=format, imode=imode)
811 if max_size is not None:
812 size = [max_size if x > max_size else x for x in size]
813 size = Tensor(size)
814 (result,) = apply(op, inp, size)
815 return result

Callers 2

forwardMethod · 0.50
DEFFunction · 0.50

Calls 2

TensorClass · 0.50
applyFunction · 0.50

Tested by

no test coverage detected