'''simple docstring'''

import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import OwlViTImageProcessor




class    lowerCamelCase__  (   unittest.TestCase     ):



   def __init__(    self					,      lowerCAmelCase__					,      lowerCAmelCase__=7					,      lowerCAmelCase__=3					,      lowerCAmelCase__=18					,      lowerCAmelCase__=30					,      lowerCAmelCase__=400					,      lowerCAmelCase__=True					,      lowerCAmelCase__=None					,      lowerCAmelCase__=True					,      lowerCAmelCase__=None					,      lowerCAmelCase__=True					,      lowerCAmelCase__=[0.4814_5466, 0.457_8275, 0.4082_1073]					,      lowerCAmelCase__=[0.2686_2954, 0.2613_0258, 0.2757_7711]					,      lowerCAmelCase__=True					,      )				->     Optional[int]:
        """simple docstring"""





        _UpperCamelCase  :List[str]       =parent
        _UpperCamelCase  :Optional[Any]       =batch_size
        _UpperCamelCase  :Any       =num_channels
        _UpperCamelCase  :int       =image_size
        _UpperCamelCase  :Optional[Any]       =min_resolution
        _UpperCamelCase  :int       =max_resolution
        _UpperCamelCase  :List[Any]       =do_resize
        _UpperCamelCase  :Any       =size if size is not None else {"""height""": 18, """width""": 18}
        _UpperCamelCase  :Dict       =do_center_crop
        _UpperCamelCase  :List[str]       =crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
        _UpperCamelCase  :Any       =do_normalize
        _UpperCamelCase  :Any       =image_mean
        _UpperCamelCase  :str       =image_std
        _UpperCamelCase  :str       =do_convert_rgb




   def  _UpperCamelCase		(    self     )				->     List[str]:
        """simple docstring"""





        return {
            "do_resize": self.do_resize,
            "size": self.size,
            "do_center_crop": self.do_center_crop,
            "crop_size": self.crop_size,
            "do_normalize": self.do_normalize,
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_convert_rgb": self.do_convert_rgb,
        }




@require_torch
@require_vision
class    lowerCamelCase__  (   __snake_case       ,				unittest.TestCase     ):
   __UpperCAmelCase           =						OwlViTImageProcessor if is_vision_available() else None



   def  _UpperCamelCase		(    self     )				->     Union[str, Any]:
        """simple docstring"""





        _UpperCamelCase  :Union[str, Any]       =OwlViTImageProcessingTester(self     )



   @property
   def  _UpperCamelCase		(    self     )				->     Any:
        """simple docstring"""





        return self.image_processor_tester.prepare_image_processor_dict()



   def  _UpperCamelCase		(    self     )				->     int:
        """simple docstring"""





        _UpperCamelCase  :List[Any]       =self.image_processing_class(**self.image_processor_dict     )
        self.assertTrue(hasattr(lowerCAmelCase__					,      """do_resize"""     )     )
        self.assertTrue(hasattr(lowerCAmelCase__					,      """size"""     )     )
        self.assertTrue(hasattr(lowerCAmelCase__					,      """do_center_crop"""     )     )
        self.assertTrue(hasattr(lowerCAmelCase__					,      """center_crop"""     )     )
        self.assertTrue(hasattr(lowerCAmelCase__					,      """do_normalize"""     )     )
        self.assertTrue(hasattr(lowerCAmelCase__					,      """image_mean"""     )     )
        self.assertTrue(hasattr(lowerCAmelCase__					,      """image_std"""     )     )
        self.assertTrue(hasattr(lowerCAmelCase__					,      """do_convert_rgb"""     )     )



   def  _UpperCamelCase		(    self     )				->     Tuple:
        """simple docstring"""





        _UpperCamelCase  :Any       =self.image_processing_class.from_dict(self.image_processor_dict     )
        self.assertEqual(image_processor.size					,      {"""height""": 18, """width""": 18}     )
        self.assertEqual(image_processor.crop_size					,      {"""height""": 18, """width""": 18}     )

        _UpperCamelCase  :str       =self.image_processing_class.from_dict(self.image_processor_dict					,      size=42					,      crop_size=84     )
        self.assertEqual(image_processor.size					,      {"""height""": 42, """width""": 42}     )
        self.assertEqual(image_processor.crop_size					,      {"""height""": 84, """width""": 84}     )



   def  _UpperCamelCase		(    self     )				->     List[str]:
        """simple docstring"""





        _UpperCamelCase  :Union[str, Any]       =self.image_processing_class(**self.image_processor_dict     )
        # create random PIL images
        _UpperCamelCase  :List[str]       =prepare_image_inputs(self.image_processor_tester					,      equal_resolution=lowerCAmelCase__     )

        for image in image_inputs:
             self.assertIsInstance(lowerCAmelCase__					,      Image.Image     )

        # Test not batched input
        _UpperCamelCase  :str       =image_processing(image_inputs[0]					,      return_tensors="""pt"""     ).pixel_values
        self.assertEqual(
            encoded_images.shape					,      (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )					,      )

        # Test batched
        _UpperCamelCase  :List[Any]       =image_processing(lowerCAmelCase__					,      return_tensors="""pt"""     ).pixel_values
        self.assertEqual(
            encoded_images.shape					,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )					,      )



   def  _UpperCamelCase		(    self     )				->     str:
        """simple docstring"""





        _UpperCamelCase  :List[str]       =self.image_processing_class(**self.image_processor_dict     )
        # create random numpy tensors
        _UpperCamelCase  :Any       =prepare_image_inputs(self.image_processor_tester					,      equal_resolution=lowerCAmelCase__					,      numpify=lowerCAmelCase__     )
        for image in image_inputs:
             self.assertIsInstance(lowerCAmelCase__					,      np.ndarray     )

        # Test not batched input
        _UpperCamelCase  :Optional[int]       =image_processing(image_inputs[0]					,      return_tensors="""pt"""     ).pixel_values
        self.assertEqual(
            encoded_images.shape					,      (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )					,      )

        # Test batched
        _UpperCamelCase  :str       =image_processing(lowerCAmelCase__					,      return_tensors="""pt"""     ).pixel_values
        self.assertEqual(
            encoded_images.shape					,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )					,      )




   def  _UpperCamelCase		(    self     )				->     List[str]:
        """simple docstring"""





        _UpperCamelCase  :List[str]       =self.image_processing_class(**self.image_processor_dict     )
        # create random PyTorch tensors
        _UpperCamelCase  :Dict       =prepare_image_inputs(self.image_processor_tester					,      equal_resolution=lowerCAmelCase__					,      torchify=lowerCAmelCase__     )
        for image in image_inputs:
             self.assertIsInstance(lowerCAmelCase__					,      torch.Tensor     )

        # Test not batched input
        _UpperCamelCase  :Any       =image_processing(image_inputs[0]					,      return_tensors="""pt"""     ).pixel_values
        self.assertEqual(
            encoded_images.shape					,      (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )					,      )

        # Test batched
        _UpperCamelCase  :Dict       =image_processing(lowerCAmelCase__					,      return_tensors="""pt"""     ).pixel_values
        self.assertEqual(
            encoded_images.shape					,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )					,      )






'''simple docstring'''







from typing import TYPE_CHECKING

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


snake_case_  :							Any            =	{
    "configuration_dpr": ["DPR_PRETRAINED_CONFIG_ARCHIVE_MAP", "DPRConfig"],
    "tokenization_dpr": [
        "DPRContextEncoderTokenizer",
        "DPRQuestionEncoderTokenizer",
        "DPRReaderOutput",
        "DPRReaderTokenizer",
    ],
}


try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_  :							str            =	[
					    "DPRContextEncoderTokenizerFast",
					    "DPRQuestionEncoderTokenizerFast",
					    "DPRReaderTokenizerFast",
					]

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_  :							Optional[int]            =	[
					    "DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "DPRContextEncoder",
					    "DPRPretrainedContextEncoder",
					    "DPRPreTrainedModel",
					    "DPRPretrainedQuestionEncoder",
					    "DPRPretrainedReader",
					    "DPRQuestionEncoder",
					    "DPRReader",
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_  :							Dict            =	[
					    "TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "TFDPRContextEncoder",
					    "TFDPRPretrainedContextEncoder",
					    "TFDPRPretrainedQuestionEncoder",
					    "TFDPRPretrainedReader",
					    "TFDPRQuestionEncoder",
					    "TFDPRReader",
					]


if TYPE_CHECKING:
					from .configuration_dpr import DPR_PRETRAINED_CONFIG_ARCHIVE_MAP, DPRConfig
					from .tokenization_dpr import (
					    DPRContextEncoderTokenizer,
					    DPRQuestionEncoderTokenizer,
					    DPRReaderOutput,
					    DPRReaderTokenizer,
					)

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_dpr_fast import (
										    DPRContextEncoderTokenizerFast,
										    DPRQuestionEncoderTokenizerFast,
										    DPRReaderTokenizerFast,
										)

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_dpr import (
										    DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    DPRContextEncoder,
										    DPRPretrainedContextEncoder,
										    DPRPreTrainedModel,
										    DPRPretrainedQuestionEncoder,
										    DPRPretrainedReader,
										    DPRQuestionEncoder,
										    DPRReader,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_dpr import (
										    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFDPRContextEncoder,
										    TFDPRPretrainedContextEncoder,
										    TFDPRPretrainedQuestionEncoder,
										    TFDPRPretrainedReader,
										    TFDPRQuestionEncoder,
										    TFDPRReader,
										)

else:
					import sys

					snake_case_  :							List[str]            =	_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





