


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__			:      List[str]								=threading.Lock()
lowerCAmelCase__			:      Optional[logging.Handler]								=None

lowerCAmelCase__			:      List[Any]								={
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

lowerCAmelCase__			:      Tuple								=logging.WARNING

lowerCAmelCase__			:      Dict								=True






def 						a__			(				):
			SCREAMING_SNAKE_CASE_		:     Optional[int]					=					os.getenv('TRANSFORMERS_VERBOSITY',      A__				)
			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__			(				):
			return __name__.split('.'				)[0]






def 						a__			(				):
			return logging.getLogger(_get_library_name()				)






def 						a__			(				):
			global _default_handler

			with _lock:
						if _default_handler:
									# This library has already configured the library root logger.
									return
						SCREAMING_SNAKE_CASE_		:     Optional[int]					=					logging.StreamHandler()  # Set sys.stderr as stream.
						SCREAMING_SNAKE_CASE_		:     Any					=					sys.stderr.flush

						# Apply our default configuration to the library root logger.
						SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					_get_library_root_logger()
						library_root_logger.addHandler(_default_handler				)
						library_root_logger.setLevel(_get_default_logging_level()				)
						SCREAMING_SNAKE_CASE_		:     int					=					False






def 						a__			(				):
			global _default_handler

			with _lock:
						if not _default_handler:
									return

						SCREAMING_SNAKE_CASE_		:     List[str]					=					_get_library_root_logger()
						library_root_logger.removeHandler(_default_handler				)
						library_root_logger.setLevel(logging.NOTSET				)
						SCREAMING_SNAKE_CASE_		:     int					=					None






def 						a__			(				):
			return log_levels






def 						a__			(				A__ = None				):

			if name is None:
						SCREAMING_SNAKE_CASE_		:     List[str]					=					_get_library_name()

			_configure_library_root_logger()
			return logging.getLogger(A__				)






def 						a__			(				):
			_configure_library_root_logger()
			return _get_library_root_logger().getEffectiveLevel()






def 						a__			(				A__				):
			_configure_library_root_logger()
			_get_library_root_logger().setLevel(A__				)






def 						a__			(				):
			return set_verbosity(A__				)






def 						a__			(				):
			return set_verbosity(A__				)






def 						a__			(				):
			return set_verbosity(A__				)






def 						a__			(				):
			return set_verbosity(A__				)






def 						a__			(				):
			_configure_library_root_logger()

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






def 						a__			(				):
			_configure_library_root_logger()

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






def 						a__			(				A__				):
			_configure_library_root_logger()

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






def 						a__			(				A__				):
			_configure_library_root_logger()

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






def 						a__			(				):
			_configure_library_root_logger()
			SCREAMING_SNAKE_CASE_		:     str					=					False






def 						a__			(				):
			_configure_library_root_logger()
			SCREAMING_SNAKE_CASE_		:     str					=					True






def 						a__			(				):
			SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					_get_library_root_logger().handlers

			for handler in handlers:
						SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'				)
						handler.setFormatter(A__				)






def 						a__			(				):
			SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					_get_library_root_logger().handlers

			for handler in handlers:
						handler.setFormatter(A__				)






def 						a__			(				self,      *A__,      **A__				):
			SCREAMING_SNAKE_CASE_		:     Dict					=					os.getenv('TRANSFORMERS_NO_ADVISORY_WARNINGS',      A__				)
			if no_advisory_warnings:
						return
			self.warning(*A__,      **A__				)


lowerCAmelCase__			:      Optional[Any]								=warning_advice






@functools.lru_cache(A__				)
def 						a__			(				self,      *A__,      **A__				):
			self.warning(*A__,      **A__				)


lowerCAmelCase__			:      List[str]								=warning_once







class 	__lowercase    :





							"""simple docstring"""







							def __init__(      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):  # pylint: disable=unused-argument





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     List[str]					=					args[0] if args else None






							def __iter__(      self       ):





										"""simple docstring"""




										return iter(self._iterator       )






							def __getattr__(      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




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

										return empty_fn






							def __enter__(      self       ):





										"""simple docstring"""




										return self






							def __exit__(      self			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__       ):





										"""simple docstring"""




										return







class 	__lowercase    :





							"""simple docstring"""







							def __call__(      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




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






							def 					UpperCamelCase__     (      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					None
										if _tqdm_active:
													return tqdm_lib.tqdm.set_lock(*lowerCAmelCase__			,						**lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										if _tqdm_active:
													return tqdm_lib.tqdm.get_lock()







lowerCAmelCase__			:      str								=_tqdm_cls()






def 						a__			(				):
			global _tqdm_active
			return bool(_tqdm_active				)






def 						a__			(				):
			global _tqdm_active
			SCREAMING_SNAKE_CASE_		:     Any					=					True
			hf_hub_utils.enable_progress_bars()






def 						a__			(				):
			global _tqdm_active
			SCREAMING_SNAKE_CASE_		:     Optional[int]					=					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_image_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import ViTImageProcessor


class 							UpperCamelCase_       (					unittest.TestCase	):

    '''simple docstring'''






    def __init__(     self :      Tuple   ,					UpperCAmelCase__ :      List[str]   ,					UpperCAmelCase__ :      int=13   ,					UpperCAmelCase__ :      Union[str, Any]=3   ,					UpperCAmelCase__ :      str=224   ,					UpperCAmelCase__ :      str=30   ,					UpperCAmelCase__ :      Tuple=400   ,					UpperCAmelCase__ :      int=True   ,					UpperCAmelCase__ :      Dict=None   ,					UpperCAmelCase__ :      List[Any]=True   ,					UpperCAmelCase__ :      Union[str, Any]=[0.5, 0.5, 0.5]   ,					UpperCAmelCase__ :      Tuple=[0.5, 0.5, 0.5]   ,					)		->str:





           '''simple docstring'''

           A__ 					=       size if size is not None else {'''height''': 18, '''width''': 18}
           A__ 					=       parent
           A__ 					=       batch_size
           A__ 					=       num_channels
           A__ 					=       image_size
           A__ 					=       min_resolution
           A__ 					=       max_resolution
           A__ 					=       do_resize
           A__ 					=       size
           A__ 					=       do_normalize
           A__ 					=       image_mean
           A__ 					=       image_std





    def 			SCREAMING_SNAKE_CASE				(     self :      Any)		->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 							UpperCamelCase_       (					UpperCAmelCase__						,   unittest.TestCase	):

    '''simple docstring'''






    UpperCAmelCase__				    = ViTImageProcessor if is_vision_available() else None


    def 			SCREAMING_SNAKE_CASE				(     self :      List[str])		->str:





           '''simple docstring'''

           A__ 					=       EfficientFormerImageProcessorTester(self)


    @property
    def 			SCREAMING_SNAKE_CASE				(     self :      Dict)		->int:





           '''simple docstring'''

           return self.image_proc_tester.prepare_image_processor_dict()


    def 			SCREAMING_SNAKE_CASE				(     self :      Optional[Any])		->Dict:





           '''simple docstring'''

           A__ 					=       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__   ,					'''size'''))


    def 			SCREAMING_SNAKE_CASE				(     self :      List[str])		->Dict:





           '''simple docstring'''

           pass


    def 			SCREAMING_SNAKE_CASE				(     self :      str)		->Optional[Any]:





           '''simple docstring'''

           A__ 					=       self.image_processing_class(**self.image_processor_dict)
           # create random PIL images
           A__ 					=       prepare_image_inputs(self.image_proc_tester   ,					equal_resolution=UpperCAmelCase__)
           for image in image_inputs:
                  self.assertIsInstance(UpperCAmelCase__   ,					Image.Image)

           # Test not batched input
           A__ 					=       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
           A__ 					=       image_processor(UpperCAmelCase__   ,					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 			SCREAMING_SNAKE_CASE				(     self :      Tuple)		->List[Any]:





           '''simple docstring'''

           A__ 					=       self.image_processing_class(**self.image_processor_dict)
           # create random numpy tensors
           A__ 					=       prepare_image_inputs(self.image_proc_tester   ,					equal_resolution=UpperCAmelCase__   ,					numpify=UpperCAmelCase__)
           for image in image_inputs:
                  self.assertIsInstance(UpperCAmelCase__   ,					np.ndarray)

           # Test not batched input
           A__ 					=       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
           A__ 					=       image_processor(UpperCAmelCase__   ,					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 			SCREAMING_SNAKE_CASE				(     self :      Tuple)		->Optional[Any]:





           '''simple docstring'''

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

           # Test not batched input
           A__ 					=       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
           A__ 					=       image_processor(UpperCAmelCase__   ,					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'''],
               )   ,					)


