'''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 VivitImageProcessor






class 			__lowercase		(						unittest.TestCase						):







     """simple docstring"""






     def __init__(		self     ,			_lowerCamelCase     ,			_lowerCamelCase=7     ,			_lowerCamelCase=3     ,			_lowerCamelCase=1_0     ,			_lowerCamelCase=1_8     ,			_lowerCamelCase=3_0     ,			_lowerCamelCase=4_0_0     ,			_lowerCamelCase=True     ,			_lowerCamelCase=None     ,			_lowerCamelCase=True     ,			_lowerCamelCase=[0.5, 0.5, 0.5]     ,			_lowerCamelCase=[0.5, 0.5, 0.5]     ,			_lowerCamelCase=None     ,			):
         __UpperCamelCase	:	int		    =  size if size is not None else {'shortest_edge': 1_8}
         __UpperCamelCase	:	List[str]		    =  crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}

         __UpperCamelCase	:	List[Any]		    =  parent
         __UpperCamelCase	:	Union[str, Any]		    =  batch_size
         __UpperCamelCase	:	Optional[int]		    =  num_channels
         __UpperCamelCase	:	str		    =  num_frames
         __UpperCamelCase	:	Any		    =  image_size
         __UpperCamelCase	:	Union[str, Any]		    =  min_resolution
         __UpperCamelCase	:	Optional[int]		    =  max_resolution
         __UpperCamelCase	:	Optional[int]		    =  do_resize
         __UpperCamelCase	:	Optional[int]		    =  size
         __UpperCamelCase	:	Dict		    =  do_normalize
         __UpperCamelCase	:	Union[str, Any]		    =  image_mean
         __UpperCamelCase	:	Dict		    =  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 			__lowercase		(						_lowerCamelCase			,							unittest.TestCase						):







     """simple docstring"""






     SCREAMING_SNAKE_CASE__		   =						VivitImageProcessor if is_vision_available() else None







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Dict		    =  VivitImageProcessingTester(self    )







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







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Union[str, Any]		    =  self.image_processing_class(**self.image_processor_dict    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'image_mean'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'image_std'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'do_normalize'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'do_resize'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'do_center_crop'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'size'    )    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	int		    =  self.image_processing_class.from_dict(self.image_processor_dict    )
         self.assertEqual(image_processor.size     ,			{'shortest_edge': 1_8}    )
         self.assertEqual(image_processor.crop_size     ,			{'height': 1_8, 'width': 1_8}    )

         __UpperCamelCase	:	Optional[int]		    =  self.image_processing_class.from_dict(self.image_processor_dict     ,			size=4_2     ,			crop_size=8_4    )
         self.assertEqual(image_processor.size     ,			{'shortest_edge': 4_2}    )
         self.assertEqual(image_processor.crop_size     ,			{'height': 8_4, 'width': 8_4}    )







     def lowerCAmelCase     (		self    ):
         # Initialize image_processing
         __UpperCamelCase	:	List[str]		    =  self.image_processing_class(**self.image_processor_dict    )
         # create random PIL videos
         __UpperCamelCase	:	Tuple		    =  prepare_video_inputs(self.image_processor_tester     ,			equal_resolution=_lowerCamelCase    )
         for video in video_inputs:
             self.assertIsInstance(_lowerCamelCase     ,			_lowerCamelCase    )
             self.assertIsInstance(video[0]     ,			Image.Image    )

         # Test not batched input
         __UpperCamelCase	:	List[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	:	Tuple		    =  image_processing(_lowerCamelCase     ,			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	:	Tuple		    =  self.image_processing_class(**self.image_processor_dict    )
         # create random numpy tensors
         __UpperCamelCase	:	Dict		    =  prepare_video_inputs(self.image_processor_tester     ,			equal_resolution=_lowerCamelCase     ,			numpify=_lowerCamelCase    )
         for video in video_inputs:
             self.assertIsInstance(_lowerCamelCase     ,			_lowerCamelCase    )
             self.assertIsInstance(video[0]     ,			np.ndarray    )

         # Test not batched input
         __UpperCamelCase	:	Optional[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	:	Any		    =  image_processing(_lowerCamelCase     ,			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 PyTorch tensors
         __UpperCamelCase	:	Optional[Any]		    =  prepare_video_inputs(self.image_processor_tester     ,			equal_resolution=_lowerCamelCase     ,			torchify=_lowerCamelCase    )
         for video in video_inputs:
             self.assertIsInstance(_lowerCamelCase     ,			_lowerCamelCase    )
             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(_lowerCamelCase     ,			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_sentencepiece_available,
    is_tokenizers_available,
    is_torch_available,
)


a=  {}

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

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


if TYPE_CHECKING:
  try:
    if not is_sentencepiece_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_nllb import NllbTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_nllb_fast import NllbTokenizerFast

else:
  import sys

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



