'''simple docstring'''







from typing import Dict, List, Optional, Tuple, 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_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, logging


if is_torch_available():
		import torch


UpperCamelCase_      	=	logging.get_logger(__name__)




class _SCREAMING_SNAKE_CASE(							_SCREAMING_SNAKE_CASE					):
						A_			:							Optional[int]     		= ['pixel_values']




						def __init__(    self :       Dict							,							UpperCamelCase_ :       bool = True							,							UpperCamelCase_ :       Optional[Dict[str, int]] = None							,							UpperCamelCase_ :       PILImageResampling = PILImageResampling.BILINEAR							,							UpperCamelCase_ :       bool = True							,							UpperCamelCase_ :       Dict[str, int] = None							,							UpperCamelCase_ :       bool = True							,							UpperCamelCase_ :       Union[int, float] = 1 / 2_55							,							UpperCamelCase_ :       bool = True							,							UpperCamelCase_ :       Optional[Union[float, List[float]]] = None							,							UpperCamelCase_ :       Optional[Union[float, List[float]]] = None							,							**UpperCamelCase_ :       Optional[int]							,							)     ->				None:
													super().__init__(**UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = size if size is not None else {'shortest_edge': 2_56}
													SCREAMING_SNAKE_CASE__     :Dict						    = get_size_dict(UpperCamelCase_							,							default_to_square=UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Tuple						    = crop_size if crop_size is not None else {'height': 2_24, 'width': 2_24}
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = get_size_dict(UpperCamelCase_							,							param_name='crop_size'      )
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = do_resize
													SCREAMING_SNAKE_CASE__     :int						    = size
													SCREAMING_SNAKE_CASE__     :List[str]						    = resample
													SCREAMING_SNAKE_CASE__     :str						    = do_center_crop
													SCREAMING_SNAKE_CASE__     :Optional[int]						    = crop_size
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = do_rescale
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = rescale_factor
													SCREAMING_SNAKE_CASE__     :Any						    = do_normalize
													SCREAMING_SNAKE_CASE__     :str						    = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = image_std if image_std is not None else IMAGENET_STANDARD_STD




						def      __lowerCamelCase       (    self :       Dict							,							UpperCamelCase_ :       np.ndarray							,							UpperCamelCase_ :       Dict[str, int]							,							UpperCamelCase_ :       PILImageResampling = PILImageResampling.BICUBIC							,							UpperCamelCase_ :       Optional[Union[str, ChannelDimension]] = None							,							**UpperCamelCase_ :       List[Any]							,							)     ->				np.ndarray:
													SCREAMING_SNAKE_CASE__     :Dict						    = get_size_dict(UpperCamelCase_							,							default_to_square=UpperCamelCase_      )
													if "shortest_edge" not in size:
																				raise ValueError(f'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'''      )
													SCREAMING_SNAKE_CASE__     :Optional[int]						    = get_resize_output_image_size(UpperCamelCase_							,							size=size['shortest_edge']							,							default_to_square=UpperCamelCase_      )
													return resize(UpperCamelCase_							,							size=UpperCamelCase_							,							resample=UpperCamelCase_							,							data_format=UpperCamelCase_							,							**UpperCamelCase_      )




						def      __lowerCamelCase       (    self :       Tuple							,							UpperCamelCase_ :       np.ndarray							,							UpperCamelCase_ :       Dict[str, int]							,							UpperCamelCase_ :       Optional[Union[str, ChannelDimension]] = None							,							**UpperCamelCase_ :       str							,							)     ->				np.ndarray:
													SCREAMING_SNAKE_CASE__     :List[Any]						    = get_size_dict(UpperCamelCase_      )
													if "height" not in size or "width" not in size:
																				raise ValueError(f'''The `size` parameter must contain the keys `height` and `width`. Got {size.keys()}'''      )
													return center_crop(UpperCamelCase_							,							size=(size['height'], size['width'])							,							data_format=UpperCamelCase_							,							**UpperCamelCase_      )




						def      __lowerCamelCase       (    self :       Optional[Any]							,							UpperCamelCase_ :       np.ndarray							,							UpperCamelCase_ :       float							,							UpperCamelCase_ :       Optional[Union[str, ChannelDimension]] = None							,							**UpperCamelCase_ :       Union[str, Any]      )     ->				np.ndarray:
													return rescale(UpperCamelCase_							,							scale=UpperCamelCase_							,							data_format=UpperCamelCase_							,							**UpperCamelCase_      )




						def      __lowerCamelCase       (    self :       Union[str, Any]							,							UpperCamelCase_ :       np.ndarray							,							UpperCamelCase_ :       Union[float, List[float]]							,							UpperCamelCase_ :       Union[float, List[float]]							,							UpperCamelCase_ :       Optional[Union[str, ChannelDimension]] = None							,							**UpperCamelCase_ :       Optional[Any]							,							)     ->				np.ndarray:
													return normalize(UpperCamelCase_							,							mean=UpperCamelCase_							,							std=UpperCamelCase_							,							data_format=UpperCamelCase_							,							**UpperCamelCase_      )




						def      __lowerCamelCase       (    self :       Any							,							UpperCamelCase_ :       ImageInput							,							UpperCamelCase_ :       Optional[bool] = None							,							UpperCamelCase_ :       Dict[str, int] = None							,							UpperCamelCase_ :       PILImageResampling = None							,							UpperCamelCase_ :       bool = None							,							UpperCamelCase_ :       Dict[str, int] = 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_ :       Union[str, ChannelDimension] = ChannelDimension.FIRST							,							**UpperCamelCase_ :       List[str]							,							)     ->				List[str]:
													SCREAMING_SNAKE_CASE__     :Any						    = do_resize if do_resize is not None else self.do_resize
													SCREAMING_SNAKE_CASE__     :Tuple						    = size if size is not None else self.size
													SCREAMING_SNAKE_CASE__     :List[str]						    = get_size_dict(UpperCamelCase_							,							default_to_square=UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Any						    = resample if resample is not None else self.resample
													SCREAMING_SNAKE_CASE__     :Any						    = do_center_crop if do_center_crop is not None else self.do_center_crop
													SCREAMING_SNAKE_CASE__     :List[str]						    = crop_size if crop_size is not None else self.crop_size
													SCREAMING_SNAKE_CASE__     :str						    = get_size_dict(UpperCamelCase_							,							param_name='crop_size'      )
													SCREAMING_SNAKE_CASE__     :int						    = do_rescale if do_rescale is not None else self.do_rescale
													SCREAMING_SNAKE_CASE__     :int						    = rescale_factor if rescale_factor is not None else self.rescale_factor
													SCREAMING_SNAKE_CASE__     :str						    = do_normalize if do_normalize is not None else self.do_normalize
													SCREAMING_SNAKE_CASE__     :List[Any]						    = image_mean if image_mean is not None else self.image_mean
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = image_std if image_std is not None else self.image_std

													SCREAMING_SNAKE_CASE__     :Dict						    = 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_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.'      )

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

													if do_resize:
																				SCREAMING_SNAKE_CASE__     :Any						    = [self.resize(image=UpperCamelCase_							,							size=UpperCamelCase_							,							resample=UpperCamelCase_      ) for image in images]

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

													if do_rescale:
																				SCREAMING_SNAKE_CASE__     :Optional[int]						    = [self.rescale(image=UpperCamelCase_							,							scale=UpperCamelCase_      ) for image in images]

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

													SCREAMING_SNAKE_CASE__     :List[str]						    = [to_channel_dimension_format(UpperCamelCase_							,							UpperCamelCase_      ) for image in images]

													SCREAMING_SNAKE_CASE__     :List[str]						    = {'pixel_values': images}
													return BatchFeature(data=UpperCamelCase_							,							tensor_type=UpperCamelCase_      )




						def      __lowerCamelCase       (    self :       List[Any]							,							UpperCamelCase_ :       str							,							UpperCamelCase_ :       List[Tuple] = None      )     ->				Dict:
													SCREAMING_SNAKE_CASE__     :List[str]						    = outputs.logits

													# Resize logits and compute semantic segmentation maps
													if target_sizes is not None:
																				if len(UpperCamelCase_      ) != len(UpperCamelCase_      ):
																											raise ValueError(
																											    'Make sure that you pass in as many target sizes as the batch dimension of the logits'      )

																				if is_torch_tensor(UpperCamelCase_      ):
																											SCREAMING_SNAKE_CASE__     :str						    = target_sizes.numpy()

																				SCREAMING_SNAKE_CASE__     :int						    = []

																				for idx in range(len(UpperCamelCase_      )      ):
																											SCREAMING_SNAKE_CASE__     :List[Any]						    = torch.nn.functional.interpolate(
																											    logits[idx].unsqueeze(dim=0      )							,							size=target_sizes[idx]							,							mode='bilinear'							,							align_corners=UpperCamelCase_      )
																											SCREAMING_SNAKE_CASE__     :Any						    = resized_logits[0].argmax(dim=0      )
																											semantic_segmentation.append(UpperCamelCase_      )
													else:
																				SCREAMING_SNAKE_CASE__     :Optional[int]						    = logits.argmax(dim=1      )
																				SCREAMING_SNAKE_CASE__     :Any						    = [semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]      )]

													return semantic_segmentation







'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


UpperCamelCase_      	=	{
    '''configuration_blip''': [
        '''BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''BlipConfig''',
        '''BlipTextConfig''',
        '''BlipVisionConfig''',
    ],
    '''processing_blip''': ['''BlipProcessor'''],
}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCamelCase_      	=	['''BlipImageProcessor''']


try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCamelCase_      	=	[
		    '''BLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''BlipModel''',
		    '''BlipPreTrainedModel''',
		    '''BlipForConditionalGeneration''',
		    '''BlipForQuestionAnswering''',
		    '''BlipVisionModel''',
		    '''BlipTextModel''',
		    '''BlipForImageTextRetrieval''',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCamelCase_      	=	[
		    '''TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''TFBlipModel''',
		    '''TFBlipPreTrainedModel''',
		    '''TFBlipForConditionalGeneration''',
		    '''TFBlipForQuestionAnswering''',
		    '''TFBlipVisionModel''',
		    '''TFBlipTextModel''',
		    '''TFBlipForImageTextRetrieval''',
		]

if TYPE_CHECKING:
		from .configuration_blip import BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP, BlipConfig, BlipTextConfig, BlipVisionConfig
		from .processing_blip import BlipProcessor

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .image_processing_blip import BlipImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_blip import (
				    BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    BlipForConditionalGeneration,
				    BlipForImageTextRetrieval,
				    BlipForQuestionAnswering,
				    BlipModel,
				    BlipPreTrainedModel,
				    BlipTextModel,
				    BlipVisionModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_blip import (
				    TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFBlipForConditionalGeneration,
				    TFBlipForImageTextRetrieval,
				    TFBlipForQuestionAnswering,
				    TFBlipModel,
				    TFBlipPreTrainedModel,
				    TFBlipTextModel,
				    TFBlipVisionModel,
				)

else:
		import sys

		UpperCamelCase_      	=	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






