






'''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 					__UpperCAmelCase (		unittest.TestCase	):

      '''simple docstring'''





      def __init__(					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase=7  ,		_UpperCAmelCase=3  ,		_UpperCAmelCase=10  ,		_UpperCAmelCase=18  ,		_UpperCAmelCase=30  ,		_UpperCAmelCase=400  ,		_UpperCAmelCase=True  ,		_UpperCAmelCase=None  ,		_UpperCAmelCase=True  ,		_UpperCAmelCase=[0.5, 0.5, 0.5]  ,		_UpperCAmelCase=[0.5, 0.5, 0.5]  ,		_UpperCAmelCase=None  ,		):
             UpperCAmelCase__	:   int												=	size if size is not None else {'''shortest_edge''': 18}
             UpperCAmelCase__	:   int												=	crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

             UpperCAmelCase__	:   Union[str, Any]												=	parent
             UpperCAmelCase__	:   Optional[Any]												=	batch_size
             UpperCAmelCase__	:   Union[str, Any]												=	num_channels
             UpperCAmelCase__	:   str												=	num_frames
             UpperCAmelCase__	:   Union[str, Any]												=	image_size
             UpperCAmelCase__	:   Optional[int]												=	min_resolution
             UpperCAmelCase__	:   Union[str, Any]												=	max_resolution
             UpperCAmelCase__	:   Optional[int]												=	do_resize
             UpperCAmelCase__	:   List[Any]												=	size
             UpperCAmelCase__	:   Any												=	do_normalize
             UpperCAmelCase__	:   Any												=	image_mean
             UpperCAmelCase__	:   List[str]												=	image_std
             UpperCAmelCase__	:   Dict												=	crop_size




      def 							lowerCamelCase     (					self						):
             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 					__UpperCAmelCase (		UpperCamelCase__      ,				unittest.TestCase	):

      '''simple docstring'''





      SCREAMING_SNAKE_CASE				:    Dict				       =					VideoMAEImageProcessor if is_vision_available() else None




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   List[Any]												=	VideoMAEImageProcessingTester(self						)




      @property
      def 							lowerCamelCase     (					self						):
             return self.image_processor_tester.prepare_image_processor_dict()




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Dict												=	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						):
             UpperCAmelCase__	:   Optional[int]												=	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}						)

             UpperCAmelCase__	:   str												=	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						):
             pass




      def 							lowerCamelCase     (					self						):
             # Initialize image_processing
             UpperCAmelCase__	:   List[Any]												=	self.image_processing_class(**self.image_processor_dict						)
             # create random PIL videos
             UpperCAmelCase__	:   Dict												=	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
             UpperCAmelCase__	:   Optional[int]												=	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
             UpperCAmelCase__	:   str												=	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						):
             # Initialize image_processing
             UpperCAmelCase__	:   List[str]												=	self.image_processing_class(**self.image_processor_dict						)
             # create random numpy tensors
             UpperCAmelCase__	:   Optional[Any]												=	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
             UpperCAmelCase__	:   List[str]												=	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
             UpperCAmelCase__	:   List[Any]												=	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						):
             # Initialize image_processing
             UpperCAmelCase__	:   Union[str, Any]												=	self.image_processing_class(**self.image_processor_dict						)
             # create random PyTorch tensors
             UpperCAmelCase__	:   Union[str, Any]												=	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
             UpperCAmelCase__	:   Union[str, Any]												=	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
             UpperCAmelCase__	:   List[str]												=	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'''







import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
  import torch

  from transformers import CamembertModel




@require_torch
@require_sentencepiece
@require_tokenizers
class 					__UpperCAmelCase (		unittest.TestCase	):

      '''simple docstring'''





      @slow
      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Optional[int]												=	CamembertModel.from_pretrained('''camembert-base'''						)
             model.to(_UpperCAmelCase						)

             UpperCAmelCase__	:   Optional[int]												=	torch.tensor(
                 [[5, 121, 11, 660, 16, 730, 2_5543, 110, 83, 6]]  ,		device=_UpperCAmelCase  ,		dtype=torch.long  ,		)  # J'aime le camembert !
             with torch.no_grad():
                    UpperCAmelCase__	:   Tuple												=	model(_UpperCAmelCase						)['''last_hidden_state''']
             UpperCAmelCase__	:   List[str]												=	torch.Size((1, 10, 768)						)
             self.assertEqual(output.shape  ,		_UpperCAmelCase						)
             # compare the actual values for a slice.
             UpperCAmelCase__	:   List[Any]												=	torch.tensor(
                 [[[-0.02_54, 0.02_35, 0.10_27], [0.06_06, -0.18_11, -0.04_18], [-0.15_61, -0.11_27, 0.26_87]]]  ,		device=_UpperCAmelCase  ,		dtype=torch.float  ,		)
             # camembert = torch.hub.load('pytorch/fairseq', 'camembert.v0')
             # camembert.eval()
             # expected_slice = roberta.model.forward(input_ids)[0][:, :3, :3].detach()

             self.assertTrue(torch.allclose(output[:, :3, :3]  ,		_UpperCAmelCase  ,		atol=1E-4						)						)