






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


_a      	=  logging.get_logger(__name__)


if is_vision_available():
		import PIL





class __lowerCamelCase (      snake_case__):





	"""simple docstring"""






	UpperCamelCase__								=      ["pixel_values"]

	def __init__(							self       ,    UpperCAmelCase = True       ,    UpperCAmelCase = None       ,    UpperCAmelCase = PILImageResampling.BICUBIC       ,    UpperCAmelCase = True       ,    UpperCAmelCase = None       ,    UpperCAmelCase = True       ,    UpperCAmelCase = 1 / 255       ,    UpperCAmelCase = True       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = True       ,    **UpperCAmelCase       ,    ):
							"""simple docstring"""







							super().__init__(**UpperCAmelCase    )
							_UpperCAmelCase									=			size if size is not None else {'shortest_edge': 224}
							_UpperCAmelCase									=			get_size_dict(UpperCAmelCase       ,    default_to_square=UpperCAmelCase    )
							_UpperCAmelCase									=			crop_size if crop_size is not None else {'height': 224, 'width': 224}
							_UpperCAmelCase									=			get_size_dict(UpperCAmelCase       ,    default_to_square=UpperCAmelCase       ,    param_name='crop_size'    )

							_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 if image_mean is not None else OPENAI_CLIP_MEAN
							_UpperCAmelCase									=			image_std if image_std is not None else OPENAI_CLIP_STD
							_UpperCAmelCase									=			do_convert_rgb

	def        UpperCamelCase    (							self       ,    UpperCAmelCase       ,    UpperCAmelCase       ,    UpperCAmelCase = PILImageResampling.BICUBIC       ,    UpperCAmelCase = None       ,    **UpperCAmelCase       ,    ):
							"""simple docstring"""







							_UpperCAmelCase									=			get_size_dict(UpperCAmelCase       ,    default_to_square=UpperCAmelCase    )
							if "shortest_edge" not in size:
													raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""    )
							_UpperCAmelCase									=			get_resize_output_image_size(UpperCAmelCase       ,    size=size['shortest_edge']       ,    default_to_square=UpperCAmelCase    )
							return resize(UpperCAmelCase       ,    size=UpperCAmelCase       ,    resample=UpperCAmelCase       ,    data_format=UpperCAmelCase       ,    **UpperCAmelCase    )

	def        UpperCamelCase    (							self       ,    UpperCAmelCase       ,    UpperCAmelCase       ,    UpperCAmelCase = None       ,    **UpperCAmelCase       ,    ):
							"""simple docstring"""







							_UpperCAmelCase									=			get_size_dict(UpperCAmelCase    )
							if "height" not in size or "width" not in size:
													raise ValueError(F"""The `size` parameter must contain the keys (height, width). Got {size.keys()}"""    )
							return center_crop(UpperCAmelCase       ,    size=(size['height'], size['width'])       ,    data_format=UpperCAmelCase       ,    **UpperCAmelCase    )

	def        UpperCamelCase    (							self       ,    UpperCAmelCase       ,    UpperCAmelCase       ,    UpperCAmelCase = None       ,    **UpperCAmelCase       ,    ):
							"""simple docstring"""







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

	def        UpperCamelCase    (							self       ,    UpperCAmelCase       ,    UpperCAmelCase       ,    UpperCAmelCase       ,    UpperCAmelCase = None       ,    **UpperCAmelCase       ,    ):
							"""simple docstring"""







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

	def        UpperCamelCase    (							self       ,    UpperCAmelCase       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = None       ,    UpperCAmelCase = ChannelDimension.FIRST       ,    **UpperCAmelCase       ,    ):
							"""simple docstring"""







							_UpperCAmelCase									=			do_resize if do_resize is not None else self.do_resize
							_UpperCAmelCase									=			size if size is not None else self.size
							_UpperCAmelCase									=			get_size_dict(UpperCAmelCase       ,    param_name='size'       ,    default_to_square=UpperCAmelCase    )
							_UpperCAmelCase									=			resample if resample is not None else self.resample
							_UpperCAmelCase									=			do_center_crop if do_center_crop is not None else self.do_center_crop
							_UpperCAmelCase									=			crop_size if crop_size is not None else self.crop_size
							_UpperCAmelCase									=			get_size_dict(UpperCAmelCase       ,    param_name='crop_size'       ,    default_to_square=UpperCAmelCase    )
							_UpperCAmelCase									=			do_rescale if do_rescale is not None else self.do_rescale
							_UpperCAmelCase									=			rescale_factor if rescale_factor is not None else self.rescale_factor
							_UpperCAmelCase									=			do_normalize if do_normalize is not None else self.do_normalize
							_UpperCAmelCase									=			image_mean if image_mean is not None else self.image_mean
							_UpperCAmelCase									=			image_std if image_std is not None else self.image_std
							_UpperCAmelCase									=			do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

							_UpperCAmelCase									=			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:
													raise ValueError('Size 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.'    )

							# PIL RGBA images are converted to RGB
							if do_convert_rgb:
													_UpperCAmelCase									=			[convert_to_rgb(UpperCAmelCase    ) for image in images]

							# All transformations expect numpy arrays.
							_UpperCAmelCase									=			[to_numpy_array(UpperCAmelCase    ) for image in images]

							if do_resize:
													_UpperCAmelCase									=			[self.resize(image=UpperCAmelCase       ,    size=UpperCAmelCase       ,    resample=UpperCAmelCase    ) for image in images]

							if do_center_crop:
													_UpperCAmelCase									=			[self.center_crop(image=UpperCAmelCase       ,    size=UpperCAmelCase    ) for image in images]

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

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

							_UpperCAmelCase									=			[to_channel_dimension_format(UpperCAmelCase       ,    UpperCAmelCase    ) for image in images]

							_UpperCAmelCase									=			{'pixel_values': images}
							return BatchFeature(data=UpperCAmelCase       ,    tensor_type=UpperCAmelCase    )








import enum
import os
from hashlib import shaaaa
from typing import Optional

from .. import config
from .logging import get_logger


_a      	=  get_logger(__name__)





class __lowerCamelCase (      enum.Enum):





	"""simple docstring"""






	UpperCamelCase__								=      "all_checks"
	UpperCamelCase__								=      "basic_checks"
	UpperCamelCase__								=      "no_checks"





class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""









def __A    (      __lowerCAmelCase ,		__lowerCAmelCase ,		__lowerCAmelCase=None	)->  str:





						"""simple docstring"""



						if expected_checksums is None:
												logger.info('Unable to verify checksums.'	)
												return
						if len(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	) > 0:
												raise ExpectedMoreDownloadedFiles(str(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	)	)
						if len(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	) > 0:
												raise UnexpectedDownloadedFile(str(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	)	)
						_UpperCAmelCase									=			[url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
						_UpperCAmelCase									=			' for ' + verification_name if verification_name is not None else ''
						if len(__lowerCAmelCase	) > 0:
												raise NonMatchingChecksumError(
												    F"""Checksums didn't match{for_verification_name}:\n"""
												    F"""{bad_urls}\n"""
												    'Set `verification_mode=\'no_checks\'` to skip checksums verification and ignore this error'	)
						logger.info('All the checksums matched successfully' + for_verification_name	)





class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""











class __lowerCamelCase (      snake_case__):





	"""simple docstring"""









def __A    (      __lowerCAmelCase ,		__lowerCAmelCase	)->  int:





						"""simple docstring"""



						if expected_splits is None:
												logger.info('Unable to verify splits sizes.'	)
												return
						if len(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	) > 0:
												raise ExpectedMoreSplits(str(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	)	)
						if len(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	) > 0:
												raise UnexpectedSplits(str(set(__lowerCAmelCase	) - set(__lowerCAmelCase	)	)	)
						_UpperCAmelCase									=			[
						    {'expected': expected_splits[name], 'recorded': recorded_splits[name]}
						    for name in expected_splits
						    if expected_splits[name].num_examples != recorded_splits[name].num_examples
						]
						if len(__lowerCAmelCase	) > 0:
												raise NonMatchingSplitsSizesError(str(__lowerCAmelCase	)	)
						logger.info('All the splits matched successfully.'	)


def __A    (      __lowerCAmelCase ,		__lowerCAmelCase = True	)->  dict:





						"""simple docstring"""



						if record_checksum:
												_UpperCAmelCase									=			shaaaa()
												with open(__lowerCAmelCase ,		'rb'	) as f:
																		for chunk in iter(lambda: f.read(1 << 20	) ,		b''	):
																								m.update(__lowerCAmelCase	)
																		_UpperCAmelCase									=			m.hexdigest()
						else:
												_UpperCAmelCase									=			None
						return {"num_bytes": os.path.getsize(__lowerCAmelCase	), "checksum": checksum}


def __A    (      __lowerCAmelCase	)->  List[str]:





						"""simple docstring"""



						if dataset_size and config.IN_MEMORY_MAX_SIZE:
												return dataset_size < config.IN_MEMORY_MAX_SIZE
						else:
												return False
