



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


if is_vision_available():
	import PIL


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







class 							A_							(      _lowerCAmelCase				):
			A					=  ['''pixel_values''']

			def __init__(self,      SCREAMING_SNAKE_CASE_ = True,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = True,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = PILImageResampling.BICUBIC,      SCREAMING_SNAKE_CASE_ = True,      SCREAMING_SNAKE_CASE_ = 1 / 255,      SCREAMING_SNAKE_CASE_ = True,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      **SCREAMING_SNAKE_CASE_,      )					->      None:
						super().__init__(**SCREAMING_SNAKE_CASE_				)
						UpperCAmelCase_:		Optional[Any]       			=    crop_size if crop_size is not None else {"""height""": 256, """width""": 256}
						UpperCAmelCase_:		int       			=    get_size_dict(SCREAMING_SNAKE_CASE_,      param_name="""crop_size"""				)
						UpperCAmelCase_:		List[Any]       			=    size if size is not None else {"""height""": 224, """width""": 224}
						UpperCAmelCase_:		Optional[Any]       			=    get_size_dict(SCREAMING_SNAKE_CASE_				)

						UpperCAmelCase_:		Dict       			=    do_center_crop
						UpperCAmelCase_:		str       			=    crop_size
						UpperCAmelCase_:		Optional[int]       			=    do_resize
						UpperCAmelCase_:		List[str]       			=    size
						UpperCAmelCase_:		Tuple       			=    resample
						UpperCAmelCase_:		Tuple       			=    do_rescale
						UpperCAmelCase_:		List[Any]       			=    rescale_factor
						UpperCAmelCase_:		Tuple       			=    do_normalize
						UpperCAmelCase_:		List[Any]       			=    image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
						UpperCAmelCase_:		Optional[int]       			=    image_std if image_std is not None else IMAGENET_DEFAULT_STD

			def     __snake_case					(self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      **SCREAMING_SNAKE_CASE_,      )					->      np.ndarray:
						UpperCAmelCase_:		Optional[int]       			=    self.size if size is None else size
						UpperCAmelCase_:		Dict       			=    get_size_dict(SCREAMING_SNAKE_CASE_				)
						UpperCAmelCase_:		Dict       			=    get_size_dict(SCREAMING_SNAKE_CASE_,      param_name="""crop_size"""				)

						UpperCAmelCase_:		Dict       			=    get_image_size(SCREAMING_SNAKE_CASE_				)
						UpperCAmelCase_:		Union[str, Any]       			=    min(SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_				)
						UpperCAmelCase_:		int       			=    (size["""height"""] / crop_size["""height"""]) * min_dim
						UpperCAmelCase_:		Dict       			=    (size["""width"""] / crop_size["""width"""]) * min_dim
						return center_crop(SCREAMING_SNAKE_CASE_,      size=(cropped_height, cropped_width),      data_format=SCREAMING_SNAKE_CASE_,      **SCREAMING_SNAKE_CASE_				)

			def     __snake_case					(self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_ = PIL.Image.BICUBIC,      SCREAMING_SNAKE_CASE_ = None,      **SCREAMING_SNAKE_CASE_,      )					->      np.ndarray:
						UpperCAmelCase_:		str       			=    get_size_dict(SCREAMING_SNAKE_CASE_				)
						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()}'				)
						return resize(
						    SCREAMING_SNAKE_CASE_,      size=(size["""height"""], size["""width"""]),      resample=SCREAMING_SNAKE_CASE_,      data_format=SCREAMING_SNAKE_CASE_,      **SCREAMING_SNAKE_CASE_				)

			def     __snake_case					(self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_ = None,      **SCREAMING_SNAKE_CASE_,      )					->      List[Any]:
						return rescale(SCREAMING_SNAKE_CASE_,      scale=SCREAMING_SNAKE_CASE_,      data_format=SCREAMING_SNAKE_CASE_,      **SCREAMING_SNAKE_CASE_				)

			def     __snake_case					(self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_ = None,      **SCREAMING_SNAKE_CASE_,      )					->      np.ndarray:
						return normalize(SCREAMING_SNAKE_CASE_,      mean=SCREAMING_SNAKE_CASE_,      std=SCREAMING_SNAKE_CASE_,      data_format=SCREAMING_SNAKE_CASE_,      **SCREAMING_SNAKE_CASE_				)

			def     __snake_case					(self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = None,      SCREAMING_SNAKE_CASE_ = ChannelDimension.FIRST,      **SCREAMING_SNAKE_CASE_,      )					->      PIL.Image.Image:
						UpperCAmelCase_:		List[str]       			=    do_center_crop if do_center_crop is not None else self.do_center_crop
						UpperCAmelCase_:		Optional[int]       			=    crop_size if crop_size is not None else self.crop_size
						UpperCAmelCase_:		str       			=    get_size_dict(SCREAMING_SNAKE_CASE_,      param_name="""crop_size"""				)
						UpperCAmelCase_:		Dict       			=    do_resize if do_resize is not None else self.do_resize
						UpperCAmelCase_:		Tuple       			=    size if size is not None else self.size
						UpperCAmelCase_:		Optional[Any]       			=    get_size_dict(SCREAMING_SNAKE_CASE_				)
						UpperCAmelCase_:		Any       			=    resample if resample is not None else self.resample
						UpperCAmelCase_:		List[str]       			=    do_rescale if do_rescale is not None else self.do_rescale
						UpperCAmelCase_:		List[Any]       			=    rescale_factor if rescale_factor is not None else self.rescale_factor
						UpperCAmelCase_:		Optional[int]       			=    do_normalize if do_normalize is not None else self.do_normalize
						UpperCAmelCase_:		Tuple       			=    image_mean if image_mean is not None else self.image_mean
						UpperCAmelCase_:		Optional[int]       			=    image_std if image_std is not None else self.image_std

						UpperCAmelCase_:		Tuple       			=    make_list_of_images(SCREAMING_SNAKE_CASE_				)

						if not valid_images(SCREAMING_SNAKE_CASE_				):
									raise ValueError(
									    """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
									    """torch.Tensor, tf.Tensor or jax.ndarray."""				)

						if do_center_crop and crop_size is None:
									raise ValueError("""If `do_center_crop` is set to `True`, `crop_size` must be provided."""				)

						if do_resize and size is None:
									raise ValueError("""Size 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 image standard deviation must be specified if do_normalize is True."""				)

						# All transformations expect numpy arrays.
						UpperCAmelCase_:		Dict       			=    [to_numpy_array(SCREAMING_SNAKE_CASE_				) for image in images]

						if do_center_crop:
									UpperCAmelCase_:		Any       			=    [self.center_crop(SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      size=SCREAMING_SNAKE_CASE_				) for image in images]

						if do_resize:
									UpperCAmelCase_:		Union[str, Any]       			=    [self.resize(image=SCREAMING_SNAKE_CASE_,      size=SCREAMING_SNAKE_CASE_,      resample=SCREAMING_SNAKE_CASE_				) for image in images]

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

						if do_normalize:
									UpperCAmelCase_:		Tuple       			=    [self.normalize(image=SCREAMING_SNAKE_CASE_,      mean=SCREAMING_SNAKE_CASE_,      std=SCREAMING_SNAKE_CASE_				) for image in images]

						UpperCAmelCase_:		Union[str, Any]       			=    [to_channel_dimension_format(SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_				) for image in images]

						UpperCAmelCase_:		int       			=    {"""pixel_values""": images}
						return BatchFeature(data=SCREAMING_SNAKE_CASE_,      tensor_type=SCREAMING_SNAKE_CASE_				)











from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a			:     List[str]     = {'configuration_visual_bert': ['VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'VisualBertConfig']}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	a			:     List[str]     = [
	    'VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'VisualBertForMultipleChoice',
	    'VisualBertForPreTraining',
	    'VisualBertForQuestionAnswering',
	    'VisualBertForRegionToPhraseAlignment',
	    'VisualBertForVisualReasoning',
	    'VisualBertLayer',
	    'VisualBertModel',
	    'VisualBertPreTrainedModel',
	]


if TYPE_CHECKING:
	from .configuration_visual_bert import VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, VisualBertConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_visual_bert import (
		    VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    VisualBertForMultipleChoice,
		    VisualBertForPreTraining,
		    VisualBertForQuestionAnswering,
		    VisualBertForRegionToPhraseAlignment,
		    VisualBertForVisualReasoning,
		    VisualBertLayer,
		    VisualBertModel,
		    VisualBertPreTrainedModel,
		)


else:
	import sys

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






