Unverified Commit 3269278e authored by jason_w's avatar jason_w Committed by GitHub
Browse files

[Fix] Fix type hint in geometric (#2799)

parent 0c23eb02
...@@ -16,13 +16,13 @@ except ImportError: ...@@ -16,13 +16,13 @@ except ImportError:
def _scale_size( def _scale_size(
size: Tuple[int, int], size: Tuple[int, int],
scale: Union[float, int, tuple], scale: Union[float, int, Tuple[float, float], Tuple[int, int]],
) -> Tuple[int, int]: ) -> Tuple[int, int]:
"""Rescale a size by a ratio. """Rescale a size by a ratio.
Args: Args:
size (tuple[int]): (w, h). size (tuple[int]): (w, h).
scale (float | tuple(float)): Scaling factor. scale (float | int | tuple(float) | tuple(int)): Scaling factor.
Returns: Returns:
tuple[int]: scaled size. tuple[int]: scaled size.
...@@ -128,7 +128,8 @@ def imresize_to_multiple( ...@@ -128,7 +128,8 @@ def imresize_to_multiple(
img: np.ndarray, img: np.ndarray,
divisor: Union[int, Tuple[int, int]], divisor: Union[int, Tuple[int, int]],
size: Union[int, Tuple[int, int], None] = None, size: Union[int, Tuple[int, int], None] = None,
scale_factor: Union[float, Tuple[float, float], None] = None, scale_factor: Union[float, int, Tuple[float, float], Tuple[int, int],
None] = None,
keep_ratio: bool = False, keep_ratio: bool = False,
return_scale: bool = False, return_scale: bool = False,
interpolation: str = 'bilinear', interpolation: str = 'bilinear',
...@@ -145,9 +146,10 @@ def imresize_to_multiple( ...@@ -145,9 +146,10 @@ def imresize_to_multiple(
divisor. If divisor is a tuple, divisor should be divisor. If divisor is a tuple, divisor should be
(w_divisor, h_divisor). (w_divisor, h_divisor).
size (None | int | tuple[int]): Target size (w, h). Default: None. size (None | int | tuple[int]): Target size (w, h). Default: None.
scale_factor (None | float | tuple[float]): Multiplier for spatial scale_factor (None | float | int | tuple[float] | tuple[int]):
size. Should match input size if it is a tuple and the 2D style is Multiplier for spatial size. Should match input size if it is a
(w_scale_factor, h_scale_factor). Default: None. tuple and the 2D style is (w_scale_factor, h_scale_factor).
Default: None.
keep_ratio (bool): Whether to keep the aspect ratio when resizing the keep_ratio (bool): Whether to keep the aspect ratio when resizing the
image. Default: False. image. Default: False.
return_scale (bool): Whether to return `w_scale` and `h_scale`. return_scale (bool): Whether to return `w_scale` and `h_scale`.
...@@ -215,16 +217,16 @@ def imresize_like( ...@@ -215,16 +217,16 @@ def imresize_like(
def rescale_size(old_size: tuple, def rescale_size(old_size: tuple,
scale: Union[float, int, tuple], scale: Union[float, int, Tuple[int, int]],
return_scale: bool = False) -> tuple: return_scale: bool = False) -> tuple:
"""Calculate the new size to be rescaled to. """Calculate the new size to be rescaled to.
Args: Args:
old_size (tuple[int]): The old size (w, h) of image. old_size (tuple[int]): The old size (w, h) of image.
scale (float | tuple[int]): The scaling factor or maximum size. scale (float | int | tuple[int]): The scaling factor or maximum size.
If it is a float number, then the image will be rescaled by this If it is a float number or an integer, then the image will be
factor, else if it is a tuple of 2 integers, then the image will rescaled by this factor, else if it is a tuple of 2 integers, then
be rescaled as large as possible within the scale. the image will be rescaled as large as possible within the scale.
return_scale (bool): Whether to return the scaling factor besides the return_scale (bool): Whether to return the scaling factor besides the
rescaled image size. rescaled image size.
...@@ -255,7 +257,7 @@ def rescale_size(old_size: tuple, ...@@ -255,7 +257,7 @@ def rescale_size(old_size: tuple,
def imrescale( def imrescale(
img: np.ndarray, img: np.ndarray,
scale: Union[float, Tuple[int, int]], scale: Union[float, int, Tuple[int, int]],
return_scale: bool = False, return_scale: bool = False,
interpolation: str = 'bilinear', interpolation: str = 'bilinear',
backend: Optional[str] = None backend: Optional[str] = None
...@@ -264,10 +266,10 @@ def imrescale( ...@@ -264,10 +266,10 @@ def imrescale(
Args: Args:
img (ndarray): The input image. img (ndarray): The input image.
scale (float | tuple[int]): The scaling factor or maximum size. scale (float | int | tuple[int]): The scaling factor or maximum size.
If it is a float number, then the image will be rescaled by this If it is a float number or an integer, then the image will be
factor, else if it is a tuple of 2 integers, then the image will rescaled by this factor, else if it is a tuple of 2 integers, then
be rescaled as large as possible within the scale. the image will be rescaled as large as possible within the scale.
return_scale (bool): Whether to return the scaling factor besides the return_scale (bool): Whether to return the scaling factor besides the
rescaled image. rescaled image.
interpolation (str): Same as :func:`resize`. interpolation (str): Same as :func:`resize`.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment