






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







     '''simple docstring'''




     def __init__( self				:	Optional[Any]       ,		UpperCamelCase_				:	List[Any]       ,		UpperCamelCase_				:	int=7       ,		UpperCamelCase_				:	Tuple=3       ,		UpperCamelCase_				:	Tuple=18       ,		UpperCamelCase_				:	Dict=30       ,		UpperCamelCase_				:	Dict=400       ,		UpperCamelCase_				:	int=True       ,		UpperCamelCase_				:	List[str]=None       ,		UpperCamelCase_				:	Optional[Any]=True       ,		UpperCamelCase_				:	List[Any]=None       ,		UpperCamelCase_				:	Tuple=True       ,		UpperCamelCase_				:	int=[0.48145466, 0.4578275, 0.40821073]       ,		UpperCamelCase_				:	List[Any]=[0.26862954, 0.26130258, 0.27577711]       ,		UpperCamelCase_				:	List[str]=True       ,		):


         """simple docstring"""



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





     def 						lowerCAmelCase_   ( self				:	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 					__lowercase					(		lowercase_	,					unittest.TestCase     ):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE        = OwlViTImageProcessor if is_vision_available() else None




     def 						lowerCAmelCase_   ( self				:	List[str] ):


         """simple docstring"""



         __A   			=		OwlViTImageProcessingTester(self )




     @property
     def 						lowerCAmelCase_   ( self				:	Optional[Any] ):


         """simple docstring"""



         return self.image_processor_tester.prepare_image_processor_dict()




     def 						lowerCAmelCase_   ( self				:	Tuple ):


         """simple docstring"""



         __A   			=		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 						lowerCAmelCase_   ( self				:	Optional[Any] ):


         """simple docstring"""



         __A   			=		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} )

         __A   			=		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 						lowerCAmelCase_   ( self				:	Dict ):


         """simple docstring"""



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

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

         # Test not batched input
         __A   			=		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
         __A   			=		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 						lowerCAmelCase_   ( self				:	List[str] ):


         """simple docstring"""



         __A   			=		self.image_processing_class(**self.image_processor_dict )
         # create random numpy tensors
         __A   			=		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
         __A   			=		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
         __A   			=		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 						lowerCAmelCase_   ( self				:	int ):


         """simple docstring"""



         __A   			=		self.image_processing_class(**self.image_processor_dict )
         # create random PyTorch tensors
         __A   			=		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
         __A   			=		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
         __A   			=		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),
       ])




