






'''simple docstring'''




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 (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
    import PIL


lowerCamelCase_												=					logging.get_logger(__name__)

class    _UpperCAmelCase			(     snake_case_						):




   """simple docstring"""

   snake_case    				=						['''pixel_values''']

   def __init__(		self :	Dict      ,      __UpperCAmelCase :	bool = True      ,      __UpperCAmelCase :	Dict[str, int] = None      ,      __UpperCAmelCase :	float = None      ,      __UpperCAmelCase :	PILImageResampling = PILImageResampling.BILINEAR      ,      __UpperCAmelCase :	bool = True      ,      __UpperCAmelCase :	Union[int, float] = 1 / 255      ,      __UpperCAmelCase :	bool = True      ,      __UpperCAmelCase :	Optional[Union[float, List[float]]] = None      ,      __UpperCAmelCase :	Optional[Union[float, List[float]]] = None      ,      **__UpperCAmelCase :	Any      ,      ):





         '''simple docstring'''





         super().__init__(**__UpperCAmelCase		)
         _A			     =	size if size is not None else {"shortest_edge": 384}
         _A			     =	get_size_dict(__UpperCAmelCase      ,      default_to_square=__UpperCAmelCase		)

         _A			     =	do_resize
         _A			     =	size
         # Default value set here for backwards compatibility where the value in config is None
         _A			     =	crop_pct if crop_pct is not None else 224 / 256
         _A			     =	resample
         _A			     =	do_rescale
         _A			     =	rescale_factor
         _A			     =	do_normalize
         _A			     =	image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
         _A			     =	image_std if image_std is not None else IMAGENET_STANDARD_STD

   def 						lowerCAmelCase (		self :	Optional[int]      ,      __UpperCAmelCase :	np.ndarray      ,      __UpperCAmelCase :	Dict[str, int]      ,      __UpperCAmelCase :	float      ,      __UpperCAmelCase :	PILImageResampling = PILImageResampling.BICUBIC      ,      __UpperCAmelCase :	Optional[Union[str, ChannelDimension]] = None      ,      **__UpperCAmelCase :	Optional[Any]      ,      ):





         '''simple docstring'''





         _A			     =	get_size_dict(__UpperCAmelCase      ,      default_to_square=__UpperCAmelCase		)
         if "shortest_edge" not in size:
               raise ValueError(f'''Size dictionary must contain \'shortest_edge\' key. Got {size.keys()}'''		)
         _A			     =	size["shortest_edge"]

         if shortest_edge < 384:
               # maintain same ratio, resizing shortest edge to shortest_edge/crop_pct
               _A			     =	int(shortest_edge / crop_pct		)
               _A			     =	get_resize_output_image_size(__UpperCAmelCase      ,      size=__UpperCAmelCase      ,      default_to_square=__UpperCAmelCase		)
               _A			     =	resize(image=__UpperCAmelCase      ,      size=__UpperCAmelCase      ,      resample=__UpperCAmelCase      ,      data_format=__UpperCAmelCase      ,      **__UpperCAmelCase		)
               # then crop to (shortest_edge, shortest_edge)
               return center_crop(image=__UpperCAmelCase      ,      size=(shortest_edge, shortest_edge)      ,      data_format=__UpperCAmelCase      ,      **__UpperCAmelCase		)
         else:
               # warping (no cropping) when evaluated at 384 or larger
               return resize(
                   __UpperCAmelCase      ,      size=(shortest_edge, shortest_edge)      ,      resample=__UpperCAmelCase      ,      data_format=__UpperCAmelCase      ,      **__UpperCAmelCase		)

   def 						lowerCAmelCase (		self :	str      ,      __UpperCAmelCase :	np.ndarray      ,      __UpperCAmelCase :	Union[int, float]      ,      __UpperCAmelCase :	Optional[Union[str, ChannelDimension]] = None      ,      **__UpperCAmelCase :	Union[str, Any]      ,      ):





         '''simple docstring'''





         return rescale(__UpperCAmelCase      ,      scale=__UpperCAmelCase      ,      data_format=__UpperCAmelCase      ,      **__UpperCAmelCase		)

   def 						lowerCAmelCase (		self :	int      ,      __UpperCAmelCase :	np.ndarray      ,      __UpperCAmelCase :	Union[float, List[float]]      ,      __UpperCAmelCase :	Union[float, List[float]]      ,      __UpperCAmelCase :	Optional[Union[str, ChannelDimension]] = None      ,      **__UpperCAmelCase :	Union[str, Any]      ,      ):





         '''simple docstring'''





         return normalize(__UpperCAmelCase      ,      mean=__UpperCAmelCase      ,      std=__UpperCAmelCase      ,      data_format=__UpperCAmelCase      ,      **__UpperCAmelCase		)

   def 						lowerCAmelCase (		self :	List[str]      ,      __UpperCAmelCase :	ImageInput      ,      __UpperCAmelCase :	bool = None      ,      __UpperCAmelCase :	Dict[str, int] = None      ,      __UpperCAmelCase :	float = None      ,      __UpperCAmelCase :	PILImageResampling = None      ,      __UpperCAmelCase :	bool = None      ,      __UpperCAmelCase :	float = None      ,      __UpperCAmelCase :	bool = None      ,      __UpperCAmelCase :	Optional[Union[float, List[float]]] = None      ,      __UpperCAmelCase :	Optional[Union[float, List[float]]] = None      ,      __UpperCAmelCase :	Optional[Union[str, TensorType]] = None      ,      __UpperCAmelCase :	ChannelDimension = ChannelDimension.FIRST      ,      **__UpperCAmelCase :	List[Any]      ,      ):





         '''simple docstring'''





         _A			     =	do_resize if do_resize is not None else self.do_resize
         _A			     =	crop_pct if crop_pct is not None else self.crop_pct
         _A			     =	resample if resample is not None else self.resample
         _A			     =	do_rescale if do_rescale is not None else self.do_rescale
         _A			     =	rescale_factor if rescale_factor is not None else self.rescale_factor
         _A			     =	do_normalize if do_normalize is not None else self.do_normalize
         _A			     =	image_mean if image_mean is not None else self.image_mean
         _A			     =	image_std if image_std is not None else self.image_std

         _A			     =	size if size is not None else self.size
         _A			     =	get_size_dict(__UpperCAmelCase      ,      default_to_square=__UpperCAmelCase		)

         _A			     =	make_list_of_images(__UpperCAmelCase		)

         if not valid_images(__UpperCAmelCase		):
               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 or resample is None:
               raise ValueError("Size and resample must be specified if do_resize is True."		)

         if do_resize and size["shortest_edge"] < 384 and crop_pct is None:
               raise ValueError("crop_pct must be specified if size < 384."		)

         if do_rescale and rescale_factor is None:
               raise ValueError("Rescale factor must be specified if do_rescale 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.
         _A			     =	[to_numpy_array(__UpperCAmelCase		) for image in images]

         if do_resize:
               _A			     =	[self.resize(image=__UpperCAmelCase      ,      size=__UpperCAmelCase      ,      crop_pct=__UpperCAmelCase      ,      resample=__UpperCAmelCase		) for image in images]

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

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

         _A			     =	[to_channel_dimension_format(__UpperCAmelCase      ,      __UpperCAmelCase		) for image in images]

         _A			     =	{"pixel_values": images}
         return BatchFeature(data=__UpperCAmelCase      ,      tensor_type=__UpperCAmelCase		)









# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


UpperCAmelCase__   	=							{
    '''configuration_efficientnet''': [
        '''EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''EfficientNetConfig''',
        '''EfficientNetOnnxConfig''',
    ]
}

try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__   	=							['''EfficientNetImageProcessor''']

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__   	=							[
      '''EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''EfficientNetForImageClassification''',
      '''EfficientNetModel''',
      '''EfficientNetPreTrainedModel''',
  ]

if TYPE_CHECKING:
  from .configuration_efficientnet import (
      EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP,
      EfficientNetConfig,
      EfficientNetOnnxConfig,
  )

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .image_processing_efficientnet import EfficientNetImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_efficientnet import (
        EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST,
        EfficientNetForImageClassification,
        EfficientNetModel,
        EfficientNetPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase__   	=							_LazyModule(__name__, globals()['''__file__'''], _import_structure)

