
"""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, prepare_video_inputs


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import VideoMAEImageProcessor







class 	lowerCamelCase__      (      unittest.TestCase       ):





			'''simple docstring'''



			def __init__(							self  ,  __UpperCAmelCase  ,  __UpperCAmelCase=7  ,  __UpperCAmelCase=3  ,  __UpperCAmelCase=10  ,  __UpperCAmelCase=18  ,  __UpperCAmelCase=30  ,  __UpperCAmelCase=4_00  ,  __UpperCAmelCase=True  ,  __UpperCAmelCase=None  ,  __UpperCAmelCase=True  ,  __UpperCAmelCase=[0.5, 0.5, 0.5]  ,  __UpperCAmelCase=[0.5, 0.5, 0.5]  ,  __UpperCAmelCase=None  ,  )				->  Union[str, Any]:
				_lowerCAmelCase			=size if size is not None else {"""shortest_edge""": 18}
				_lowerCAmelCase			=crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

				_lowerCAmelCase			=parent
				_lowerCAmelCase			=batch_size
				_lowerCAmelCase			=num_channels
				_lowerCAmelCase			=num_frames
				_lowerCAmelCase			=image_size
				_lowerCAmelCase			=min_resolution
				_lowerCAmelCase			=max_resolution
				_lowerCAmelCase			=do_resize
				_lowerCAmelCase			=size
				_lowerCAmelCase			=do_normalize
				_lowerCAmelCase			=image_mean
				_lowerCAmelCase			=image_std
				_lowerCAmelCase			=crop_size



			def       _lowerCAmelCase	(							self						)				->  Dict:
				return {
				    "image_mean": self.image_mean,
				    "image_std": self.image_std,
				    "do_normalize": self.do_normalize,
				    "do_resize": self.do_resize,
				    "size": self.size,
				    "crop_size": self.crop_size,
				}







@require_torch
@require_vision
class 	lowerCamelCase__      (      __magic_name__				,			unittest.TestCase       ):





			'''simple docstring'''
			lowerCamelCase						      =	VideoMAEImageProcessor if is_vision_available() else None



			def       _lowerCAmelCase	(							self						)				->  Optional[int]:
				_lowerCAmelCase			=VideoMAEImageProcessingTester(self						)



			@property
			def       _lowerCAmelCase	(							self						)				->  Optional[Any]:
				return self.image_processor_tester.prepare_image_processor_dict()



			def       _lowerCAmelCase	(							self						)				->  Optional[Any]:
				_lowerCAmelCase			=self.image_processing_class(**self.image_processor_dict						)
				self.assertTrue(hasattr(__UpperCAmelCase  ,  """image_mean"""						)						)
				self.assertTrue(hasattr(__UpperCAmelCase  ,  """image_std"""						)						)
				self.assertTrue(hasattr(__UpperCAmelCase  ,  """do_normalize"""						)						)
				self.assertTrue(hasattr(__UpperCAmelCase  ,  """do_resize"""						)						)
				self.assertTrue(hasattr(__UpperCAmelCase  ,  """do_center_crop"""						)						)
				self.assertTrue(hasattr(__UpperCAmelCase  ,  """size"""						)						)



			def       _lowerCAmelCase	(							self						)				->  Union[str, Any]:
				_lowerCAmelCase			=self.image_processing_class.from_dict(self.image_processor_dict						)
				self.assertEqual(image_processor.size  ,  {"""shortest_edge""": 18}						)
				self.assertEqual(image_processor.crop_size  ,  {"""height""": 18, """width""": 18}						)

				_lowerCAmelCase			=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       _lowerCAmelCase	(							self						)				->  List[Any]:
				pass



			def       _lowerCAmelCase	(							self						)				->  Any:
				# Initialize image_processing
				_lowerCAmelCase			=self.image_processing_class(**self.image_processor_dict						)
				# create random PIL videos
				_lowerCAmelCase			=prepare_video_inputs(self.image_processor_tester  ,  equal_resolution=__UpperCAmelCase						)
				for video in video_inputs:
					self.assertIsInstance(__UpperCAmelCase  ,  __UpperCAmelCase						)
					self.assertIsInstance(video[0]  ,  Image.Image						)

				# Test not batched input
				_lowerCAmelCase			=image_processing(video_inputs[0]  ,  return_tensors="""pt"""						).pixel_values
				self.assertEqual(
				    encoded_videos.shape  ,  (
				        1,
				        self.image_processor_tester.num_frames,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size["""height"""],
				        self.image_processor_tester.crop_size["""width"""],
				    )  ,  )

				# Test batched
				_lowerCAmelCase			=image_processing(__UpperCAmelCase  ,  return_tensors="""pt"""						).pixel_values
				self.assertEqual(
				    encoded_videos.shape  ,  (
				        self.image_processor_tester.batch_size,
				        self.image_processor_tester.num_frames,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size["""height"""],
				        self.image_processor_tester.crop_size["""width"""],
				    )  ,  )



			def       _lowerCAmelCase	(							self						)				->  Dict:
				# Initialize image_processing
				_lowerCAmelCase			=self.image_processing_class(**self.image_processor_dict						)
				# create random numpy tensors
				_lowerCAmelCase			=prepare_video_inputs(self.image_processor_tester  ,  equal_resolution=__UpperCAmelCase  ,  numpify=__UpperCAmelCase						)
				for video in video_inputs:
					self.assertIsInstance(__UpperCAmelCase  ,  __UpperCAmelCase						)
					self.assertIsInstance(video[0]  ,  np.ndarray						)

				# Test not batched input
				_lowerCAmelCase			=image_processing(video_inputs[0]  ,  return_tensors="""pt"""						).pixel_values
				self.assertEqual(
				    encoded_videos.shape  ,  (
				        1,
				        self.image_processor_tester.num_frames,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size["""height"""],
				        self.image_processor_tester.crop_size["""width"""],
				    )  ,  )

				# Test batched
				_lowerCAmelCase			=image_processing(__UpperCAmelCase  ,  return_tensors="""pt"""						).pixel_values
				self.assertEqual(
				    encoded_videos.shape  ,  (
				        self.image_processor_tester.batch_size,
				        self.image_processor_tester.num_frames,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size["""height"""],
				        self.image_processor_tester.crop_size["""width"""],
				    )  ,  )



			def       _lowerCAmelCase	(							self						)				->  Dict:
				# Initialize image_processing
				_lowerCAmelCase			=self.image_processing_class(**self.image_processor_dict						)
				# create random PyTorch tensors
				_lowerCAmelCase			=prepare_video_inputs(self.image_processor_tester  ,  equal_resolution=__UpperCAmelCase  ,  torchify=__UpperCAmelCase						)
				for video in video_inputs:
					self.assertIsInstance(__UpperCAmelCase  ,  __UpperCAmelCase						)
					self.assertIsInstance(video[0]  ,  torch.Tensor						)

				# Test not batched input
				_lowerCAmelCase			=image_processing(video_inputs[0]  ,  return_tensors="""pt"""						).pixel_values
				self.assertEqual(
				    encoded_videos.shape  ,  (
				        1,
				        self.image_processor_tester.num_frames,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size["""height"""],
				        self.image_processor_tester.crop_size["""width"""],
				    )  ,  )

				# Test batched
				_lowerCAmelCase			=image_processing(__UpperCAmelCase  ,  return_tensors="""pt"""						).pixel_values
				self.assertEqual(
				    encoded_videos.shape  ,  (
				        self.image_processor_tester.batch_size,
				        self.image_processor_tester.num_frames,
				        self.image_processor_tester.num_channels,
				        self.image_processor_tester.crop_size["""height"""],
				        self.image_processor_tester.crop_size["""width"""],
				    )  ,  )





"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

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


__A 		= logging.get_logger(__name__)

__A 		= {
    '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 	lowerCamelCase__      (      __magic_name__       ):





			'''simple docstring'''
			lowerCamelCase						      =	'''ernie'''



			def __init__(							self  ,  __UpperCAmelCase=3_05_22  ,  __UpperCAmelCase=7_68  ,  __UpperCAmelCase=12  ,  __UpperCAmelCase=12  ,  __UpperCAmelCase=30_72  ,  __UpperCAmelCase="gelu"  ,  __UpperCAmelCase=0.1  ,  __UpperCAmelCase=0.1  ,  __UpperCAmelCase=5_12  ,  __UpperCAmelCase=2  ,  __UpperCAmelCase=3  ,  __UpperCAmelCase=False  ,  __UpperCAmelCase=0.0_2  ,  __UpperCAmelCase=1e-12  ,  __UpperCAmelCase=0  ,  __UpperCAmelCase="absolute"  ,  __UpperCAmelCase=True  ,  __UpperCAmelCase=None  ,  **__UpperCAmelCase  ,  )				->  str:
				super().__init__(pad_token_id=__UpperCAmelCase  ,  **__UpperCAmelCase						)

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







class 	lowerCamelCase__      (      __magic_name__       ):





			'''simple docstring'''



			@property
			def       _lowerCAmelCase	(							self						)				->  Mapping[str, Mapping[int, str]]:
				if self.task == "multiple-choice":
					_lowerCAmelCase			={0: """batch""", 1: """choice""", 2: """sequence"""}
				else:
					_lowerCAmelCase			={0: """batch""", 1: """sequence"""}
				return OrderedDict(
				    [
				        ("""input_ids""", dynamic_axis),
				        ("""attention_mask""", dynamic_axis),
				        ("""token_type_ids""", dynamic_axis),
				        ("""task_type_ids""", dynamic_axis),
				    ]						)



