



'''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_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


a							   =				logging.get_logger(__name__)






class 						a_		(     snake_case    ):
							UpperCAmelCase			:		List[Any]        =				["""pixel_values"""]


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


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


							def    UpperCamelCase     (				self   :						List[str]      ,						a_   :						np.ndarray      ,						a_   :						Dict[str, int]      ,						a_   :						Optional[Union[str, ChannelDimension]] = None      ,						**a_   :						List[Any]      ,						)			->					np.ndarray:
										snake_case:    Optional[int]      							=get_size_dict(a_			)
										return center_crop(a_      ,						size=(size['height'], size['width'])      ,						data_format=a_      ,						**a_			)


							def    UpperCamelCase     (				self   :						int      ,						a_   :						np.ndarray      ,						a_   :						float      ,						a_   :						Optional[Union[str, ChannelDimension]] = None      ,						**a_   :						Tuple			)			->					np.ndarray:
										return rescale(a_      ,						scale=a_      ,						data_format=a_      ,						**a_			)


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




							def    UpperCamelCase     (				self   :						int      ,						a_   :						ImageInput      ,						a_   :						Optional[bool] = None      ,						a_   :						Dict[str, int] = None      ,						a_   :						PILImageResampling = None      ,						a_   :						bool = None      ,						a_   :						Dict[str, int] = None      ,						a_   :						Optional[bool] = None      ,						a_   :						Optional[float] = None      ,						a_   :						Optional[bool] = None      ,						a_   :						Optional[Union[float, List[float]]] = None      ,						a_   :						Optional[Union[float, List[float]]] = None      ,						a_   :						Optional[Union[str, TensorType]] = None      ,						a_   :						Union[str, ChannelDimension] = ChannelDimension.FIRST      ,						**a_   :						str      ,						)			->					List[str]:
										snake_case:    Optional[Any]      							=do_resize if do_resize is not None else self.do_resize
										snake_case:    Union[str, Any]      							=size if size is not None else self.size
										snake_case:    Dict      							=get_size_dict(a_      ,						default_to_square=a_			)
										snake_case:    List[Any]      							=resample if resample is not None else self.resample
										snake_case:    Dict      							=do_center_crop if do_center_crop is not None else self.do_center_crop
										snake_case:    Union[str, Any]      							=crop_size if crop_size is not None else self.crop_size
										snake_case:    Tuple      							=get_size_dict(a_			)
										snake_case:    Union[str, Any]      							=do_rescale if do_rescale is not None else self.do_rescale
										snake_case:    int      							=rescale_factor if rescale_factor is not None else self.rescale_factor
										snake_case:    Optional[int]      							=do_normalize if do_normalize is not None else self.do_normalize
										snake_case:    str      							=image_mean if image_mean is not None else self.image_mean
										snake_case:    Any      							=image_std if image_std is not None else self.image_std

										snake_case:    List[str]      							=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:
													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.
										snake_case:    str      							=[to_numpy_array(a_			) for image in images]

										if do_resize:
													snake_case:    Optional[int]      							=[self.resize(image=a_      ,						size=a_      ,						resample=a_			) for image in images]

										if do_center_crop:
													snake_case:    List[Any]      							=[self.center_crop(image=a_      ,						size=a_			) for image in images]

										if do_rescale:
													snake_case:    Dict      							=[self.rescale(image=a_      ,						scale=a_			) for image in images]

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

										snake_case:    Dict      							=[to_channel_dimension_format(a_      ,						a_			) for image in images]

										snake_case:    str      							={'pixel_values': images}
										return BatchFeature(data=a_      ,						tensor_type=a_			)









'''simple docstring'''

from typing import TYPE_CHECKING

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


a							   =				{
    'configuration_owlvit': [
        'OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'OwlViTConfig',
        'OwlViTOnnxConfig',
        'OwlViTTextConfig',
        'OwlViTVisionConfig',
    ],
    'processing_owlvit': ['OwlViTProcessor'],
}


try:
	if not is_vision_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	a							   =				['OwlViTFeatureExtractor']
	a							   =				['OwlViTImageProcessor']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	a							   =				[
	    'OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'OwlViTModel',
	    'OwlViTPreTrainedModel',
	    'OwlViTTextModel',
	    'OwlViTVisionModel',
	    'OwlViTForObjectDetection',
	]

if TYPE_CHECKING:
	from .configuration_owlvit import (
	    OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    OwlViTConfig,
	    OwlViTOnnxConfig,
	    OwlViTTextConfig,
	    OwlViTVisionConfig,
	)
	from .processing_owlvit import OwlViTProcessor

	try:
		if not is_vision_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .feature_extraction_owlvit import OwlViTFeatureExtractor
		from .image_processing_owlvit import OwlViTImageProcessor

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_owlvit import (
		    OWLVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    OwlViTForObjectDetection,
		    OwlViTModel,
		    OwlViTPreTrainedModel,
		    OwlViTTextModel,
		    OwlViTVisionModel,
		)

else:
	import sys

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




