






from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    get_resize_output_image_size,
    normalize,
    pad,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging
from ...utils.import_utils import is_vision_available


a	: Optional[Any]      =				logging.get_logger(__name__)


if is_vision_available():
       import PIL
class 					a					(				lowercase__     ):



      """simple docstring"""


      a						:				Dict							 =			['pixel_values']
      def __init__(   self      :    Optional[Any]	,   __lowercase      :    bool = True	,   __lowercase      :    Dict[str, int] = None	,   __lowercase      :    PILImageResampling = PILImageResampling.BILINEAR	,   __lowercase      :    bool = True	,   __lowercase      :    bool = False	,   __lowercase      :    bool = True	,   __lowercase      :    bool = True	,   __lowercase      :    Union[int, float] = 1 / 255	,   __lowercase      :    bool = True	,   __lowercase      :    Optional[Union[float, List[float]]] = None	,   __lowercase      :    Optional[Union[float, List[float]]] = None	,   **__lowercase      :    Dict	,   )							->   None:
        super().__init__(**__lowercase      )

        __UpperCAmelCase							:			Optional[Any]     =						size if size is not None else {"""height""": 2560, """width""": 1920}
        if isinstance(__lowercase	,   (tuple, list)      ):
          # The previous feature extractor size parameter was in (width, height) format
          __UpperCAmelCase							:			Dict     =						size[::-1]
        __UpperCAmelCase							:			Optional[Any]     =						get_size_dict(__lowercase      )

        __UpperCAmelCase							:			Any     =						do_resize
        __UpperCAmelCase							:			str     =						size
        __UpperCAmelCase							:			List[Any]     =						resample
        __UpperCAmelCase							:			Dict     =						do_thumbnail
        __UpperCAmelCase							:			List[str]     =						do_align_long_axis
        __UpperCAmelCase							:			str     =						do_pad
        __UpperCAmelCase							:			Any     =						do_rescale
        __UpperCAmelCase							:			Optional[int]     =						rescale_factor
        __UpperCAmelCase							:			str     =						do_normalize
        __UpperCAmelCase							:			Optional[Any]     =						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        __UpperCAmelCase							:			Tuple     =						image_std if image_std is not None else IMAGENET_STANDARD_STD
      def 			UpperCAmelCase   (   self      :    List[str]	,   __lowercase      :    np.ndarray	,   __lowercase      :    Dict[str, int]	,   __lowercase      :    Optional[Union[str, ChannelDimension]] = None      )							->   np.ndarray:
        __UpperCAmelCase   ,				__UpperCAmelCase							:			str     =						get_image_size(__lowercase      )
        __UpperCAmelCase   ,				__UpperCAmelCase							:			List[str]     =						size["""height"""], size["""width"""]

        if (output_width < output_height and input_width > input_height) or (
            output_width > output_height and input_width < input_height
        ):
          __UpperCAmelCase							:			Dict     =						np.rotaa(__lowercase	,   3      )

        if data_format is not None:
          __UpperCAmelCase							:			List[str]     =						to_channel_dimension_format(__lowercase	,   __lowercase      )

        return image
      def 			UpperCAmelCase   (   self      :    Tuple	,   __lowercase      :    np.ndarray	,   __lowercase      :    Dict[str, int]	,   __lowercase      :    bool = False	,   __lowercase      :    Optional[Union[str, ChannelDimension]] = None	,   )							->   np.ndarray:
        __UpperCAmelCase   ,				__UpperCAmelCase							:			List[str]     =						size["""height"""], size["""width"""]
        __UpperCAmelCase   ,				__UpperCAmelCase							:			List[Any]     =						get_image_size(__lowercase      )

        __UpperCAmelCase							:			Dict     =						output_width - input_width
        __UpperCAmelCase							:			Tuple     =						output_height - input_height

        if random_padding:
          __UpperCAmelCase							:			List[str]     =						np.random.randint(low=0	,   high=delta_height + 1      )
          __UpperCAmelCase							:			Optional[int]     =						np.random.randint(low=0	,   high=delta_width + 1      )
        else:
          __UpperCAmelCase							:			List[Any]     =						delta_height // 2
          __UpperCAmelCase							:			int     =						delta_width // 2

        __UpperCAmelCase							:			Any     =						delta_height - pad_top
        __UpperCAmelCase							:			int     =						delta_width - pad_left

        __UpperCAmelCase							:			Dict     =						((pad_top, pad_bottom), (pad_left, pad_right))
        return pad(__lowercase	,   __lowercase	,   data_format=__lowercase      )
      def 			UpperCAmelCase   (   self      :    str	,   *__lowercase      :    Optional[Any]	,   **__lowercase      :    int      )							->   List[Any]:
        logger.info("""pad is deprecated and will be removed in version 4.27. Please use pad_image instead."""      )
        return self.pad_image(*__lowercase	,   **__lowercase      )
      def 			UpperCAmelCase   (   self      :    List[str]	,   __lowercase      :    np.ndarray	,   __lowercase      :    Dict[str, int]	,   __lowercase      :    PILImageResampling = PILImageResampling.BICUBIC	,   __lowercase      :    Optional[Union[str, ChannelDimension]] = None	,   **__lowercase      :    Tuple	,   )							->   np.ndarray:
        __UpperCAmelCase   ,				__UpperCAmelCase							:			Any     =						get_image_size(__lowercase      )
        __UpperCAmelCase   ,				__UpperCAmelCase							:			Dict     =						size["""height"""], size["""width"""]

        # We always resize to the smallest of either the input or output size.
        __UpperCAmelCase							:			Union[str, Any]     =						min(__lowercase	,   __lowercase      )
        __UpperCAmelCase							:			int     =						min(__lowercase	,   __lowercase      )

        if height == input_height and width == input_width:
          return image

        if input_height > input_width:
          __UpperCAmelCase							:			Optional[Any]     =						int(input_width * height / input_height      )
        elif input_width > input_height:
          __UpperCAmelCase							:			Union[str, Any]     =						int(input_height * width / input_width      )

        return resize(
            __lowercase	,   size=(height, width)	,   resample=__lowercase	,   reducing_gap=2.0	,   data_format=__lowercase	,   **__lowercase      )
      def 			UpperCAmelCase   (   self      :    Tuple	,   __lowercase      :    np.ndarray	,   __lowercase      :    Dict[str, int]	,   __lowercase      :    PILImageResampling = PILImageResampling.BICUBIC	,   __lowercase      :    Optional[Union[str, ChannelDimension]] = None	,   **__lowercase      :    str	,   )							->   np.ndarray:
        __UpperCAmelCase							:			Dict     =						get_size_dict(__lowercase      )
        __UpperCAmelCase							:			Tuple     =						min(size["""height"""]	,   size["""width"""]      )
        __UpperCAmelCase							:			Optional[Any]     =						get_resize_output_image_size(__lowercase	,   size=__lowercase	,   default_to_square=__lowercase      )
        __UpperCAmelCase							:			int     =						resize(__lowercase	,   size=__lowercase	,   resample=__lowercase	,   data_format=__lowercase	,   **__lowercase      )
        return resized_image
      def 			UpperCAmelCase   (   self      :    Union[str, Any]	,   __lowercase      :    np.ndarray	,   __lowercase      :    Union[int, float]	,   __lowercase      :    Optional[Union[str, ChannelDimension]] = None	,   **__lowercase      :    str	,   )							->   Dict:
        return rescale(__lowercase	,   scale=__lowercase	,   data_format=__lowercase	,   **__lowercase      )
      def 			UpperCAmelCase   (   self      :    Any	,   __lowercase      :    np.ndarray	,   __lowercase      :    Union[float, List[float]]	,   __lowercase      :    Union[float, List[float]]	,   __lowercase      :    Optional[Union[str, ChannelDimension]] = None	,   **__lowercase      :    str	,   )							->   np.ndarray:
        return normalize(__lowercase	,   mean=__lowercase	,   std=__lowercase	,   data_format=__lowercase	,   **__lowercase      )




      def 			UpperCAmelCase   (   self      :    Union[str, Any]	,   __lowercase      :    ImageInput	,   __lowercase      :    bool = None	,   __lowercase      :    Dict[str, int] = None	,   __lowercase      :    PILImageResampling = None	,   __lowercase      :    bool = None	,   __lowercase      :    bool = None	,   __lowercase      :    bool = None	,   __lowercase      :    bool = False	,   __lowercase      :    bool = None	,   __lowercase      :    float = None	,   __lowercase      :    bool = None	,   __lowercase      :    Optional[Union[float, List[float]]] = None	,   __lowercase      :    Optional[Union[float, List[float]]] = None	,   __lowercase      :    Optional[Union[str, TensorType]] = None	,   __lowercase      :    Optional[ChannelDimension] = ChannelDimension.FIRST	,   **__lowercase      :    Tuple	,   )							->   PIL.Image.Image:
        __UpperCAmelCase							:			Dict     =						do_resize if do_resize is not None else self.do_resize
        __UpperCAmelCase							:			List[Any]     =						size if size is not None else self.size
        if isinstance(__lowercase	,   (tuple, list)      ):
          # Previous feature extractor had size in (width, height) format
          __UpperCAmelCase							:			Tuple     =						size[::-1]
        __UpperCAmelCase							:			Dict     =						get_size_dict(__lowercase      )
        __UpperCAmelCase							:			List[str]     =						resample if resample is not None else self.resample
        __UpperCAmelCase							:			List[Any]     =						do_thumbnail if do_thumbnail is not None else self.do_thumbnail
        __UpperCAmelCase							:			Optional[Any]     =						do_align_long_axis if do_align_long_axis is not None else self.do_align_long_axis
        __UpperCAmelCase							:			Any     =						do_pad if do_pad is not None else self.do_pad
        __UpperCAmelCase							:			List[str]     =						do_rescale if do_rescale is not None else self.do_rescale
        __UpperCAmelCase							:			List[Any]     =						rescale_factor if rescale_factor is not None else self.rescale_factor
        __UpperCAmelCase							:			Tuple     =						do_normalize if do_normalize is not None else self.do_normalize
        __UpperCAmelCase							:			Tuple     =						image_mean if image_mean is not None else self.image_mean
        __UpperCAmelCase							:			int     =						image_std if image_std is not None else self.image_std

        __UpperCAmelCase							:			str     =						make_list_of_images(__lowercase      )

        if not valid_images(__lowercase      ):
          raise ValueError(
              """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
              """torch.Tensor, tf.Tensor or jax.ndarray."""      )

        if do_resize and size is None:
          raise ValueError("""Size must be specified if do_resize is True."""      )

        if do_rescale and rescale_factor is None:
          raise ValueError("""Rescale factor must be specified if do_rescale is True."""      )

        if do_pad and size is None:
          raise ValueError("""Size must be specified if do_pad is True."""      )

        if do_normalize and (image_mean is None or image_std is None):
          raise ValueError("""Image mean and std must be specified if do_normalize is True."""      )

        # All transformations expect numpy arrays.
        __UpperCAmelCase							:			Optional[int]     =						[to_numpy_array(__lowercase      ) for image in images]

        if do_align_long_axis:
          __UpperCAmelCase							:			Union[str, Any]     =						[self.align_long_axis(__lowercase	,   size=__lowercase      ) for image in images]

        if do_resize:
          __UpperCAmelCase							:			Optional[Any]     =						[self.resize(image=__lowercase	,   size=__lowercase	,   resample=__lowercase      ) for image in images]

        if do_thumbnail:
          __UpperCAmelCase							:			Tuple     =						[self.thumbnail(image=__lowercase	,   size=__lowercase      ) for image in images]

        if do_pad:
          __UpperCAmelCase							:			Union[str, Any]     =						[self.pad_image(image=__lowercase	,   size=__lowercase	,   random_padding=__lowercase      ) for image in images]

        if do_rescale:
          __UpperCAmelCase							:			List[str]     =						[self.rescale(image=__lowercase	,   scale=__lowercase      ) for image in images]

        if do_normalize:
          __UpperCAmelCase							:			Optional[Any]     =						[self.normalize(image=__lowercase	,   mean=__lowercase	,   std=__lowercase      ) for image in images]

        __UpperCAmelCase							:			Optional[int]     =						[to_channel_dimension_format(__lowercase	,   __lowercase      ) for image in images]

        __UpperCAmelCase							:			Optional[Any]     =						{"""pixel_values""": images}
        return BatchFeature(data=__lowercase	,   tensor_type=__lowercase      )










import enum
import inspect
import warnings
from functools import wraps
from typing import Callable, Optional

from .logging import get_logger


a	: Any      =				set()
a	: List[Any]      =				get_logger(__name__)






def        lowerCamelCase__   (					__lowerCamelCase    :  Optional[str] = None	):

  def decorator(__lowerCamelCase    :  Callable	):
    global _emitted_deprecation_warnings

    if inspect.isclass(__lowerCamelCase	):
      __UpperCAmelCase							:			Optional[Any]     =						deprecated_class_or_function.__init__
      __UpperCAmelCase							:			int     =						deprecated_class_or_function.__name__
    else:
      __UpperCAmelCase							:			Any     =						deprecated_class_or_function
      __UpperCAmelCase							:			Any     =						deprecated_function.__name__
      # Support deprecating __init__ class method: class name instead
      __UpperCAmelCase							:			List[str]     =						name if name != """__init__""" else deprecated_function.__qualname__.split("""."""	)[-2]

    __UpperCAmelCase							:			Union[str, Any]     =						(
        f"""{name} is deprecated and will be removed in the next major version of datasets.""" + f""" {help_message}"""
        if help_message
        else """"""
    )

    @wraps(__lowerCamelCase	)
    def wrapper(*__lowerCamelCase    :  List[str]						,	**__lowerCamelCase    :  Tuple	):
      __UpperCAmelCase							:			Optional[Any]     =						hash(__lowerCamelCase	)
      if func_hash not in _emitted_deprecation_warnings:
        warnings.warn(__lowerCamelCase						,	category=__lowerCamelCase						,	stacklevel=2	)
        _emitted_deprecation_warnings.add(__lowerCamelCase	)
      return deprecated_function(*__lowerCamelCase						,	**__lowerCamelCase	)

    __UpperCAmelCase							:			List[str]     =						"""deprecated"""

    if inspect.isclass(__lowerCamelCase	):
      __UpperCAmelCase							:			int     =						wrapper
      return deprecated_class_or_function
    else:
      return wrapper

  return decorator
class 					a					(				enum.EnumMeta     ):



      """simple docstring"""


      def __getattribute__(   cls      :    Optional[int]	,   __lowercase      :    List[Any]      )							->   str:
        __UpperCAmelCase							:			List[Any]     =						super().__getattribute__(__lowercase      )
        if isinstance(__lowercase	,   enum.Enum      ) and obj._on_access:
          obj._on_access()
        return obj
      def __getitem__(   cls      :    Union[str, Any]	,   __lowercase      :    Optional[int]      )							->   Optional[int]:
        __UpperCAmelCase							:			Union[str, Any]     =						super().__getitem__(__lowercase      )
        if member._on_access:
          member._on_access()
        return member




      def __call__(   cls      :    List[str]	,   __lowercase      :    Dict	,   __lowercase      :    List[Any]=None	,   *, __lowercase      :    Dict=None	,   __lowercase      :    Any=None	,   __lowercase      :    Optional[Any]=None	,   __lowercase      :    Dict=1      )							->   List[Any]:
        __UpperCAmelCase							:			Union[str, Any]     =						super().__call__(__lowercase	,   __lowercase	,   module=__lowercase	,   qualname=__lowercase	,   type=__lowercase	,   start=__lowercase      )
        if isinstance(__lowercase	,   enum.Enum      ) and obj._on_access:
          obj._on_access()
        return obj


class 					a					(				enum.Enum							, metaclass=lowercase__     ):



      """simple docstring"""


      def __new__(   cls      :    Dict	,   __lowercase      :    Tuple      )							->   Optional[Any]:
        __UpperCAmelCase							:			List[Any]     =						object.__new__(cls      )
        __UpperCAmelCase							:			Any     =						value
        __UpperCAmelCase							:			int     =						member.deprecate
        return member
      @property
      def 			UpperCAmelCase   (   self      :    Optional[Any]      )							->   Dict:
        return ""




      def 			UpperCAmelCase   (   self      :    str      )							->   Dict:
        __UpperCAmelCase							:			Optional[int]     =						f""" {self.help_message}""" if self.help_message else """"""
        warnings.warn(
            f"""'{self.__objclass__.__name__}' is deprecated and will be removed in the next major version of datasets."""
            + help_message	,   __lowercase	,   stacklevel=3	,   )


