


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 EfficientNetImageProcessor

class    __magic_name__						(  unittest.TestCase):


     def __init__(   self				:  Tuple				,						lowerCamelCase__				:  List[str]				,						lowerCamelCase__				:  Optional[Any]=13				,						lowerCamelCase__				:  List[Any]=3				,						lowerCamelCase__				:  Tuple=18				,						lowerCamelCase__				:  Union[str, Any]=30				,						lowerCamelCase__				:  List[str]=400				,						lowerCamelCase__				:  List[str]=True				,						lowerCamelCase__				:  List[str]=None				,						lowerCamelCase__				:  List[Any]=True				,						lowerCamelCase__				:  List[str]=[0.5, 0.5, 0.5]				,						lowerCamelCase__				:  Optional[int]=[0.5, 0.5, 0.5]				,						)	->   Union[str, Any]:





      '''simple docstring'''






      UpperCamelCase__       :     Tuple 							= size if size is not None else {'''height''': 18, '''width''': 18}
      UpperCamelCase__       :     str 							= parent
      UpperCamelCase__       :     Union[str, Any] 							= batch_size
      UpperCamelCase__       :     List[Any] 							= num_channels
      UpperCamelCase__       :     Union[str, Any] 							= image_size
      UpperCamelCase__       :     Optional[Any] 							= min_resolution
      UpperCamelCase__       :     Union[str, Any] 							= max_resolution
      UpperCamelCase__       :     List[Any] 							= do_resize
      UpperCamelCase__       :     int 							= size
      UpperCamelCase__       :     Tuple 							= do_normalize
      UpperCamelCase__       :     int 							= image_mean
      UpperCamelCase__       :     Optional[int] 							= image_std


     def   UpperCAmelCase__						(   self				:  str      )	->   Dict:





      '''simple docstring'''






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



@require_torch
@require_vision
class    __magic_name__						(  __lowerCAmelCase       ,					unittest.TestCase):
     A:		List[str]								=   EfficientNetImageProcessor if is_vision_available() else None


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





      '''simple docstring'''






      UpperCamelCase__       :     Any 							= EfficientNetImageProcessorTester(self      )


     @property
     def   UpperCAmelCase__						(   self				:  Dict      )	->   List[str]:





      '''simple docstring'''






      return self.image_processor_tester.prepare_image_processor_dict()


     def   UpperCAmelCase__						(   self				:  Any      )	->   Tuple:





      '''simple docstring'''






      UpperCamelCase__       :     Dict 							= self.image_processing_class(**self.image_processor_dict      )
      self.assertTrue(hasattr(lowerCamelCase__				,						'''image_mean'''      )      )
      self.assertTrue(hasattr(lowerCamelCase__				,						'''image_std'''      )      )
      self.assertTrue(hasattr(lowerCamelCase__				,						'''do_normalize'''      )      )
      self.assertTrue(hasattr(lowerCamelCase__				,						'''do_resize'''      )      )
      self.assertTrue(hasattr(lowerCamelCase__				,						'''size'''      )      )


     def   UpperCAmelCase__						(   self				:  str      )	->   Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__       :     Dict 							= self.image_processing_class.from_dict(self.image_processor_dict      )
      self.assertEqual(image_processor.size				,						{'''height''': 18, '''width''': 18}      )

      UpperCamelCase__       :     Any 							= self.image_processing_class.from_dict(self.image_processor_dict				,						size=42      )
      self.assertEqual(image_processor.size				,						{'''height''': 42, '''width''': 42}      )


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





      '''simple docstring'''






      UpperCamelCase__       :     Tuple 							= self.image_processing_class(**self.image_processor_dict      )
      # create random PIL images
      UpperCamelCase__       :     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__       :     Dict 							= 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.size['''height'''],
              self.image_processor_tester.size['''width'''],
          )				,						)

      # Test batched
      UpperCamelCase__       :     List[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.size['''height'''],
              self.image_processor_tester.size['''width'''],
          )				,						)


     def   UpperCAmelCase__						(   self				:  Optional[int]      )	->   Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__       :     Tuple 							= self.image_processing_class(**self.image_processor_dict      )
      # create random numpy tensors
      UpperCamelCase__       :     Optional[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__       :     List[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.size['''height'''],
              self.image_processor_tester.size['''width'''],
          )				,						)

      # Test batched
      UpperCamelCase__       :     Union[str, 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.size['''height'''],
              self.image_processor_tester.size['''width'''],
          )				,						)


     def   UpperCAmelCase__						(   self				:  Optional[int]      )	->   Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__       :     Union[str, Any] 							= self.image_processing_class(**self.image_processor_dict      )
      # create random PyTorch tensors
      UpperCamelCase__       :     List[Any] 							= 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__       :     Union[str, 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.size['''height'''],
              self.image_processor_tester.size['''width'''],
          )				,						)

      # Test batched
      UpperCamelCase__       :     int 							= 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.size['''height'''],
              self.image_processor_tester.size['''width'''],
          )				,						)






from typing import TYPE_CHECKING

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


__UpperCamelCase							:							Dict    							=					{
    "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:
       __UpperCamelCase							:							Any    							=					[
           "DPRContextEncoderTokenizerFast",
           "DPRQuestionEncoderTokenizerFast",
           "DPRReaderTokenizerFast",
       ]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase							:							str    							=					[
           "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:
       __UpperCamelCase							:							int    							=					[
           "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

       __UpperCamelCase							:							Dict    							=					_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


