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


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


if is_vision_available():
					import PIL





class 					lowercase__						(   __lowerCamelCase):
						UpperCamelCase_     =		["pixel_values"]


						def __init__(       self	:				List[Any]    ,		UpperCamelCase__	:				bool = True    ,		UpperCamelCase__	:				Dict[str, int] = None    ,		UpperCamelCase__	:				PILImageResampling = PILImageResampling.BICUBIC    ,		UpperCamelCase__	:				bool = True    ,		UpperCamelCase__	:				Dict[str, int] = None    ,		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__	:				bool = True    ,		**UpperCamelCase__	:				str    ,		):





												'''simple docstring'''





												super().__init__(**__A						)
												SCREAMING_SNAKE_CASE							:    List[Any]							=							size if size is not None else {'''shortest_edge''': 224}
												SCREAMING_SNAKE_CASE							:    Optional[int]							=							get_size_dict(__A    ,		default_to_square=__A						)
												SCREAMING_SNAKE_CASE							:    Dict							=							crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
												SCREAMING_SNAKE_CASE							:    int							=							get_size_dict(__A    ,		default_to_square=__A    ,		param_name='''crop_size'''						)

												SCREAMING_SNAKE_CASE							:    List[str]							=							do_resize
												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							size
												SCREAMING_SNAKE_CASE							:    int							=							resample
												SCREAMING_SNAKE_CASE							:    Tuple							=							do_center_crop
												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							crop_size
												SCREAMING_SNAKE_CASE							:    Any							=							do_rescale
												SCREAMING_SNAKE_CASE							:    int							=							rescale_factor
												SCREAMING_SNAKE_CASE							:    List[str]							=							do_normalize
												SCREAMING_SNAKE_CASE							:    Dict							=							image_mean if image_mean is not None else OPENAI_CLIP_MEAN
												SCREAMING_SNAKE_CASE							:    Tuple							=							image_std if image_std is not None else OPENAI_CLIP_STD
												SCREAMING_SNAKE_CASE							:    Tuple							=							do_convert_rgb


						def        __A       (       self	:				Optional[Any]    ,		UpperCamelCase__	:				np.ndarray    ,		UpperCamelCase__	:				Dict[str, int]    ,		UpperCamelCase__	:				PILImageResampling = PILImageResampling.BICUBIC    ,		UpperCamelCase__	:				Optional[Union[str, ChannelDimension]] = None    ,		**UpperCamelCase__	:				List[str]    ,		):





												'''simple docstring'''





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


						def        __A       (       self	:				str    ,		UpperCamelCase__	:				np.ndarray    ,		UpperCamelCase__	:				Dict[str, int]    ,		UpperCamelCase__	:				Optional[Union[str, ChannelDimension]] = None    ,		**UpperCamelCase__	:				Optional[int]    ,		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    str							=							get_size_dict(__A						)
												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(__A    ,		size=(size['''height'''], size['''width'''])    ,		data_format=__A    ,		**__A						)


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





												'''simple docstring'''





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


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





												'''simple docstring'''





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



						def        __A       (       self	:				Union[str, Any]    ,		UpperCamelCase__	:				ImageInput    ,		UpperCamelCase__	:				bool = None    ,		UpperCamelCase__	:				Dict[str, int] = None    ,		UpperCamelCase__	:				PILImageResampling = None    ,		UpperCamelCase__	:				bool = None    ,		UpperCamelCase__	:				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__	:				bool = None    ,		UpperCamelCase__	:				Optional[Union[str, TensorType]] = None    ,		UpperCamelCase__	:				Optional[ChannelDimension] = ChannelDimension.FIRST    ,		**UpperCamelCase__	:				Dict    ,		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Optional[int]							=							do_resize if do_resize is not None else self.do_resize
												SCREAMING_SNAKE_CASE							:    Dict							=							size if size is not None else self.size
												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							get_size_dict(__A    ,		param_name='''size'''    ,		default_to_square=__A						)
												SCREAMING_SNAKE_CASE							:    int							=							resample if resample is not None else self.resample
												SCREAMING_SNAKE_CASE							:    Optional[int]							=							do_center_crop if do_center_crop is not None else self.do_center_crop
												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							crop_size if crop_size is not None else self.crop_size
												SCREAMING_SNAKE_CASE							:    Optional[int]							=							get_size_dict(__A    ,		param_name='''crop_size'''    ,		default_to_square=__A						)
												SCREAMING_SNAKE_CASE							:    List[str]							=							do_rescale if do_rescale is not None else self.do_rescale
												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							rescale_factor if rescale_factor is not None else self.rescale_factor
												SCREAMING_SNAKE_CASE							:    Optional[Any]							=							do_normalize if do_normalize is not None else self.do_normalize
												SCREAMING_SNAKE_CASE							:    str							=							image_mean if image_mean is not None else self.image_mean
												SCREAMING_SNAKE_CASE							:    Optional[int]							=							image_std if image_std is not None else self.image_std
												SCREAMING_SNAKE_CASE							:    Dict							=							do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

												SCREAMING_SNAKE_CASE							:    int							=							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:
																		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:
																		SCREAMING_SNAKE_CASE							:    Any							=							[convert_to_rgb(__A						) for image in images]

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

												if do_resize:
																		SCREAMING_SNAKE_CASE							:    List[str]							=							[self.resize(image=__A    ,		size=__A    ,		resample=__A						) for image in images]

												if do_center_crop:
																		SCREAMING_SNAKE_CASE							:    str							=							[self.center_crop(image=__A    ,		size=__A						) for image in images]

												if do_rescale:
																		SCREAMING_SNAKE_CASE							:    str							=							[self.rescale(image=__A    ,		scale=__A						) for image in images]

												if do_normalize:
																		SCREAMING_SNAKE_CASE							:    Any							=							[self.normalize(image=__A    ,		mean=__A    ,		std=__A						) for image in images]

												SCREAMING_SNAKE_CASE							:    Tuple							=							[to_channel_dimension_format(__A    ,		__A						) for image in images]

												SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							{'''pixel_values''': images}
												return BatchFeature(data=__A    ,		tensor_type=__A						)












'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a__							:							List[str] ={
    '''configuration_bigbird_pegasus''': [
        '''BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''BigBirdPegasusConfig''',
        '''BigBirdPegasusOnnxConfig''',
    ],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    a__							:							Any =[
        '''BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST''',
        '''BigBirdPegasusForCausalLM''',
        '''BigBirdPegasusForConditionalGeneration''',
        '''BigBirdPegasusForQuestionAnswering''',
        '''BigBirdPegasusForSequenceClassification''',
        '''BigBirdPegasusModel''',
        '''BigBirdPegasusPreTrainedModel''',
    ]


if TYPE_CHECKING:
    from .configuration_bigbird_pegasus import (
        BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP,
        BigBirdPegasusConfig,
        BigBirdPegasusOnnxConfig,
    )

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_bigbird_pegasus import (
            BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
            BigBirdPegasusForCausalLM,
            BigBirdPegasusForConditionalGeneration,
            BigBirdPegasusForQuestionAnswering,
            BigBirdPegasusForSequenceClassification,
            BigBirdPegasusModel,
            BigBirdPegasusPreTrainedModel,
        )


else:
    import sys

    a__							:							str =_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
