


"""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 ChineseCLIPImageProcessor






class 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    def __init__(					self				:    Optional[Any]				, __UpperCAmelCase				:    Dict				, __UpperCAmelCase				:    str=7				, __UpperCAmelCase				:    str=3				, __UpperCAmelCase				:    Tuple=18				, __UpperCAmelCase				:    Dict=30				, __UpperCAmelCase				:    Any=400				, __UpperCAmelCase				:    List[Any]=True				, __UpperCAmelCase				:    Dict=None				, __UpperCAmelCase				:    Any=True				, __UpperCAmelCase				:    Optional[Any]=None				, __UpperCAmelCase				:    Tuple=True				, __UpperCAmelCase				:    Tuple=[0.48_145_466, 0.4_578_275, 0.40_821_073]				, __UpperCAmelCase				:    Optional[Any]=[0.26_862_954, 0.26_130_258, 0.27_577_711]				, __UpperCAmelCase				:    Union[str, Any]=True				, ):
      a						:		int      							=			size if size is not None else {"height": 224, "width": 224}
      a						:		List[str]      							=			crop_size if crop_size is not None else {"height": 18, "width": 18}
      a						:		List[Any]      							=			parent
      a						:		Any      							=			batch_size
      a						:		str      							=			num_channels
      a						:		Optional[int]      							=			image_size
      a						:		Tuple      							=			min_resolution
      a						:		str      							=			max_resolution
      a						:		Dict      							=			do_resize
      a						:		Any      							=			size
      a						:		Dict      							=			do_center_crop
      a						:		List[str]      							=			crop_size
      a						:		str      							=			do_normalize
      a						:		Optional[int]      							=			image_mean
      a						:		Tuple      							=			image_std
      a						:		Any      							=			do_convert_rgb






    def 	__snake_case							(					self				:    Union[str, Any]):
      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 	__snake_case							(					self				:    Dict				, __UpperCAmelCase				:    Optional[Any]=False				, __UpperCAmelCase				:    List[Any]=False				, __UpperCAmelCase				:    Any=False):
      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

      if equal_resolution:
        a						:		str      							=			[]
        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:
        a						:		Tuple      							=			[]
        for i in range(self.batch_size):
          a							,		a						:		List[str]      							=			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
        a						:		List[Any]      							=			[Image.fromarray(np.moveaxis(__UpperCAmelCase				, 0				, -1)) for x in image_inputs]

      if torchify:
        a						:		Optional[Any]      							=			[torch.from_numpy(__UpperCAmelCase) for x in image_inputs]

      return image_inputs






@require_torch
@require_vision
class 						_A  (  _a    ,unittest.TestCase  ):







    """simple docstring"""




    UpperCAmelCase       :							Union[str, Any]	=       ChineseCLIPImageProcessor if is_vision_available() else None






    def 	__snake_case							(					self				:    List[str]):
      a						:		Dict      							=			ChineseCLIPImageProcessingTester(self				, do_center_crop=__UpperCAmelCase)






    @property
    def 	__snake_case							(					self				:    Union[str, Any]):
      return self.image_processor_tester.prepare_image_processor_dict()






    def 	__snake_case							(					self				:    str):
      a						:		Optional[int]      							=			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 	__snake_case							(					self				:    Any):
      a						:		Union[str, Any]      							=			self.image_processing_class.from_dict(self.image_processor_dict)
      self.assertEqual(image_processor.size				, {"height": 224, "width": 224})
      self.assertEqual(image_processor.crop_size				, {"height": 18, "width": 18})

      a						:		int      							=			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 	__snake_case							(					self				:    str):
      pass






    def 	__snake_case							(					self				:    Tuple):
      # Initialize image_processing
      a						:		Union[str, Any]      							=			self.image_processing_class(**self.image_processor_dict)
      # create random PIL images
      a						:		Any      							=			self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase)
      for image in image_inputs:
        self.assertIsInstance(__UpperCAmelCase				, Image.Image)

      # Test not batched input
      a						:		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
      a						:		Dict      							=			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 	__snake_case							(					self				:    List[Any]):
      # Initialize image_processing
      a						:		str      							=			self.image_processing_class(**self.image_processor_dict)
      # create random numpy tensors
      a						:		Any      							=			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
      a						:		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
      a						:		Union[str, Any]      							=			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 	__snake_case							(					self				:    List[str]):
      # Initialize image_processing
      a						:		str      							=			self.image_processing_class(**self.image_processor_dict)
      # create random PyTorch tensors
      a						:		Tuple      							=			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
      a						:		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
      a						:		str      							=			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 						_A  (  _a    ,unittest.TestCase  ):







    """simple docstring"""




    UpperCAmelCase       :							Optional[int]	=       ChineseCLIPImageProcessor if is_vision_available() else None






    def 	__snake_case							(					self				:    Union[str, Any]):
      a						:		str      							=			ChineseCLIPImageProcessingTester(self				, num_channels=4				, do_center_crop=__UpperCAmelCase)
      a						:		Dict      							=			3






    @property
    def 	__snake_case							(					self				:    Optional[Any]):
      return self.image_processor_tester.prepare_image_processor_dict()






    def 	__snake_case							(					self				:    Optional[int]):
      a						:		Tuple      							=			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 	__snake_case							(					self				:    Any):
      pass






    def 	__snake_case							(					self				:    Union[str, Any]):
      # Initialize image_processing
      a						:		List[Any]      							=			self.image_processing_class(**self.image_processor_dict)
      # create random PIL images
      a						:		str      							=			self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase)
      for image in image_inputs:
        self.assertIsInstance(__UpperCAmelCase				, Image.Image)

      # Test not batched input
      a						:		Tuple      							=			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
      a						:		Optional[Any]      							=			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"],
          )				, )










'''simple docstring'''
from collections import OrderedDict
from typing import Mapping

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


__snake_case							      =     logging.get_logger(__name__)

__snake_case							      =     {
    '''camembert-base''': '''https://huggingface.co/camembert-base/resolve/main/config.json''',
    '''umberto-commoncrawl-cased-v1''': (
        '''https://huggingface.co/Musixmatch/umberto-commoncrawl-cased-v1/resolve/main/config.json'''
    ),
    '''umberto-wikipedia-uncased-v1''': (
        '''https://huggingface.co/Musixmatch/umberto-wikipedia-uncased-v1/resolve/main/config.json'''
    ),
}
class    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				'camembert'




		def __init__(		self    ,   UpperCamelCase_=30522    ,   UpperCamelCase_=768    ,   UpperCamelCase_=12    ,   UpperCamelCase_=12    ,   UpperCamelCase_=3072    ,   UpperCamelCase_="gelu"    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=512    ,   UpperCamelCase_=2    ,   UpperCamelCase_=0.02    ,   UpperCamelCase_=1e-12    ,   UpperCamelCase_=1    ,   UpperCamelCase_=0    ,   UpperCamelCase_=2    ,   UpperCamelCase_="absolute"    ,   UpperCamelCase_=True    ,   UpperCamelCase_=None    ,   **UpperCamelCase_    ,   ):

							'''simple docstring'''


							super().__init__(pad_token_id=UpperCamelCase_    ,   bos_token_id=UpperCamelCase_    ,   eos_token_id=UpperCamelCase_    ,   **UpperCamelCase_							)

							UpperCamelCase__   :int												= vocab_size
							UpperCamelCase__   :Optional[int]												= hidden_size
							UpperCamelCase__   :Optional[int]												= num_hidden_layers
							UpperCamelCase__   :List[Any]												= num_attention_heads
							UpperCamelCase__   :Union[str, Any]												= hidden_act
							UpperCamelCase__   :List[Any]												= intermediate_size
							UpperCamelCase__   :int												= hidden_dropout_prob
							UpperCamelCase__   :Tuple												= attention_probs_dropout_prob
							UpperCamelCase__   :Union[str, Any]												= max_position_embeddings
							UpperCamelCase__   :Tuple												= type_vocab_size
							UpperCamelCase__   :int												= initializer_range
							UpperCamelCase__   :List[str]												= layer_norm_eps
							UpperCamelCase__   :int												= position_embedding_type
							UpperCamelCase__   :Any												= use_cache
							UpperCamelCase__   :Any												= classifier_dropout



class    lowercase	(							A__					):

		"""simple docstring"""

		@property
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							if self.task == "multiple-choice":
												UpperCamelCase__   :List[str]												= {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
							else:
												UpperCamelCase__   :Tuple												= {0: '''batch''', 1: '''sequence'''}
							return OrderedDict(
							    [
							        ('''input_ids''', dynamic_axis),
							        ('''attention_mask''', dynamic_axis),
							    ]							)