

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



def        _lowerCAmelCase      (						UpperCAmelCase     :							Optional[Any]      ,							UpperCAmelCase     :							Union[str, Any]=10      ,							UpperCAmelCase     :							Optional[int]=10      ,							UpperCAmelCase     :							int=False      ,							UpperCAmelCase     :							Optional[int]=False				):


     '''simple docstring'''






     UpperCamelCase__		:    int         =[]
     for i in range(image_processor_tester.num_frames				):
          video.append(np.random.randint(255      ,							size=(image_processor_tester.num_channels, width, height)      ,							dtype=np.uinta				)				)

     if not numpify and not torchify:
          # PIL expects the channel dimension as last dimension
          UpperCamelCase__		:    Any         =[Image.fromarray(np.moveaxis(__snake_case      ,							0      ,							-1				)				) for frame in video]

     if torchify:
          UpperCamelCase__		:    Union[str, Any]         =[torch.from_numpy(__snake_case				) for frame in video]

     return video



def        _lowerCAmelCase      (						UpperCAmelCase     :							Union[str, Any]      ,							UpperCAmelCase     :							Optional[Any]=False      ,							UpperCAmelCase     :							Optional[int]=False      ,							UpperCAmelCase     :							Tuple=False				):


     '''simple docstring'''






     assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

     UpperCamelCase__		:    int         =[]
     for i in range(image_processor_tester.batch_size				):
          if equal_resolution:
               UpperCamelCase__		:    List[Any]         =image_processor_tester.max_resolution
          else:
               UpperCamelCase__  ,			UpperCamelCase__		:    List[str]         =np.random.choice(
                   np.arange(image_processor_tester.min_resolution      ,							image_processor_tester.max_resolution				)      ,							2				)
               UpperCamelCase__		:    List[Any]         =prepare_video(
                   image_processor_tester=__snake_case      ,							width=__snake_case      ,							height=__snake_case      ,							numpify=__snake_case      ,							torchify=__snake_case      ,							)
          video_inputs.append(__snake_case				)

     return video_inputs

class     __a   (      unittest.TestCase    ):

   """simple docstring"""

   def __init__(							self     :					str						,  lowercase_     :					Tuple						,  lowercase_     :					Optional[int]=7						,  lowercase_     :					Tuple=3						,  lowercase_     :					Tuple=4						,  lowercase_     :					Tuple=18						,  lowercase_     :					Dict=30						,  lowercase_     :					List[Any]=400						,  lowercase_     :					str=True						,  lowercase_     :					List[str]=None						,  lowercase_     :					str=True						,  lowercase_     :					Any=[0.5, 0.5, 0.5]						,  lowercase_     :					Any=[0.5, 0.5, 0.5]						,  lowercase_     :					str=True						,  lowercase_     :					Dict=None						,  ):
        UpperCamelCase__		:    List[str]         =size if size is not None else {'''shortest_edge''': 18}
        UpperCamelCase__		:    Optional[int]         =crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

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






   def    _lowerCAmelCase			(							self     :					str						):
        return {
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_normalize": self.do_normalize,
            "do_resize": self.do_resize,
            "size": self.size,
            "do_center_crop": self.do_center_crop,
            "crop_size": self.crop_size,
        }



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

   """simple docstring"""

   SCREAMING_SNAKE_CASE_						     =						TvltImageProcessor if is_vision_available() else None






   def    _lowerCAmelCase			(							self     :					List[Any]						):
        UpperCamelCase__		:    List[Any]         =TvltImageProcessorTester(self						)






   @property
   def    _lowerCAmelCase			(							self     :					int						):
        return self.image_processor_tester.prepare_image_processor_dict()






   def    _lowerCAmelCase			(							self     :					Dict						):
        UpperCamelCase__		:    int         =self.image_processing_class(**self.image_processor_dict						)
        self.assertTrue(hasattr(lowercase_						,  '''image_mean'''						)						)
        self.assertTrue(hasattr(lowercase_						,  '''image_std'''						)						)
        self.assertTrue(hasattr(lowercase_						,  '''do_normalize'''						)						)
        self.assertTrue(hasattr(lowercase_						,  '''do_resize'''						)						)
        self.assertTrue(hasattr(lowercase_						,  '''do_center_crop'''						)						)
        self.assertTrue(hasattr(lowercase_						,  '''size'''						)						)






   def    _lowerCAmelCase			(							self     :					Any						):
        UpperCamelCase__		:    Dict         =self.image_processing_class(**self.image_processor_dict						)
        # create random PIL videos
        UpperCamelCase__		:    Optional[int]         =prepare_video_inputs(self.image_processor_tester						,  equal_resolution=lowercase_						)
        for video in video_inputs:
             self.assertIsInstance(lowercase_						,  lowercase_						)
             self.assertIsInstance(video[0]						,  Image.Image						)

        # Test not batched input
        UpperCamelCase__		:    List[Any]         =image_processor(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_processor(lowercase_						,  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     :					List[str]						):
        UpperCamelCase__		:    Dict         =self.image_processing_class(**self.image_processor_dict						)
        # create random numpy tensors
        UpperCamelCase__		:    int         =prepare_video_inputs(self.image_processor_tester						,  equal_resolution=lowercase_						,  numpify=lowercase_						)
        for video in video_inputs:
             self.assertIsInstance(lowercase_						,  lowercase_						)
             self.assertIsInstance(video[0]						,  np.ndarray						)

        # Test not batched input
        UpperCamelCase__		:    Union[str, Any]         =image_processor(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__		:    Optional[int]         =image_processor(lowercase_						,  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     :					str						):
        UpperCamelCase__		:    Tuple         =self.image_processing_class(**self.image_processor_dict						)
        # create random PyTorch tensors
        UpperCamelCase__		:    Any         =prepare_video_inputs(self.image_processor_tester						,  equal_resolution=lowercase_						,  torchify=lowercase_						)
        for video in video_inputs:
             self.assertIsInstance(lowercase_						,  lowercase_						)
             self.assertIsInstance(video[0]						,  torch.Tensor						)

        # Test not batched input
        UpperCamelCase__		:    Optional[Any]         =image_processor(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__		:    Tuple         =image_processor(lowercase_						,  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 typing import TYPE_CHECKING

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


_SCREAMING_SNAKE_CASE       :  List[Any]        = {"""configuration_t5""": ["""T5_PRETRAINED_CONFIG_ARCHIVE_MAP""", """T5Config""", """T5OnnxConfig"""]}

try:
				if not is_sentencepiece_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_SCREAMING_SNAKE_CASE       :  Optional[Any]        = ["""T5Tokenizer"""]

try:
				if not is_tokenizers_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_SCREAMING_SNAKE_CASE       :  str        = ["""T5TokenizerFast"""]

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_SCREAMING_SNAKE_CASE       :  Dict        = [
				    """T5_PRETRAINED_MODEL_ARCHIVE_LIST""",
				    """T5EncoderModel""",
				    """T5ForConditionalGeneration""",
				    """T5Model""",
				    """T5PreTrainedModel""",
				    """load_tf_weights_in_t5""",
				    """T5ForQuestionAnswering""",
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_SCREAMING_SNAKE_CASE       :  Dict        = [
				    """TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST""",
				    """TFT5EncoderModel""",
				    """TFT5ForConditionalGeneration""",
				    """TFT5Model""",
				    """TFT5PreTrainedModel""",
				]

try:
				if not is_flax_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_SCREAMING_SNAKE_CASE       :  Any        = [
				    """FlaxT5EncoderModel""",
				    """FlaxT5ForConditionalGeneration""",
				    """FlaxT5Model""",
				    """FlaxT5PreTrainedModel""",
				]


if TYPE_CHECKING:
				from .configuration_ta import T5_PRETRAINED_CONFIG_ARCHIVE_MAP, TaConfig, TaOnnxConfig

				try:
								if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_ta import TaTokenizer

				try:
								if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_ta_fast import TaTokenizerFast

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_ta import (
								    T5_PRETRAINED_MODEL_ARCHIVE_LIST,
								    TaEncoderModel,
								    TaForConditionalGeneration,
								    TaForQuestionAnswering,
								    TaModel,
								    TaPreTrainedModel,
								    load_tf_weights_in_ta,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_ta import (
								    TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST,
								    TFTaEncoderModel,
								    TFTaForConditionalGeneration,
								    TFTaModel,
								    TFTaPreTrainedModel,
								)

				try:
								if not is_flax_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_flax_ta import (
								    FlaxTaEncoderModel,
								    FlaxTaForConditionalGeneration,
								    FlaxTaModel,
								    FlaxTaPreTrainedModel,
								)


else:
				import sys

				_SCREAMING_SNAKE_CASE       :  str        = _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


