

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


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import ViTImageProcessor

class      __a							(unittest.TestCase):






     '''simple docstring'''

     def __init__(						self	,    _a	,    _a=13	,    _a=3	,    _a=224	,    _a=30	,    _a=400	,    _a=True	,    _a=None	,    _a=True	,    _a=[0.5, 0.5, 0.5]	,    _a=[0.5, 0.5, 0.5]	,    )  ->      Union[str, Any]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	size if size is not None else {"""height""": 18, """width""": 18}
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	parent
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	batch_size
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	num_channels
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	image_size
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	min_resolution
           SCREAMING_SNAKE_CASE__   :      Any      		=	max_resolution
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	do_resize
           SCREAMING_SNAKE_CASE__   :      int      		=	size
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	do_normalize
           SCREAMING_SNAKE_CASE__   :      Any      		=	image_mean
           SCREAMING_SNAKE_CASE__   :      str      		=	image_std





     def 					_a			(						self  )  ->      Optional[int]:


           """simple docstring"""


           return {
               "image_mean": self.image_mean,
               "image_std": self.image_std,
               "do_normalize": self.do_normalize,
               "do_resize": self.do_resize,
               "size": self.size,
           }





@require_torch
@require_vision
class      __a							(UpperCamelCase_   ,	unittest.TestCase):






     '''simple docstring'''
     _SCREAMING_SNAKE_CASE						:Dict       = ViTImageProcessor if is_vision_available() else None

     def 					_a			(						self  )  ->      Dict:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	EfficientFormerImageProcessorTester(self  )

     @property
     def 					_a			(						self  )  ->      List[str]:


           """simple docstring"""


           return self.image_proc_tester.prepare_image_processor_dict()

     def 					_a			(						self  )  ->      Union[str, Any]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      str      		=	self.image_processing_class(**self.image_processor_dict  )
           self.assertTrue(hasattr(_a	,    """image_mean"""  )  )
           self.assertTrue(hasattr(_a	,    """image_std"""  )  )
           self.assertTrue(hasattr(_a	,    """do_normalize"""  )  )
           self.assertTrue(hasattr(_a	,    """do_resize"""  )  )
           self.assertTrue(hasattr(_a	,    """size"""  )  )

     def 					_a			(						self  )  ->      Dict:


           """simple docstring"""


           pass

     def 					_a			(						self  )  ->      Dict:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	self.image_processing_class(**self.image_processor_dict  )
           # create random PIL images
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	prepare_image_inputs(self.image_proc_tester	,    equal_resolution=_a  )
           for image in image_inputs:
                 self.assertIsInstance(_a	,    Image.Image  )

           # Test not batched input
           SCREAMING_SNAKE_CASE__   :      int      		=	image_processor(image_inputs[0]	,    return_tensors="""pt"""  ).pixel_values
           self.assertEqual(
               encoded_images.shape	,    (
                   1,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["""height"""],
                   self.image_proc_tester.size["""width"""],
               )	,    )

           # Test batched
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	image_processor(_a	,    return_tensors="""pt"""  ).pixel_values
           self.assertEqual(
               encoded_images.shape	,    (
                   self.image_proc_tester.batch_size,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["""height"""],
                   self.image_proc_tester.size["""width"""],
               )	,    )

     def 					_a			(						self  )  ->      Any:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	self.image_processing_class(**self.image_processor_dict  )
           # create random numpy tensors
           SCREAMING_SNAKE_CASE__   :      Any      		=	prepare_image_inputs(self.image_proc_tester	,    equal_resolution=_a	,    numpify=_a  )
           for image in image_inputs:
                 self.assertIsInstance(_a	,    np.ndarray  )

           # Test not batched input
           SCREAMING_SNAKE_CASE__   :      int      		=	image_processor(image_inputs[0]	,    return_tensors="""pt"""  ).pixel_values
           self.assertEqual(
               encoded_images.shape	,    (
                   1,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["""height"""],
                   self.image_proc_tester.size["""width"""],
               )	,    )

           # Test batched
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	image_processor(_a	,    return_tensors="""pt"""  ).pixel_values
           self.assertEqual(
               encoded_images.shape	,    (
                   self.image_proc_tester.batch_size,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["""height"""],
                   self.image_proc_tester.size["""width"""],
               )	,    )





     def 					_a			(						self  )  ->      Dict:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      str      		=	self.image_processing_class(**self.image_processor_dict  )
           # create random PyTorch tensors
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	prepare_image_inputs(self.image_proc_tester	,    equal_resolution=_a	,    torchify=_a  )
           for image in image_inputs:
                 self.assertIsInstance(_a	,    torch.Tensor  )

           # Test not batched input
           SCREAMING_SNAKE_CASE__   :      str      		=	image_processor(image_inputs[0]	,    return_tensors="""pt"""  ).pixel_values
           self.assertEqual(
               encoded_images.shape	,    (
                   1,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["""height"""],
                   self.image_proc_tester.size["""width"""],
               )	,    )

           # Test batched
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	image_processor(_a	,    return_tensors="""pt"""  ).pixel_values
           self.assertEqual(
               encoded_images.shape	,    (
                   self.image_proc_tester.batch_size,
                   self.image_proc_tester.num_channels,
                   self.image_proc_tester.size["""height"""],
                   self.image_proc_tester.size["""width"""],
               )	,    )







"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow


if is_tf_available():
  import numpy as np
  import tensorflow as tf

  from transformers import TFCamembertModel

@require_tf
@require_sentencepiece
@require_tokenizers
class      __a							(unittest.TestCase):






     '''simple docstring'''

     @slow
     def 					_a			(						self  )  ->      Union[str, Any]:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	TFCamembertModel.from_pretrained("""jplu/tf-camembert-base"""  )

           SCREAMING_SNAKE_CASE__   :      Any      		=	tf.convert_to_tensor(
               [[5, 121, 11, 660, 16, 730, 25_543, 110, 83, 6]]	,    dtype=tf.intaa	,    )  # J'aime le camembert !"

           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	model(_a  )["""last_hidden_state"""]
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	tf.TensorShape((1, 10, 768)  )
           self.assertEqual(output.shape	,    _a  )
           # compare the actual values for a slice.
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	tf.convert_to_tensor(
               [[[-0.0_254, 0.0_235, 0.1_027], [0.0_606, -0.1_811, -0.0_418], [-0.1_561, -0.1_127, 0.2_687]]]	,    dtype=tf.floataa	,    )
           # camembert = torch.hub.load('pytorch/fairseq', 'camembert.v0')
           # camembert.eval()
           # expected_slice = roberta.model.forward(input_ids)[0][:, :3, :3].detach()

           self.assertTrue(np.allclose(output[:, :3, :3].numpy()	,    expected_slice.numpy()	,    atol=1E-4  )  )




