

"""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,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
						import PIL


A_							:			List[str]											= logging.get_logger(__name__)

def 	A       (     snake_case__    ):




			'''simple docstring'''


			if isinstance(snake_case__		,				(list, tuple)    ) and isinstance(videos[0]		,				(list, tuple)    ) and is_valid_image(videos[0][0]    ):
						return videos

			elif isinstance(snake_case__		,				(list, tuple)    ) and is_valid_image(videos[0]    ):
						return [videos]

			elif is_valid_image(snake_case__    ):
						return [[videos]]

			raise ValueError(f"""Could not make batched video from {videos}"""    )





class    lowerCamelCase						(UpperCAmelCase__			):
			lowerCamelCase__   :		str							=							['pixel_values']

			def __init__(					self				:						List[str]    ,				__UpperCAmelCase				:						bool = True    ,				__UpperCAmelCase				:						Dict[str, int] = None    ,				__UpperCAmelCase				:						PILImageResampling = PILImageResampling.BILINEAR    ,				__UpperCAmelCase				:						bool = True    ,				__UpperCAmelCase				:						Dict[str, int] = None    ,				__UpperCAmelCase				:						bool = True    ,				__UpperCAmelCase				:						Union[int, float] = 1 / 2_5_5    ,				__UpperCAmelCase				:						bool = True    ,				__UpperCAmelCase				:						Optional[Union[float, List[float]]] = None    ,				__UpperCAmelCase				:						Optional[Union[float, List[float]]] = None    ,				**__UpperCAmelCase				:						List[Any]    ,				)   ->    None:
						super().__init__(**__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      size if size is not None else {"""shortest_edge""": 2_2_4}
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      crop_size if crop_size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase    ,				param_name="""crop_size"""       )

						SCREAMING_SNAKE_CASE__								=      do_resize
						SCREAMING_SNAKE_CASE__								=      size
						SCREAMING_SNAKE_CASE__								=      do_center_crop
						SCREAMING_SNAKE_CASE__								=      crop_size
						SCREAMING_SNAKE_CASE__								=      resample
						SCREAMING_SNAKE_CASE__								=      do_rescale
						SCREAMING_SNAKE_CASE__								=      rescale_factor
						SCREAMING_SNAKE_CASE__								=      do_normalize
						SCREAMING_SNAKE_CASE__								=      image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
						SCREAMING_SNAKE_CASE__								=      image_std if image_std is not None else IMAGENET_STANDARD_STD

			def 					SCREAMING_SNAKE_CASE				(					self				:						Dict    ,				__UpperCAmelCase				:						np.ndarray    ,				__UpperCAmelCase				:						Dict[str, int]    ,				__UpperCAmelCase				:						PILImageResampling = PILImageResampling.BILINEAR    ,				__UpperCAmelCase				:						Optional[Union[str, ChannelDimension]] = None    ,				**__UpperCAmelCase				:						Union[str, Any]    ,				)   ->    np.ndarray:
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase       )
						if "shortest_edge" in size:
									SCREAMING_SNAKE_CASE__								=      get_resize_output_image_size(__UpperCAmelCase    ,				size["""shortest_edge"""]    ,				default_to_square=__UpperCAmelCase       )
						elif "height" in size and "width" in size:
									SCREAMING_SNAKE_CASE__								=      (size["""height"""], size["""width"""])
						else:
									raise ValueError(F"""Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}"""       )
						return resize(__UpperCAmelCase    ,				size=__UpperCAmelCase    ,				resample=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase       )

			def 					SCREAMING_SNAKE_CASE				(					self				:						str    ,				__UpperCAmelCase				:						np.ndarray    ,				__UpperCAmelCase				:						Dict[str, int]    ,				__UpperCAmelCase				:						Optional[Union[str, ChannelDimension]] = None    ,				**__UpperCAmelCase				:						Optional[int]    ,				)   ->    np.ndarray:
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase       )
						if "height" not in size or "width" not in size:
									raise ValueError(F"""Size must have \'height\' and \'width\' as keys. Got {size.keys()}"""       )
						return center_crop(__UpperCAmelCase    ,				size=(size["""height"""], size["""width"""])    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase       )

			def 					SCREAMING_SNAKE_CASE				(					self				:						str    ,				__UpperCAmelCase				:						np.ndarray    ,				__UpperCAmelCase				:						Union[int, float]    ,				__UpperCAmelCase				:						Optional[Union[str, ChannelDimension]] = None    ,				**__UpperCAmelCase				:						int    ,				)   ->    List[str]:
						return rescale(__UpperCAmelCase    ,				scale=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase       )

			def 					SCREAMING_SNAKE_CASE				(					self				:						Any    ,				__UpperCAmelCase				:						np.ndarray    ,				__UpperCAmelCase				:						Union[float, List[float]]    ,				__UpperCAmelCase				:						Union[float, List[float]]    ,				__UpperCAmelCase				:						Optional[Union[str, ChannelDimension]] = None    ,				**__UpperCAmelCase				:						int    ,				)   ->    np.ndarray:
						return normalize(__UpperCAmelCase    ,				mean=__UpperCAmelCase    ,				std=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase       )

			def 					SCREAMING_SNAKE_CASE				(					self				:						Optional[Any]    ,				__UpperCAmelCase				:						ImageInput    ,				__UpperCAmelCase				:						bool = None    ,				__UpperCAmelCase				:						Dict[str, int] = None    ,				__UpperCAmelCase				:						PILImageResampling = None    ,				__UpperCAmelCase				:						bool = None    ,				__UpperCAmelCase				:						Dict[str, int] = 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[ChannelDimension] = ChannelDimension.FIRST    ,				)   ->    np.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_center_crop and crop_size is None:
									raise ValueError("""Crop size must be specified if do_center_crop is True."""       )

						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.
						SCREAMING_SNAKE_CASE__								=      to_numpy_array(__UpperCAmelCase       )

						if do_resize:
									SCREAMING_SNAKE_CASE__								=      self.resize(image=__UpperCAmelCase    ,				size=__UpperCAmelCase    ,				resample=__UpperCAmelCase       )

						if do_center_crop:
									SCREAMING_SNAKE_CASE__								=      self.center_crop(__UpperCAmelCase    ,				size=__UpperCAmelCase       )

						if do_rescale:
									SCREAMING_SNAKE_CASE__								=      self.rescale(image=__UpperCAmelCase    ,				scale=__UpperCAmelCase       )

						if do_normalize:
									SCREAMING_SNAKE_CASE__								=      self.normalize(image=__UpperCAmelCase    ,				mean=__UpperCAmelCase    ,				std=__UpperCAmelCase       )

						SCREAMING_SNAKE_CASE__								=      to_channel_dimension_format(__UpperCAmelCase    ,				__UpperCAmelCase       )
						return image





			def 					SCREAMING_SNAKE_CASE				(					self				:						List[str]    ,				__UpperCAmelCase				:						ImageInput    ,				__UpperCAmelCase				:						bool = None    ,				__UpperCAmelCase				:						Dict[str, int] = None    ,				__UpperCAmelCase				:						PILImageResampling = None    ,				__UpperCAmelCase				:						bool = None    ,				__UpperCAmelCase				:						Dict[str, int] = 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[str]    ,				)   ->    PIL.Image.Image:
						SCREAMING_SNAKE_CASE__								=      do_resize if do_resize is not None else self.do_resize
						SCREAMING_SNAKE_CASE__								=      resample if resample is not None else self.resample
						SCREAMING_SNAKE_CASE__								=      do_center_crop if do_center_crop is not None else self.do_center_crop
						SCREAMING_SNAKE_CASE__								=      do_rescale if do_rescale is not None else self.do_rescale
						SCREAMING_SNAKE_CASE__								=      rescale_factor if rescale_factor is not None else self.rescale_factor
						SCREAMING_SNAKE_CASE__								=      do_normalize if do_normalize is not None else self.do_normalize
						SCREAMING_SNAKE_CASE__								=      image_mean if image_mean is not None else self.image_mean
						SCREAMING_SNAKE_CASE__								=      image_std if image_std is not None else self.image_std

						SCREAMING_SNAKE_CASE__								=      size if size is not None else self.size
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      crop_size if crop_size is not None else self.crop_size
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase    ,				param_name="""crop_size"""       )

						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."""       )

						SCREAMING_SNAKE_CASE__								=      make_batched(__UpperCAmelCase       )

						SCREAMING_SNAKE_CASE__								=      [
						    [
						        self._preprocess_image(
						            image=__UpperCAmelCase    ,				do_resize=__UpperCAmelCase    ,				size=__UpperCAmelCase    ,				resample=__UpperCAmelCase    ,				do_center_crop=__UpperCAmelCase    ,				crop_size=__UpperCAmelCase    ,				do_rescale=__UpperCAmelCase    ,				rescale_factor=__UpperCAmelCase    ,				do_normalize=__UpperCAmelCase    ,				image_mean=__UpperCAmelCase    ,				image_std=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				)
						        for img in video
						    ]
						    for video in videos
						]

						SCREAMING_SNAKE_CASE__								=      {"""pixel_values""": videos}
						return BatchFeature(data=__UpperCAmelCase    ,				tensor_type=__UpperCAmelCase       )








"""simple docstring"""




# 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


A_							:			Dict											= {
    "configuration_efficientnet": [
        "EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "EfficientNetConfig",
        "EfficientNetOnnxConfig",
    ]
}

try:
						if not is_vision_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A_							:			List[Any]											= ["EfficientNetImageProcessor"]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A_							:			Dict											= [
						    "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

						A_							:			List[Any]											= _LazyModule(__name__, globals()["__file__"], _import_structure)


