






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


UpperCAmelCase__            =	logging.get_logger(__name__)






class 	lowercase_      (			lowercase     ):






      '''simple docstring'''




      __snake_case  						=						['''pixel_values''']







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




       """simple docstring"""


       super().__init__(**__UpperCAmelCase						)
       a							=   crop_size if crop_size is not None else {'''height''': 256, '''width''': 256}
       a							=   get_size_dict(__UpperCAmelCase				,      param_name='''crop_size'''						)
       a							=   size if size is not None else {'''height''': 224, '''width''': 224}
       a							=   get_size_dict(__UpperCAmelCase						)

       a							=   do_center_crop
       a							=   crop_size
       a							=   do_resize
       a							=   size
       a							=   resample
       a							=   do_rescale
       a							=   rescale_factor
       a							=   do_normalize
       a							=   image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
       a							=   image_std if image_std is not None else IMAGENET_DEFAULT_STD







      def    __lowerCAmelCase      (   self   :		Optional[Any]				,      __UpperCAmelCase   :		np.ndarray				,      __UpperCAmelCase   :		Dict[str, int]				,      __UpperCAmelCase   :		Optional[int] = None				,      __UpperCAmelCase   :		Optional[Union[str, ChannelDimension]] = None				,      **__UpperCAmelCase   :		Optional[int]				,      )					->np.ndarray:




       """simple docstring"""


       a							=   self.size if size is None else size
       a							=   get_size_dict(__UpperCAmelCase						)
       a							=   get_size_dict(__UpperCAmelCase				,      param_name='''crop_size'''						)

       a						,  a							=   get_image_size(__UpperCAmelCase						)
       a							=   min(__UpperCAmelCase				,      __UpperCAmelCase						)
       a							=   (size['''height'''] / crop_size['''height''']) * min_dim
       a							=   (size['''width'''] / crop_size['''width''']) * min_dim
       return center_crop(__UpperCAmelCase				,      size=(cropped_height, cropped_width)				,      data_format=__UpperCAmelCase				,      **__UpperCAmelCase						)







      def    __lowerCAmelCase      (   self   :		Dict				,      __UpperCAmelCase   :		np.ndarray				,      __UpperCAmelCase   :		Dict[str, int]				,      __UpperCAmelCase   :		PILImageResampling = PIL.Image.BICUBIC				,      __UpperCAmelCase   :		Optional[Union[str, ChannelDimension]] = None				,      **__UpperCAmelCase   :		List[Any]				,      )					->np.ndarray:




       """simple docstring"""


       a							=   get_size_dict(__UpperCAmelCase						)
       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(
           __UpperCAmelCase				,      size=(size['''height'''], size['''width'''])				,      resample=__UpperCAmelCase				,      data_format=__UpperCAmelCase				,      **__UpperCAmelCase						)







      def    __lowerCAmelCase      (   self   :		Optional[int]				,      __UpperCAmelCase   :		np.ndarray				,      __UpperCAmelCase   :		Union[int, float]				,      __UpperCAmelCase   :		Optional[Union[str, ChannelDimension]] = None				,      **__UpperCAmelCase   :		int				,      )					->Optional[Any]:




       """simple docstring"""


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







      def    __lowerCAmelCase      (   self   :		List[str]				,      __UpperCAmelCase   :		np.ndarray				,      __UpperCAmelCase   :		Union[float, List[float]]				,      __UpperCAmelCase   :		Union[float, List[float]]				,      __UpperCAmelCase   :		Optional[Union[str, ChannelDimension]] = None				,      **__UpperCAmelCase   :		Tuple				,      )					->np.ndarray:




       """simple docstring"""


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







      def    __lowerCAmelCase      (   self   :		str				,      __UpperCAmelCase   :		ImageInput				,      __UpperCAmelCase   :		Optional[bool] = None				,      __UpperCAmelCase   :		Optional[Dict[str, int]] = None				,      __UpperCAmelCase   :		Optional[bool] = None				,      __UpperCAmelCase   :		Optional[Dict[str, int]] = None				,      __UpperCAmelCase   :		PILImageResampling = None				,      __UpperCAmelCase   :		Optional[bool] = None				,      __UpperCAmelCase   :		Optional[float] = None				,      __UpperCAmelCase   :		Optional[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[Any]				,      )					->PIL.Image.Image:




       """simple docstring"""


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

       a							=   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_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.
       a							=   [to_numpy_array(__UpperCAmelCase						) for image in images]

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

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

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

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

       a							=   [to_channel_dimension_format(__UpperCAmelCase				,      __UpperCAmelCase						) for image in images]

       a							=   {'''pixel_values''': images}
       return BatchFeature(data=__UpperCAmelCase				,      tensor_type=__UpperCAmelCase						)










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase__            =	{"configuration_visual_bert": ["VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "VisualBertConfig"]}

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

     UpperCAmelCase__            =	_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


