



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



   def __init__( self       :							Optional[Any]      ,  _lowercase       :							int      ,  _lowercase       :							Optional[int]=7      ,  _lowercase       :							Any=3      ,  _lowercase       :							List[Any]=18      ,  _lowercase       :							Optional[Any]=30      ,  _lowercase       :							List[Any]=400      ,  _lowercase       :							Union[str, Any]=True      ,  _lowercase       :							Union[str, Any]=None      ,  _lowercase       :							Union[str, Any]=True      ,  _lowercase       :							List[Any]=None      ,  _lowercase       :							Any=True      ,  _lowercase       :							List[Any]=[0.48145466, 0.4578275, 0.40821073]      ,  _lowercase       :							Optional[int]=[0.26862954, 0.26130258, 0.27577711]      ,  _lowercase       :							List[str]=True      ,  )       ->				Optional[Any]:
         snake_case      : List[str]							=   size if size is not None else {"shortest_edge": 20}
         snake_case      : List[Any]							=   crop_size if crop_size is not None else {"height": 18, "width": 18}
         snake_case      : List[Any]							=   parent
         snake_case      : List[Any]							=   batch_size
         snake_case      : List[str]							=   num_channels
         snake_case      : str							=   image_size
         snake_case      : str							=   min_resolution
         snake_case      : List[Any]							=   max_resolution
         snake_case      : Optional[int]							=   do_resize
         snake_case      : List[Any]							=   size
         snake_case      : Optional[Any]							=   do_center_crop
         snake_case      : List[str]							=   crop_size
         snake_case      : Union[str, Any]							=   do_normalize
         snake_case      : Tuple							=   image_mean
         snake_case      : str							=   image_std
         snake_case      : List[Any]							=   do_convert_rgb



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

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

         if torchify:
               snake_case      : Dict							=   [torch.from_numpy(_lowerCAmelCase		) for x in image_inputs]

         return image_inputs



@require_torch
@require_vision
class 			_a     (   A__    ,  unittest.TestCase):
   __magic_name__    				=    CLIPImageProcessor if is_vision_available() else None



   def 							__lowercase				( self       :							Optional[int]		)       ->				Union[str, Any]:
         snake_case      : List[Any]							=   CLIPImageProcessingTester(self		)



   @property
   def 							__lowercase				( self       :							str		)       ->				List[Any]:
         return self.image_processor_tester.prepare_image_processor_dict()



   def 							__lowercase				( self       :							int		)       ->				Dict:
         snake_case      : Tuple							=   self.image_processing_class(**self.image_processor_dict		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "do_resize"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "size"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "do_center_crop"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "center_crop"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "do_normalize"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "image_mean"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "image_std"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "do_convert_rgb"		)		)



   def 							__lowercase				( self       :							Dict		)       ->				Optional[int]:
         snake_case      : List[Any]							=   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}		)

         snake_case      : Any							=   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 							__lowercase				( self       :							Any		)       ->				str:
         pass



   def 							__lowercase				( self       :							Optional[Any]		)       ->				Union[str, Any]:
         # Initialize image_processing
         snake_case      : int							=   self.image_processing_class(**self.image_processor_dict		)
         # create random PIL images
         snake_case      : int							=   self.image_processor_tester.prepare_inputs(equal_resolution=_lowerCAmelCase		)
         for image in image_inputs:
               self.assertIsInstance(_lowerCAmelCase      ,  Image.Image		)

         # Test not batched input
         snake_case      : 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
         snake_case      : Tuple							=   image_processing(_lowerCAmelCase      ,  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 							__lowercase				( self       :							List[Any]		)       ->				Dict:
         # Initialize image_processing
         snake_case      : Dict							=   self.image_processing_class(**self.image_processor_dict		)
         # create random numpy tensors
         snake_case      : Optional[Any]							=   self.image_processor_tester.prepare_inputs(equal_resolution=_lowerCAmelCase      ,  numpify=_lowerCAmelCase		)
         for image in image_inputs:
               self.assertIsInstance(_lowerCAmelCase      ,  np.ndarray		)

         # Test not batched input
         snake_case      : 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
         snake_case      : List[str]							=   image_processing(_lowerCAmelCase      ,  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 							__lowercase				( self       :							Tuple		)       ->				Tuple:
         # Initialize image_processing
         snake_case      : Optional[int]							=   self.image_processing_class(**self.image_processor_dict		)
         # create random PyTorch tensors
         snake_case      : Union[str, Any]							=   self.image_processor_tester.prepare_inputs(equal_resolution=_lowerCAmelCase      ,  torchify=_lowerCAmelCase		)
         for image in image_inputs:
               self.assertIsInstance(_lowerCAmelCase      ,  torch.Tensor		)

         # Test not batched input
         snake_case      : 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
         snake_case      : int							=   image_processing(_lowerCAmelCase      ,  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):
   __magic_name__    				=    CLIPImageProcessor if is_vision_available() else None



   def 							__lowercase				( self       :							int		)       ->				List[str]:
         snake_case      : List[str]							=   CLIPImageProcessingTester(self      ,  num_channels=4		)
         snake_case      : List[Any]							=   3



   @property
   def 							__lowercase				( self       :							Tuple		)       ->				Dict:
         return self.image_processor_tester.prepare_image_processor_dict()



   def 							__lowercase				( self       :							List[Any]		)       ->				Dict:
         snake_case      : Optional[int]							=   self.image_processing_class(**self.image_processor_dict		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "do_resize"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "size"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "do_center_crop"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "center_crop"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "do_normalize"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "image_mean"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "image_std"		)		)
         self.assertTrue(hasattr(_lowerCAmelCase      ,  "do_convert_rgb"		)		)



   def 							__lowercase				( self       :							Any		)       ->				List[str]:
         pass



   def 							__lowercase				( self       :							int		)       ->				Optional[int]:
         # Initialize image_processing
         snake_case      : List[Any]							=   self.image_processing_class(**self.image_processor_dict		)
         # create random PIL images
         snake_case      : List[str]							=   self.image_processor_tester.prepare_inputs(equal_resolution=_lowerCAmelCase		)
         for image in image_inputs:
               self.assertIsInstance(_lowerCAmelCase      ,  Image.Image		)

         # Test not batched input
         snake_case      : List[str]							=   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
         snake_case      : Any							=   image_processing(_lowerCAmelCase      ,  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 typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


A    =	{
    'configuration_camembert': ['CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CamembertConfig', 'CamembertOnnxConfig'],
}

try:
			if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			A    =	['CamembertTokenizer']

try:
			if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			A    =	['CamembertTokenizerFast']

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			A    =	[
			    'CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
			    'CamembertForCausalLM',
			    'CamembertForMaskedLM',
			    'CamembertForMultipleChoice',
			    'CamembertForQuestionAnswering',
			    'CamembertForSequenceClassification',
			    'CamembertForTokenClassification',
			    'CamembertModel',
			    'CamembertPreTrainedModel',
			]

try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			A    =	[
			    'TF_CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
			    'TFCamembertForCausalLM',
			    'TFCamembertForMaskedLM',
			    'TFCamembertForMultipleChoice',
			    'TFCamembertForQuestionAnswering',
			    'TFCamembertForSequenceClassification',
			    'TFCamembertForTokenClassification',
			    'TFCamembertModel',
			    'TFCamembertPreTrainedModel',
			]


if TYPE_CHECKING:
			from .configuration_camembert import CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, CamembertConfig, CamembertOnnxConfig

			try:
						if not is_sentencepiece_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_camembert import CamembertTokenizer

			try:
						if not is_tokenizers_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_camembert_fast import CamembertTokenizerFast

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_camembert import (
						    CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    CamembertForCausalLM,
						    CamembertForMaskedLM,
						    CamembertForMultipleChoice,
						    CamembertForQuestionAnswering,
						    CamembertForSequenceClassification,
						    CamembertForTokenClassification,
						    CamembertModel,
						    CamembertPreTrainedModel,
						)

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_camembert import (
						    TF_CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFCamembertForCausalLM,
						    TFCamembertForMaskedLM,
						    TFCamembertForMultipleChoice,
						    TFCamembertForQuestionAnswering,
						    TFCamembertForSequenceClassification,
						    TFCamembertForTokenClassification,
						    TFCamembertModel,
						    TFCamembertPreTrainedModel,
						)

else:
			import sys

			A    =	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



