





import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


__lowerCamelCase :  Optional[int]										=  threading.Lock()
__lowerCamelCase :  Optional[logging.Handler]										=  None

__lowerCamelCase :  Tuple										=  {
    """debug""": logging.DEBUG,
    """info""": logging.INFO,
    """warning""": logging.WARNING,
    """error""": logging.ERROR,
    """critical""": logging.CRITICAL,
}

__lowerCamelCase :  List[str]										=  logging.WARNING

__lowerCamelCase :  List[str]										=  True



def 	A_       (  )		->				int:
 UpperCamelCase			:      Any 			=     os.getenv("TRANSFORMERS_VERBOSITY"							,     _lowerCAmelCase  )
 if env_level_str:
  if env_level_str in log_levels:
   return log_levels[env_level_str]
  else:
   logging.getLogger().warning(
       F"""Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, """
       F"""has to be one of: { ", ".join(log_levels.keys()  ) }"""  )
 return _default_log_level



def 	A_       (  )		->				str:
 return __name__.split("."  )[0]



def 	A_       (  )		->				logging.Logger:
 return logging.getLogger(_get_library_name()  )



def 	A_       (  )		->				None:
 global _default_handler

 with _lock:
  if _default_handler:
   # This library has already configured the library root logger.
   return
  UpperCamelCase			:      str 			=     logging.StreamHandler()  # Set sys.stderr as stream.
  UpperCamelCase			:      Tuple 			=     sys.stderr.flush

  # Apply our default configuration to the library root logger.
  UpperCamelCase			:      Optional[Any] 			=     _get_library_root_logger()
  library_root_logger.addHandler(_default_handler  )
  library_root_logger.setLevel(_get_default_logging_level()  )
  UpperCamelCase			:      Any 			=     False



def 	A_       (  )		->				None:
 global _default_handler

 with _lock:
  if not _default_handler:
   return

  UpperCamelCase			:      List[Any] 			=     _get_library_root_logger()
  library_root_logger.removeHandler(_default_handler  )
  library_root_logger.setLevel(logging.NOTSET  )
  UpperCamelCase			:      Union[str, Any] 			=     None



def 	A_       (  )		->				Any:
 return log_levels



def 	A_       (  _lowerCAmelCase = None  )		->				logging.Logger:

 if name is None:
  UpperCamelCase			:      Any 			=     _get_library_name()

 _configure_library_root_logger()
 return logging.getLogger(_lowerCAmelCase  )



def 	A_       (  )		->				int:
 _configure_library_root_logger()
 return _get_library_root_logger().getEffectiveLevel()



def 	A_       (  _lowerCAmelCase  )		->				None:
 _configure_library_root_logger()
 _get_library_root_logger().setLevel(_lowerCAmelCase  )



def 	A_       (  )		->				Optional[Any]:
 return set_verbosity(_lowerCAmelCase  )



def 	A_       (  )		->				Optional[int]:
 return set_verbosity(_lowerCAmelCase  )



def 	A_       (  )		->				Optional[Any]:
 return set_verbosity(_lowerCAmelCase  )



def 	A_       (  )		->				int:
 return set_verbosity(_lowerCAmelCase  )



def 	A_       (  )		->				None:
 _configure_library_root_logger()

 assert _default_handler is not None
 _get_library_root_logger().removeHandler(_default_handler  )



def 	A_       (  )		->				None:
 _configure_library_root_logger()

 assert _default_handler is not None
 _get_library_root_logger().addHandler(_default_handler  )



def 	A_       (  _lowerCAmelCase  )		->				None:
 _configure_library_root_logger()

 assert handler is not None
 _get_library_root_logger().addHandler(_lowerCAmelCase  )



def 	A_       (  _lowerCAmelCase  )		->				None:
 _configure_library_root_logger()

 assert handler is not None and handler not in _get_library_root_logger().handlers
 _get_library_root_logger().removeHandler(_lowerCAmelCase  )



def 	A_       (  )		->				None:
 _configure_library_root_logger()
 UpperCamelCase			:      int 			=     False



def 	A_       (  )		->				None:
 _configure_library_root_logger()
 UpperCamelCase			:      Tuple 			=     True



def 	A_       (  )		->				None:
 UpperCamelCase			:      Union[str, Any] 			=     _get_library_root_logger().handlers

 for handler in handlers:
  UpperCamelCase			:      Tuple 			=     logging.Formatter("[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"  )
  handler.setFormatter(_lowerCAmelCase  )



def 	A_       (  )		->				None:
 UpperCamelCase			:      List[str] 			=     _get_library_root_logger().handlers

 for handler in handlers:
  handler.setFormatter(_lowerCAmelCase  )



def 	A_       (  self							,     *_lowerCAmelCase							,     **_lowerCAmelCase  )		->				Dict:
 UpperCamelCase			:      Union[str, Any] 			=     os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS"							,     _lowerCAmelCase  )
 if no_advisory_warnings:
  return
 self.warning(*_lowerCAmelCase							,     **_lowerCAmelCase  )


__lowerCamelCase :  Tuple										=  warning_advice



@functools.lru_cache(_lowerCAmelCase  )
def 	A_       (  self							,     *_lowerCAmelCase							,     **_lowerCAmelCase  )		->				Any:
 self.warning(*_lowerCAmelCase							,     **_lowerCAmelCase  )


__lowerCamelCase :  str										=  warning_once



class       A__     :





      def __init__(				self ,							*A_ ,							**A_     ):  # pylint: disable=unused-argument
       '''simple docstring'''




       UpperCamelCase			:      List[Any] 			=     args[0] if args else None





      def __iter__(				self     ):
       '''simple docstring'''




       return iter(self._iterator     )





      def __getattr__(				self ,							A_     ):
       '''simple docstring'''




       def empty_fn(*A_ ,							**A_     ):  # pylint: disable=unused-argument
        return

       return empty_fn





      def __enter__(				self     ):
       '''simple docstring'''




       return self





      def __exit__(				self ,							A_ ,							A_ ,							A_     ):
       '''simple docstring'''




       return



class       A__     :





      def __call__(				self ,							*A_ ,							**A_     ):
       '''simple docstring'''




       if _tqdm_active:
        return tqdm_lib.tqdm(*A_ ,							**A_     )
       else:
        return EmptyTqdm(*A_ ,							**A_     )





      def  __UpperCamelCase(				self ,							*A_ ,							**A_     ):
       '''simple docstring'''




       UpperCamelCase			:      Tuple 			=     None
       if _tqdm_active:
        return tqdm_lib.tqdm.set_lock(*A_ ,							**A_     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       if _tqdm_active:
        return tqdm_lib.tqdm.get_lock()


__lowerCamelCase :  Union[str, Any]										=  _tqdm_cls()



def 	A_       (  )		->				bool:
 global _tqdm_active
 return bool(_tqdm_active  )



def 	A_       (  )		->				List[Any]:
 global _tqdm_active
 UpperCamelCase			:      Dict 			=     True
 hf_hub_utils.enable_progress_bars()



def 	A_       (  )		->				str:
 global _tqdm_active
 UpperCamelCase			:      Any 			=     False
 hf_hub_utils.disable_progress_bars()







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





      def __init__(				self ,							A_ ,							A_=7 ,							A_=3 ,							A_=10 ,							A_=18 ,							A_=30 ,							A_=400 ,							A_=True ,							A_=None ,							A_=True ,							A_=[0.5, 0.5, 0.5] ,							A_=[0.5, 0.5, 0.5] ,							A_=None ,							):
       '''simple docstring'''




       UpperCamelCase			:      Optional[int] 			=     size if size is not None else {"shortest_edge": 18}
       UpperCamelCase			:      Tuple 			=     crop_size if crop_size is not None else {"height": 18, "width": 18}

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





      def  __UpperCamelCase(				self     ):
       '''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,
           "crop_size": self.crop_size,
       }



@require_torch
@require_vision
class       A__     ( __snake_case ,     unittest.TestCase    ):
      _UpperCAmelCase			:List[str]							=     VivitImageProcessor if is_vision_available() else None





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      List[Any] 			=     VivitImageProcessingTester(self     )





      @property
      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       return self.image_processor_tester.prepare_image_processor_dict()





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      List[Any] 			=     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_ ,							"do_center_crop"     )     )
       self.assertTrue(hasattr(A_ ,							"size"     )     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Dict 			=     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			:      Dict 			=     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  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[Any] 			=     self.image_processing_class(**self.image_processor_dict     )
       # create random PIL videos
       UpperCamelCase			:      Union[str, Any] 			=     prepare_video_inputs(self.image_processor_tester ,							equal_resolution=A_     )
       for video in video_inputs:
        self.assertIsInstance(A_ ,							A_     )
        self.assertIsInstance(video[0] ,							Image.Image     )

       # Test not batched input
       UpperCamelCase			:      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			:      str 			=     image_processing(A_ ,							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  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      List[Any] 			=     self.image_processing_class(**self.image_processor_dict     )
       # create random numpy tensors
       UpperCamelCase			:      str 			=     prepare_video_inputs(self.image_processor_tester ,							equal_resolution=A_ ,							numpify=A_     )
       for video in video_inputs:
        self.assertIsInstance(A_ ,							A_     )
        self.assertIsInstance(video[0] ,							np.ndarray     )

       # Test not batched input
       UpperCamelCase			:      Tuple 			=     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(A_ ,							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  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      str 			=     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=A_ ,							torchify=A_     )
       for video in video_inputs:
        self.assertIsInstance(A_ ,							A_     )
        self.assertIsInstance(video[0] ,							torch.Tensor     )

       # Test not batched input
       UpperCamelCase			:      Tuple 			=     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(A_ ,							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"],
           ) ,							)
