




'''simple docstring'''







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,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_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


lowerCAmelCase_     						=				logging.get_logger(__name__)

class 	_snake_case(			_UpperCAmelCase      ):
 __snake_case:							Optional[int]						=					['''pixel_values''']






 def __init__(self       :  int    ,		a       :  Union[str, Any] = True    ,		a       :  int = None    ,		a       :  Dict = 0.9    ,		a       :  Union[str, Any] = PILImageResampling.BICUBIC    ,		a       :  int = True    ,		a       :  Optional[int] = None    ,		a       :  List[str] = 1 / 2_55    ,		a       :  Tuple = True    ,		a       :  str = True    ,		a       :  Tuple = None    ,		a       :  Any = None    ,		**a       :  Optional[int]    ,		)       ->   None:






    """simple docstring"""


    super().__init__(**a    )
    A__       =     size if size is not None else {'shortest_edge': 2_24}
    A__       =     get_size_dict(a    ,		default_to_square=a    )
    A__       =     crop_size if crop_size is not None else {'height': 2_24, 'width': 2_24}
    A__       =     get_size_dict(a    ,		param_name='crop_size'    )

    A__       =     do_resize
    A__       =     size
    A__       =     crop_pct
    A__       =     resample
    A__       =     do_center_crop
    A__       =     crop_size
    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 						_UpperCamelCase (self       :  Optional[Any]    ,		a       :  Optional[int]    ,		a       :  int    ,		a       :  Any = None    ,		a       :  int = PILImageResampling.BICUBIC    ,		a       :  List[Any] = None    ,		**a       :  List[Any]    ,		)       ->   np.ndarray:






    """simple docstring"""


    A__       =     get_size_dict(a    ,		default_to_square=a    )
    if "shortest_edge" not in size and ("height" not in size or "width" not in size):
       raise ValueError(f"""size must contain \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}"""    )
    if crop_pct is not None:
       if "shortest_edge" in size:
          A__       =     int(size['shortest_edge'] / crop_pct    )
       elif "height" in size and "width" in size:
          if size["height"] == size["width"]:
             A__       =     int(size['height'] / crop_pct    )
          else:
             A__       =     (int(size['height'] / crop_pct    ), int(size['width'] / crop_pct    ))
       else:
          raise ValueError('Invalid size for resize: {}'.format(a    )    )

       A__       =     get_resize_output_image_size(a    ,		size=a    ,		default_to_square=a    )
    else:
       if "shortest_edge" in size:
          A__       =     get_resize_output_image_size(a    ,		size=size['shortest_edge']    ,		default_to_square=a    )
       elif "height" in size and "width" in size:
          A__       =     (size['height'], size['width'])
       else:
          raise ValueError('Invalid size for resize: {}'.format(a    )    )

    return resize(a    ,		size=a    ,		resample=a    ,		data_format=a    ,		**a    )






 def 						_UpperCamelCase (self       :  int    ,		a       :  Dict    ,		a       :  Dict    ,		a       :  List[Any] = None    ,		**a       :  Dict    ,		)       ->   np.ndarray:






    """simple docstring"""


    A__       =     get_size_dict(a    )
    if "height" not in size or "width" not in size:
       raise ValueError(f"""size must contain \'height\' and \'width\' as keys. Got {size.keys()}"""    )
    return center_crop(a    ,		size=(size['height'], size['width'])    ,		data_format=a    ,		**a    )






 def 						_UpperCamelCase (self       :  List[Any]    ,		a       :  str    ,		a       :  Union[str, Any]    ,		a       :  Tuple = None    ,		**a       :  Optional[int]    ,		)       ->   List[str]:






    """simple docstring"""


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






 def 						_UpperCamelCase (self       :  Union[str, Any]    ,		a       :  str    ,		a       :  Tuple    ,		a       :  Any    ,		a       :  Optional[Any] = None    ,		**a       :  Any    ,		)       ->   np.ndarray:






    """simple docstring"""


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






 def 						_UpperCamelCase (self       :  Tuple    ,		a       :  List[str]    ,		a       :  List[Any] = None    ,		a       :  Dict = None    ,		a       :  int = None    ,		a       :  List[Any] = None    ,		a       :  List[Any] = None    ,		a       :  str = None    ,		a       :  Union[str, Any] = None    ,		a       :  List[Any] = None    ,		a       :  Tuple = None    ,		a       :  List[Any] = None    ,		a       :  Tuple = None    ,		a       :  Tuple = None    ,		a       :  Any = ChannelDimension.FIRST    ,		**a       :  Optional[Any]    ,		)       ->   PIL.Image.Image:






    """simple docstring"""


    A__       =     do_resize if do_resize is not None else self.do_resize
    A__       =     crop_pct if crop_pct is not None else self.crop_pct
    A__       =     resample if resample is not None else self.resample
    A__       =     do_center_crop if do_center_crop is not None else self.do_center_crop
    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__       =     size if size is not None else self.size
    A__       =     get_size_dict(a    ,		default_to_square=a    )
    A__       =     crop_size if crop_size is not None else self.crop_size
    A__       =     get_size_dict(a    ,		param_name='crop_size'    )

    A__       =     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_center_crop and crop_pct is None:
       raise ValueError('Crop_pct 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.'    )

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

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

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

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

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

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

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









"""simple docstring"""





from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE__   =  logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__   =  {
    "uclanlp/visualbert-vqa": "https://huggingface.co/uclanlp/visualbert-vqa/resolve/main/config.json",
    "uclanlp/visualbert-vqa-pre": "https://huggingface.co/uclanlp/visualbert-vqa-pre/resolve/main/config.json",
    "uclanlp/visualbert-vqa-coco-pre": (
        "https://huggingface.co/uclanlp/visualbert-vqa-coco-pre/resolve/main/config.json"
    ),
    "uclanlp/visualbert-vcr": "https://huggingface.co/uclanlp/visualbert-vcr/resolve/main/config.json",
    "uclanlp/visualbert-vcr-pre": "https://huggingface.co/uclanlp/visualbert-vcr-pre/resolve/main/config.json",
    "uclanlp/visualbert-vcr-coco-pre": (
        "https://huggingface.co/uclanlp/visualbert-vcr-coco-pre/resolve/main/config.json"
    ),
    "uclanlp/visualbert-nlvr2": "https://huggingface.co/uclanlp/visualbert-nlvr2/resolve/main/config.json",
    "uclanlp/visualbert-nlvr2-pre": "https://huggingface.co/uclanlp/visualbert-nlvr2-pre/resolve/main/config.json",
    "uclanlp/visualbert-nlvr2-coco-pre": (
        "https://huggingface.co/uclanlp/visualbert-nlvr2-coco-pre/resolve/main/config.json"
    )
    # See all VisualBERT models at https://huggingface.co/models?filter=visual_bert
}

class 						lowercase   (   _UpperCAmelCase   ):
      _SCREAMING_SNAKE_CASE							      = 'visual_bert'





      def __init__(			self ,		lowercase=30_522 ,		lowercase=768 ,		lowercase=512 ,		lowercase=12 ,		lowercase=12 ,		lowercase=3_072 ,		lowercase="gelu" ,		lowercase=0.1 ,		lowercase=0.1 ,		lowercase=512 ,		lowercase=2 ,		lowercase=0.02 ,		lowercase=1e-12 ,		lowercase=False ,		lowercase=True ,		lowercase=1 ,		lowercase=0 ,		lowercase=2 ,		**lowercase ,		)						->	int:
            super().__init__(pad_token_id=lowercase ,		bos_token_id=lowercase ,		eos_token_id=lowercase ,		**lowercase					)

            lowerCAmelCase    		=			vocab_size
            lowerCAmelCase    		=			max_position_embeddings
            lowerCAmelCase    		=			hidden_size
            lowerCAmelCase    		=			visual_embedding_dim
            lowerCAmelCase    		=			num_hidden_layers
            lowerCAmelCase    		=			num_attention_heads
            lowerCAmelCase    		=			intermediate_size
            lowerCAmelCase    		=			hidden_act
            lowerCAmelCase    		=			hidden_dropout_prob
            lowerCAmelCase    		=			attention_probs_dropout_prob
            lowerCAmelCase    		=			initializer_range
            lowerCAmelCase    		=			type_vocab_size
            lowerCAmelCase    		=			layer_norm_eps
            lowerCAmelCase    		=			bypass_transformer
            lowerCAmelCase    		=			special_visual_initialize






