


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    __magic_name__						(  unittest.TestCase):


     def __init__(   self				:  List[Any]				,						lowerCamelCase__				:  Any				,						lowerCamelCase__				:  List[Any]=7				,						lowerCamelCase__				:  List[Any]=3				,						lowerCamelCase__				:  Union[str, Any]=18				,						lowerCamelCase__				:  List[str]=30				,						lowerCamelCase__				:  Union[str, Any]=400				,						lowerCamelCase__				:  Any=True				,						lowerCamelCase__				:  Tuple=None				,						lowerCamelCase__				:  Tuple=True				,						lowerCamelCase__				:  int=None				,						lowerCamelCase__				:  Dict=True				,						lowerCamelCase__				:  List[str]=[0.4814_5466, 0.457_8275, 0.4082_1073]				,						lowerCamelCase__				:  List[str]=[0.2686_2954, 0.2613_0258, 0.2757_7711]				,						lowerCamelCase__				:  List[Any]=True				,						)	->   Dict:





      '''simple docstring'''






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


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





      '''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    __magic_name__						(  __lowerCAmelCase       ,					unittest.TestCase):
     A:		int								=   OwlViTImageProcessor if is_vision_available() else None


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





      '''simple docstring'''






      UpperCamelCase__       :     Dict 							= OwlViTImageProcessingTester(self      )


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





      '''simple docstring'''






      return self.image_processor_tester.prepare_image_processor_dict()


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





      '''simple docstring'''






      UpperCamelCase__       :     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				:  List[Any]      )	->   Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__       :     Tuple 							= 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]      )	->   Union[str, Any]:





      '''simple docstring'''






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


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





      '''simple docstring'''






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


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





      '''simple docstring'''






      UpperCamelCase__       :     str 							= self.image_processing_class(**self.image_processor_dict      )
      # create random PyTorch tensors
      UpperCamelCase__       :     Tuple 							= 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__       :     Optional[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__       :     Tuple 							= 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'''],
          )				,						)






from typing import TYPE_CHECKING

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


__UpperCamelCase							:							List[Any]    							=					{
    "configuration_mpnet": ["MPNET_PRETRAINED_CONFIG_ARCHIVE_MAP", "MPNetConfig"],
    "tokenization_mpnet": ["MPNetTokenizer"],
}

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase							:							Union[str, Any]    							=					["MPNetTokenizerFast"]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase							:							Union[str, Any]    							=					[
           "MPNET_PRETRAINED_MODEL_ARCHIVE_LIST",
           "MPNetForMaskedLM",
           "MPNetForMultipleChoice",
           "MPNetForQuestionAnswering",
           "MPNetForSequenceClassification",
           "MPNetForTokenClassification",
           "MPNetLayer",
           "MPNetModel",
           "MPNetPreTrainedModel",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase							:							List[Any]    							=					[
           "TF_MPNET_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TFMPNetEmbeddings",
           "TFMPNetForMaskedLM",
           "TFMPNetForMultipleChoice",
           "TFMPNetForQuestionAnswering",
           "TFMPNetForSequenceClassification",
           "TFMPNetForTokenClassification",
           "TFMPNetMainLayer",
           "TFMPNetModel",
           "TFMPNetPreTrainedModel",
       ]


if TYPE_CHECKING:
       from .configuration_mpnet import MPNET_PRETRAINED_CONFIG_ARCHIVE_MAP, MPNetConfig
       from .tokenization_mpnet import MPNetTokenizer

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_mpnet_fast import MPNetTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_mpnet import (
                  MPNET_PRETRAINED_MODEL_ARCHIVE_LIST,
                  MPNetForMaskedLM,
                  MPNetForMultipleChoice,
                  MPNetForQuestionAnswering,
                  MPNetForSequenceClassification,
                  MPNetForTokenClassification,
                  MPNetLayer,
                  MPNetModel,
                  MPNetPreTrainedModel,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_mpnet import (
                  TF_MPNET_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFMPNetEmbeddings,
                  TFMPNetForMaskedLM,
                  TFMPNetForMultipleChoice,
                  TFMPNetForQuestionAnswering,
                  TFMPNetForSequenceClassification,
                  TFMPNetForTokenClassification,
                  TFMPNetMainLayer,
                  TFMPNetModel,
                  TFMPNetPreTrainedModel,
              )

else:
       import sys

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


