code: 
  
  
  '''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
  
  
  if is_torch_available():
   import torch
  
  if is_vision_available():
   from PIL import Image
  
   from transformers import CLIPImageProcessor
  class 						__lowerCAmelCase		(unittest.TestCase  ):
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def __init__(self					:					int     ,		UpperCamelCase					:					Dict     ,		UpperCamelCase					:					Optional[int]=7     ,		UpperCamelCase					:					str=3     ,		UpperCamelCase					:					List[str]=18     ,		UpperCamelCase					:					str=30     ,		UpperCamelCase					:					Any=400     ,		UpperCamelCase					:					Any=True     ,		UpperCamelCase					:					List[Any]=None     ,		UpperCamelCase					:					Any=True     ,		UpperCamelCase					:					Optional[Any]=None     ,		UpperCamelCase					:					List[str]=True     ,		UpperCamelCase					:					Any=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]     ,		UpperCamelCase					:					Union[str, Any]=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]     ,		UpperCamelCase					:					int=True     ,		):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				size if size is not None else {'''shortest_edge''': 20}
               lowercase__       =				crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
               lowercase__       =				parent
               lowercase__       =				batch_size
               lowercase__       =				num_channels
               lowercase__       =				image_size
               lowercase__       =				min_resolution
               lowercase__       =				max_resolution
               lowercase__       =				do_resize
               lowercase__       =				size
               lowercase__       =				do_center_crop
               lowercase__       =				crop_size
               lowercase__       =				do_normalize
               lowercase__       =				image_mean
               lowercase__       =				image_std
               lowercase__       =				do_convert_rgb
  
  
  
        def    UpperCamelCase__	(self					:					List[Any]				):
  
               '''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,
               }
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					List[str]     ,		UpperCamelCase					:					List[Any]=False     ,		UpperCamelCase					:					List[str]=False     ,		UpperCamelCase					:					Optional[int]=False				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
               if equal_resolution:
                      lowercase__       =				[]
                      for i in range(self.batch_size				):
                             image_inputs.append(
                                 np.random.randint(
                                     255     ,		size=(self.num_channels, self.max_resolution, self.max_resolution)     ,		dtype=np.uinta				)				)
               else:
                      lowercase__       =				[]
                      for i in range(self.batch_size				):
                             lowercase__    ,lowercase__       =				np.random.choice(np.arange(self.min_resolution     ,		self.max_resolution				)     ,		2				)
                             image_inputs.append(np.random.randint(255     ,		size=(self.num_channels, width, height)     ,		dtype=np.uinta				)				)
  
               if not numpify and not torchify:
                      # PIL expects the channel dimension as last dimension
                      lowercase__       =				[Image.fromarray(np.moveaxis(UpperCamelCase     ,		0     ,		-1				)				) for x in image_inputs]
  
               if torchify:
                      lowercase__       =				[torch.from_numpy(UpperCamelCase				) for x in image_inputs]
  
               return image_inputs
  
  
  
  
  
  
  @require_torch
  @require_vision
  class 						__lowerCAmelCase		(lowercase_						,  unittest.TestCase  ):
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        lowerCAmelCase__      :  Optional[int]						      =							CLIPImageProcessor if is_vision_available() else None
  
  
  
        def    UpperCamelCase__	(self					:					Tuple				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				CLIPImageProcessingTester(self				)
  
  
  
        @property
        def    UpperCamelCase__	(self					:					Optional[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
        def    UpperCamelCase__	(self					:					List[str]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.image_processing_class(**self.image_processor_dict				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''do_resize'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''size'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''do_center_crop'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''center_crop'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''do_normalize'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''image_mean'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''image_std'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''do_convert_rgb'''				)				)
  
  
  
        def    UpperCamelCase__	(self					:					Optional[int]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.image_processing_class.from_dict(self.image_processor_dict				)
               self.assertEqual(image_processor.size     ,		{'''shortest_edge''': 20}				)
               self.assertEqual(image_processor.crop_size     ,		{'''height''': 18, '''width''': 18}				)
  
               lowercase__       =				self.image_processing_class.from_dict(self.image_processor_dict     ,		size=42     ,		crop_size=84				)
               self.assertEqual(image_processor.size     ,		{'''shortest_edge''': 42}				)
               self.assertEqual(image_processor.crop_size     ,		{'''height''': 84, '''width''': 84}				)
  
  
  
        def    UpperCamelCase__	(self					:					List[str]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               pass
  
  
  
        def    UpperCamelCase__	(self					:					Any				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.image_processing_class(**self.image_processor_dict				)
               # create random PIL images
               lowercase__       =				self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase				)
               for image in image_inputs:
                      self.assertIsInstance(UpperCamelCase     ,		Image.Image				)
  
               # Test not batched input
               lowercase__       =				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
               lowercase__       =				image_processing(UpperCamelCase     ,		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]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.image_processing_class(**self.image_processor_dict				)
               # create random numpy tensors
               lowercase__       =				self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase     ,		numpify=UpperCamelCase				)
               for image in image_inputs:
                      self.assertIsInstance(UpperCamelCase     ,		np.ndarray				)
  
               # Test not batched input
               lowercase__       =				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
               lowercase__       =				image_processing(UpperCamelCase     ,		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'''
  
  
  
  
  
  
  
               lowercase__       =				self.image_processing_class(**self.image_processor_dict				)
               # create random PyTorch tensors
               lowercase__       =				self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase     ,		torchify=UpperCamelCase				)
               for image in image_inputs:
                      self.assertIsInstance(UpperCamelCase     ,		torch.Tensor				)
  
               # Test not batched input
               lowercase__       =				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
               lowercase__       =				image_processing(UpperCamelCase     ,		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'''],
                   )     ,		)
  
  
  
  
  
  
  @require_torch
  @require_vision
  class 						__lowerCAmelCase		(lowercase_						,  unittest.TestCase  ):
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        lowerCAmelCase__      :  str						      =							CLIPImageProcessor if is_vision_available() else None
  
  
  
        def    UpperCamelCase__	(self					:					Any				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				CLIPImageProcessingTester(self     ,		num_channels=4				)
               lowercase__       =				3
  
  
  
        @property
        def    UpperCamelCase__	(self					:					int				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
        def    UpperCamelCase__	(self					:					str				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.image_processing_class(**self.image_processor_dict				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''do_resize'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''size'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''do_center_crop'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''center_crop'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''do_normalize'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''image_mean'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''image_std'''				)				)
               self.assertTrue(hasattr(UpperCamelCase     ,		'''do_convert_rgb'''				)				)
  
  
  
        def    UpperCamelCase__	(self					:					int				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               pass
  
  
  
  
  
  
        def    UpperCamelCase__	(self					:					str				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				self.image_processing_class(**self.image_processor_dict				)
               # create random PIL images
               lowercase__       =				self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase				)
               for image in image_inputs:
                      self.assertIsInstance(UpperCamelCase     ,		Image.Image				)
  
               # Test not batched input
               lowercase__       =				image_processing(image_inputs[0]     ,		return_tensors='''pt'''				).pixel_values
               self.assertEqual(
                   encoded_images.shape     ,		(
                       1,
                       self.expected_encoded_image_num_channels,
                       self.image_processor_tester.crop_size['''height'''],
                       self.image_processor_tester.crop_size['''width'''],
                   )     ,		)
  
               # Test batched
               lowercase__       =				image_processing(UpperCamelCase     ,		return_tensors='''pt'''				).pixel_values
               self.assertEqual(
                   encoded_images.shape     ,		(
                       self.image_processor_tester.batch_size,
                       self.expected_encoded_image_num_channels,
                       self.image_processor_tester.crop_size['''height'''],
                       self.image_processor_tester.crop_size['''width'''],
                   )     ,		)
  
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  import argparse
  
  import torch
  
  from transformers import ElectraConfig, ElectraForMaskedLM, ElectraForPreTraining, load_tf_weights_in_electra
  from transformers.utils import logging
  
  
  logging.set_verbosity_info()
  
  def _SCREAMING_SNAKE_CASE   (A						,				A						,				A						,				A ) -> Dict:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         lowercase__       =				ElectraConfig.from_json_file(A )
         print(f"Building PyTorch model from configuration: {config}" )
  
         if discriminator_or_generator == "discriminator":
                lowercase__       =				ElectraForPreTraining(A )
         elif discriminator_or_generator == "generator":
                lowercase__       =				ElectraForMaskedLM(A )
         else:
                raise ValueError('''The discriminator_or_generator argument should be either \'discriminator\' or \'generator\'''' )
  
         # Load weights from tf checkpoint
         load_tf_weights_in_electra(
             A						,				A						,				A						,				discriminator_or_generator=A )
  
         # Save pytorch-model
         print(f"Save PyTorch model to {pytorch_dump_path}" )
         torch.save(model.state_dict()						,				A )
  
  
  if __name__ == "__main__":
   lowerCamelCase							:     Tuple								=			argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       '--tf_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
   )
   parser.add_argument(
       '--config_file',
       default=None,
       type=str,
       required=True,
       help='The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.',
   )
   parser.add_argument(
       '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
   )
   parser.add_argument(
       '--discriminator_or_generator',
       default=None,
       type=str,
       required=True,
       help=(
           'Whether to export the generator or the discriminator. Should be a string, either \'discriminator\' or '
           '\'generator\'.'
       ),
   )
   lowerCamelCase							:     Optional[int]								=			parser.parse_args()
   convert_tf_checkpoint_to_pytorch(
       args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.discriminator_or_generator
   )
  
  
  
  
  