


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 convert_to_rgb, 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


if is_vision_available():
    import PIL


__snake_case   							=						logging.get_logger(__name__)



class 	__lowerCamelCase			(_a						):
       _lowercase											=     ["""pixel_values"""]







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






            '''simple docstring'''




            super().__init__(**A_					)
            __UpperCamelCase =			size if size is not None else {'height': 384, 'width': 384}
            __UpperCamelCase =			get_size_dict(A_,default_to_square=A_					)

            __UpperCamelCase =			do_resize
            __UpperCamelCase =			size
            __UpperCamelCase =			resample
            __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 		snake_case_	(			self: Union[str, Any],A_: np.ndarray,A_: Dict[str, int],A_: PILImageResampling = PILImageResampling.BICUBIC,A_: Optional[Union[str, ChannelDimension]] = None,**A_: Union[str, Any],):






            '''simple docstring'''




            __UpperCamelCase =			get_size_dict(A_,default_to_square=A_					)
            if "height" not in size or "width" not in size:
                 raise ValueError(F'''The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'''					)
            __UpperCamelCase =			(size['height'], size['width'])
            return resize(A_,size=A_,resample=A_,data_format=A_,**A_					)







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






            '''simple docstring'''




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







       def 		snake_case_	(			self: Tuple,A_: np.ndarray,A_: Union[float, List[float]],A_: Union[float, List[float]],A_: Optional[Union[str, ChannelDimension]] = None,**A_: Dict,):






            '''simple docstring'''




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







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






            '''simple docstring'''




            __UpperCamelCase =			do_resize if do_resize is not None else self.do_resize
            __UpperCamelCase =			resample if resample is not None else self.resample
            __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 =			size if size is not None else self.size
            __UpperCamelCase =			get_size_dict(A_,default_to_square=A_					)

            __UpperCamelCase =			make_list_of_images(A_					)

            if not valid_images(A_					):
                 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_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(A_					) for image in images]

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

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

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

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

            __UpperCamelCase =			[to_channel_dimension_format(A_,A_					) for image in images]

            __UpperCamelCase =			BatchFeature(data={'pixel_values': images},tensor_type=A_					)

            return encoded_outputs




"""simple docstring"""
import operator as op


SCREAMING_SNAKE_CASE_					     =	'''scaler.pt'''
SCREAMING_SNAKE_CASE_					     =	'''pytorch_model'''
SCREAMING_SNAKE_CASE_					     =	'''random_states'''
SCREAMING_SNAKE_CASE_					     =	'''optimizer'''
SCREAMING_SNAKE_CASE_					     =	'''scheduler'''
SCREAMING_SNAKE_CASE_					     =	'''pytorch_model.bin'''
SCREAMING_SNAKE_CASE_					     =	'''pytorch_model.bin.index.json'''
SCREAMING_SNAKE_CASE_					     =	'''model.safetensors'''
SCREAMING_SNAKE_CASE_					     =	'''model.safetensors.index.json'''
SCREAMING_SNAKE_CASE_					     =	'''1.10.2'''
SCREAMING_SNAKE_CASE_					     =	'''py38'''
SCREAMING_SNAKE_CASE_					     =	'''4.17.0'''
SCREAMING_SNAKE_CASE_					     =	['''ml.p3.16xlarge''', '''ml.p3dn.24xlarge''', '''ml.p4dn.24xlarge''']
SCREAMING_SNAKE_CASE_					     =	['''FULL_SHARD''', '''SHARD_GRAD_OP''', '''NO_SHARD''', '''HYBRID_SHARD''', '''HYBRID_SHARD_ZERO2''']
SCREAMING_SNAKE_CASE_					     =	['''TRANSFORMER_BASED_WRAP''', '''SIZE_BASED_WRAP''', '''NO_WRAP''']
SCREAMING_SNAKE_CASE_					     =	['''BACKWARD_PRE''', '''BACKWARD_POST''', '''NO_PREFETCH''']
SCREAMING_SNAKE_CASE_					     =	['''FULL_STATE_DICT''', '''LOCAL_STATE_DICT''', '''SHARDED_STATE_DICT''']
SCREAMING_SNAKE_CASE_					     =	'''2.0.1'''
SCREAMING_SNAKE_CASE_					     =	['''pdsh''', '''standard''', '''openmpi''', '''mvapich''']
SCREAMING_SNAKE_CASE_					     =	['''default''', '''reduce-overhead''', '''max-autotune''']

SCREAMING_SNAKE_CASE_					     =	{'''>''': op.gt, '''>=''': op.ge, '''==''': op.eq, '''!=''': op.ne, '''<=''': op.le, '''<''': op.lt}

# These are the args for `torch.distributed.launch` for pytorch < 1.9
SCREAMING_SNAKE_CASE_					     =	[
    '''nnodes''',
    '''nproc_per_node''',
    '''rdzv_backend''',
    '''rdzv_endpoint''',
    '''rdzv_id''',
    '''rdzv_conf''',
    '''standalone''',
    '''max_restarts''',
    '''monitor_interval''',
    '''start_method''',
    '''role''',
    '''module''',
    '''m''',
    '''no_python''',
    '''run_path''',
    '''log_dir''',
    '''r''',
    '''redirects''',
    '''t''',
    '''tee''',
    '''node_rank''',
    '''master_addr''',
    '''master_port''',
]

SCREAMING_SNAKE_CASE_					     =	['''DEEPSPEED''', '''MULTI_GPU''', '''FSDP''', '''MEGATRON_LM''']
SCREAMING_SNAKE_CASE_					     =	['''DEEPSPEED''', '''MULTI_XPU''', '''FSDP''']
