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



 '''simple docstring'''




 def __init__(						self							:					Optional[Any]				,      lowercase_							:					List[Any]				,      lowercase_							:					int=7				,      lowercase_							:					Tuple=3				,      lowercase_							:					Tuple=18				,      lowercase_							:					Dict=30				,      lowercase_							:					Dict=400				,      lowercase_							:					int=True				,      lowercase_							:					List[str]=None				,      lowercase_							:					Optional[Any]=True				,      lowercase_							:					List[Any]=None				,      lowercase_							:					Tuple=True				,      lowercase_							:					int=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]				,      lowercase_							:					List[Any]=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]				,      lowercase_							:					List[str]=True				,      )		->     List[str]:


   """simple docstring"""







   _UpperCamelCase				=  parent
   _UpperCamelCase				=  batch_size
   _UpperCamelCase				=  num_channels
   _UpperCamelCase				=  image_size
   _UpperCamelCase				=  min_resolution
   _UpperCamelCase				=  max_resolution
   _UpperCamelCase				=  do_resize
   _UpperCamelCase				=  size if size is not None else {"height": 18, "width": 18}
   _UpperCamelCase				=  do_center_crop
   _UpperCamelCase				=  crop_size if crop_size is not None else {"height": 18, "width": 18}
   _UpperCamelCase				=  do_normalize
   _UpperCamelCase				=  image_mean
   _UpperCamelCase				=  image_std
   _UpperCamelCase				=  do_convert_rgb







 def 						__UpperCAmelCase							(						self							:					Tuple)		->     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  _UpperCAmelCase       (			lowerCAmelCase,       unittest.TestCase   ):



 '''simple docstring'''




 __A           = OwlViTImageProcessor if is_vision_available() else None







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


   """simple docstring"""







   _UpperCamelCase				=  OwlViTImageProcessingTester(self)







 @property
 def 						__UpperCAmelCase							(						self							:					Optional[Any])		->     int:


   """simple docstring"""







   return self.image_processor_tester.prepare_image_processor_dict()







 def 						__UpperCAmelCase							(						self							:					Tuple)		->     Optional[int]:


   """simple docstring"""







   _UpperCamelCase				=  self.image_processing_class(**self.image_processor_dict)
   self.assertTrue(hasattr(lowercase_				,      "do_resize"))
   self.assertTrue(hasattr(lowercase_				,      "size"))
   self.assertTrue(hasattr(lowercase_				,      "do_center_crop"))
   self.assertTrue(hasattr(lowercase_				,      "center_crop"))
   self.assertTrue(hasattr(lowercase_				,      "do_normalize"))
   self.assertTrue(hasattr(lowercase_				,      "image_mean"))
   self.assertTrue(hasattr(lowercase_				,      "image_std"))
   self.assertTrue(hasattr(lowercase_				,      "do_convert_rgb"))







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


   """simple docstring"""







   _UpperCamelCase				=  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				=  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							:					Dict)		->     Any:


   """simple docstring"""







   _UpperCamelCase				=  self.image_processing_class(**self.image_processor_dict)
   # create random PIL images
   _UpperCamelCase				=  prepare_image_inputs(self.image_processor_tester				,      equal_resolution=lowercase_)

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

   # Test not batched input
   _UpperCamelCase				=  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				=  image_processing(lowercase_				,      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])		->     int:


   """simple docstring"""







   _UpperCamelCase				=  self.image_processing_class(**self.image_processor_dict)
   # create random numpy tensors
   _UpperCamelCase				=  prepare_image_inputs(self.image_processor_tester				,      equal_resolution=lowercase_				,      numpify=lowercase_)
   for image in image_inputs:
     self.assertIsInstance(lowercase_				,      np.ndarray)

   # Test not batched input
   _UpperCamelCase				=  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				=  image_processing(lowercase_				,      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							:					int)		->     Tuple:


   """simple docstring"""







   _UpperCamelCase				=  self.image_processing_class(**self.image_processor_dict)
   # create random PyTorch tensors
   _UpperCamelCase				=  prepare_image_inputs(self.image_processor_tester				,      equal_resolution=lowercase_				,      torchify=lowercase_)
   for image in image_inputs:
     self.assertIsInstance(lowercase_				,      torch.Tensor)

   # Test not batched input
   _UpperCamelCase				=  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				=  image_processing(lowercase_				,      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 collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase__   = logging.get_logger(__name__)

lowerCamelCase__   = {
    '''nghuyong/ernie-1.0-base-zh''': '''https://huggingface.co/nghuyong/ernie-1.0-base-zh/resolve/main/config.json''',
    '''nghuyong/ernie-2.0-base-en''': '''https://huggingface.co/nghuyong/ernie-2.0-base-en/resolve/main/config.json''',
    '''nghuyong/ernie-2.0-large-en''': '''https://huggingface.co/nghuyong/ernie-2.0-large-en/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-base-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-base-zh/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-medium-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-medium-zh/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-mini-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-mini-zh/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-micro-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-micro-zh/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-nano-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-nano-zh/resolve/main/config.json''',
    '''nghuyong/ernie-gram-zh''': '''https://huggingface.co/nghuyong/ernie-gram-zh/resolve/main/config.json''',
    '''nghuyong/ernie-health-zh''': '''https://huggingface.co/nghuyong/ernie-health-zh/resolve/main/config.json''',
}




class  _UpperCAmelCase       (			lowerCAmelCase   ):



 '''simple docstring'''




 __A           = '''ernie'''







 def __init__(						self							:					Dict				,      lowercase_							:					List[Any]=30522				,      lowercase_							:					Optional[int]=768				,      lowercase_							:					Tuple=12				,      lowercase_							:					Optional[int]=12				,      lowercase_							:					Any=3072				,      lowercase_							:					int="gelu"				,      lowercase_							:					List[Any]=0.1				,      lowercase_							:					Any=0.1				,      lowercase_							:					str=512				,      lowercase_							:					Any=2				,      lowercase_							:					Any=3				,      lowercase_							:					List[Any]=False				,      lowercase_							:					List[Any]=0.02				,      lowercase_							:					str=1e-1_2				,      lowercase_							:					int=0				,      lowercase_							:					str="absolute"				,      lowercase_							:					Dict=True				,      lowercase_							:					List[str]=None				,      **lowercase_							:					Dict				,      )		->     Union[str, Any]:


   """simple docstring"""







   super().__init__(pad_token_id=lowercase_				,      **lowercase_)

   _UpperCamelCase				=  vocab_size
   _UpperCamelCase				=  hidden_size
   _UpperCamelCase				=  num_hidden_layers
   _UpperCamelCase				=  num_attention_heads
   _UpperCamelCase				=  hidden_act
   _UpperCamelCase				=  intermediate_size
   _UpperCamelCase				=  hidden_dropout_prob
   _UpperCamelCase				=  attention_probs_dropout_prob
   _UpperCamelCase				=  max_position_embeddings
   _UpperCamelCase				=  type_vocab_size
   _UpperCamelCase				=  task_type_vocab_size
   _UpperCamelCase				=  use_task_id
   _UpperCamelCase				=  initializer_range
   _UpperCamelCase				=  layer_norm_eps
   _UpperCamelCase				=  position_embedding_type
   _UpperCamelCase				=  use_cache
   _UpperCamelCase				=  classifier_dropout




class  _UpperCAmelCase       (			lowerCAmelCase   ):



 '''simple docstring'''




 @property
 def 						__UpperCAmelCase							(						self							:					Optional[int])		->     Mapping[str, Mapping[int, str]]:


   """simple docstring"""







   if self.task == "multiple-choice":
     _UpperCamelCase				=  {0: "batch", 1: "choice", 2: "sequence"}
   else:
     _UpperCamelCase				=  {0: "batch", 1: "sequence"}
   return OrderedDict(
       [
           ("input_ids", dynamic_axis),
           ("attention_mask", dynamic_axis),
           ("token_type_ids", dynamic_axis),
           ("task_type_ids", dynamic_axis),
       ])




