





'''simple docstring'''



import copy
import os
from typing import Union

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


_SCREAMING_SNAKE_CASE					=    logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE					=    {
    '''microsoft/git-base''': '''https://huggingface.co/microsoft/git-base/resolve/main/config.json''',
}






class 							__lowercase       (      lowerCAmelCase__						):







	'''simple docstring'''

	a    :				Union[str, Any]											=       "git_vision_model"


	def __init__(self     ,_lowerCamelCase=768     ,_lowerCamelCase=3072     ,_lowerCamelCase=12     ,_lowerCamelCase=12     ,_lowerCamelCase=3     ,_lowerCamelCase=224     ,_lowerCamelCase=16     ,_lowerCamelCase="quick_gelu"     ,_lowerCamelCase=1E-5     ,_lowerCamelCase=0.0     ,_lowerCamelCase=0.0_2     ,**_lowerCamelCase     ,)							->							Optional[Any]:







				'''simple docstring'''





				super().__init__(**_lowerCamelCase )

				__lowercase										=							hidden_size
				__lowercase										=							intermediate_size
				__lowercase										=							num_hidden_layers
				__lowercase										=							num_attention_heads
				__lowercase										=							num_channels
				__lowercase										=							patch_size
				__lowercase										=							image_size
				__lowercase										=							initializer_range
				__lowercase										=							attention_dropout
				__lowercase										=							layer_norm_eps
				__lowercase										=							hidden_act


	@classmethod
	def 						_UpperCAmelCase     (cls     ,_lowerCamelCase     ,**_lowerCamelCase )							->							"PretrainedConfig":







				'''simple docstring'''





				cls._set_token_in_kwargs(_lowerCamelCase )

				__lowercase						,		__lowercase										=							cls.get_config_dict(_lowerCamelCase     ,**_lowerCamelCase )

				# get the vision config dict if we are loading from GITConfig
				if config_dict.get('''model_type''' ) == "git":
							__lowercase										=							config_dict['''vision_config''']

				if "model_type" in config_dict and hasattr(cls     ,'''model_type''' ) and config_dict["model_type"] != cls.model_type:
							logger.warning(
							    f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
							    f"{cls.model_type}. This is not supported for all configurations of models and can yield errors." )

				return cls.from_dict(_lowerCamelCase     ,**_lowerCamelCase )






class 							__lowercase       (      lowerCAmelCase__						):







	'''simple docstring'''

	a    :				Dict											=       "git"


	def __init__(self     ,_lowerCamelCase=None     ,_lowerCamelCase=30522     ,_lowerCamelCase=768     ,_lowerCamelCase=6     ,_lowerCamelCase=12     ,_lowerCamelCase=3072     ,_lowerCamelCase="gelu"     ,_lowerCamelCase=0.1     ,_lowerCamelCase=0.1     ,_lowerCamelCase=1024     ,_lowerCamelCase=0.0_2     ,_lowerCamelCase=1E-1_2     ,_lowerCamelCase=0     ,_lowerCamelCase="absolute"     ,_lowerCamelCase=True     ,_lowerCamelCase=False     ,_lowerCamelCase=101     ,_lowerCamelCase=102     ,_lowerCamelCase=None     ,**_lowerCamelCase     ,)							->							List[str]:







				'''simple docstring'''





				super().__init__(bos_token_id=_lowerCamelCase     ,eos_token_id=_lowerCamelCase     ,pad_token_id=_lowerCamelCase     ,**_lowerCamelCase )

				if vision_config is None:
							__lowercase										=							{}
							logger.info('''vision_config is None. initializing the GitVisionConfig with default values.''' )

				__lowercase										=							GitVisionConfig(**_lowerCamelCase )
				__lowercase										=							vocab_size
				__lowercase										=							hidden_size
				__lowercase										=							num_hidden_layers
				__lowercase										=							num_attention_heads
				__lowercase										=							hidden_act
				__lowercase										=							intermediate_size
				__lowercase										=							hidden_dropout_prob
				__lowercase										=							attention_probs_dropout_prob
				__lowercase										=							max_position_embeddings
				__lowercase										=							initializer_range
				__lowercase										=							layer_norm_eps
				__lowercase										=							position_embedding_type
				__lowercase										=							use_cache
				__lowercase										=							tie_word_embeddings
				__lowercase										=							num_image_with_embedding

				__lowercase										=							bos_token_id
				__lowercase										=							eos_token_id


	def 						_UpperCAmelCase     (self )							->							Union[str, Any]:







				'''simple docstring'''





				__lowercase										=							copy.deepcopy(self.__dict__ )
				__lowercase										=							self.vision_config.to_dict()
				__lowercase										=							self.__class__.model_type
				return output












'''simple docstring'''



from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


_SCREAMING_SNAKE_CASE					=    logging.get_logger(__name__)






class 							__lowercase       (      lowerCAmelCase__						):







	'''simple docstring'''

	a    :				int											=       ["pixel_values"]


	def __init__(self     ,_lowerCamelCase = True     ,_lowerCamelCase = 32     ,_lowerCamelCase=PILImageResampling.BILINEAR     ,_lowerCamelCase = True     ,**_lowerCamelCase     ,)							->							None:







				'''simple docstring'''





				__lowercase										=							do_resize
				__lowercase										=							do_rescale
				__lowercase										=							size_divisor
				__lowercase										=							resample
				super().__init__(**_lowerCamelCase )


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase     ,_lowerCamelCase     ,_lowerCamelCase = None     ,**_lowerCamelCase )							->							np.ndarray:







				'''simple docstring'''





				__lowercase						,		__lowercase										=							get_image_size(_lowerCamelCase )
				# Rounds the height and width down to the closest multiple of size_divisor
				__lowercase										=							height // size_divisor * size_divisor
				__lowercase										=							width // size_divisor * size_divisor
				__lowercase										=							resize(_lowerCamelCase     ,(new_h, new_w)     ,resample=_lowerCamelCase     ,data_format=_lowerCamelCase     ,**_lowerCamelCase )
				return image


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase     ,_lowerCamelCase = None     ,**_lowerCamelCase )							->							np.ndarray:







				'''simple docstring'''





				return rescale(image=_lowerCamelCase     ,scale=_lowerCamelCase     ,data_format=_lowerCamelCase     ,**_lowerCamelCase )


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase = None     ,_lowerCamelCase = None     ,_lowerCamelCase=None     ,_lowerCamelCase = None     ,_lowerCamelCase = None     ,_lowerCamelCase = ChannelDimension.FIRST     ,**_lowerCamelCase     ,)							->							BatchFeature:







				'''simple docstring'''





				__lowercase										=							do_resize if do_resize is not None else self.do_resize
				__lowercase										=							do_rescale if do_rescale is not None else self.do_rescale
				__lowercase										=							size_divisor if size_divisor is not None else self.size_divisor
				__lowercase										=							resample if resample is not None else self.resample

				if do_resize and size_divisor is None:
							raise ValueError('''size_divisor is required for resizing''' )

				__lowercase										=							make_list_of_images(_lowerCamelCase )

				if not valid_images(_lowerCamelCase ):
							raise ValueError('''Invalid image(s)''' )

				# All transformations expect numpy arrays.
				__lowercase										=							[to_numpy_array(_lowerCamelCase ) for img in images]

				if do_resize:
							__lowercase										=							[self.resize(_lowerCamelCase     ,size_divisor=_lowerCamelCase     ,resample=_lowerCamelCase ) for image in images]

				if do_rescale:
							__lowercase										=							[self.rescale(_lowerCamelCase     ,scale=1 / 255 ) for image in images]

				__lowercase										=							[to_channel_dimension_format(_lowerCamelCase     ,_lowerCamelCase ) for image in images]

				__lowercase										=							{'''pixel_values''': images}
				return BatchFeature(data=_lowerCamelCase     ,tensor_type=_lowerCamelCase )





