


'''simple docstring'''
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


UpperCamelCase__    					=      threading.Lock()
UpperCamelCase__    					=      None

UpperCamelCase__    					=      {
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

UpperCamelCase__    					=      logging.WARNING

UpperCamelCase__    					=      True





def 					a__       (					)    ->	str:
    UpperCAmelCase__			:		List[Any]													=				os.getenv('''TRANSFORMERS_VERBOSITY'''  ,					SCREAMING_SNAKE_CASE__						)
    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__       (					)    ->	Tuple:
    return __name__.split('''.'''						)[0]





def 					a__       (					)    ->	int:
    return logging.getLogger(_get_library_name()						)





def 					a__       (					)    ->	Tuple:
    global _default_handler

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

        # Apply our default configuration to the library root logger.
        UpperCAmelCase__			:		Dict													=				_get_library_root_logger()
        library_root_logger.addHandler(_default_handler						)
        library_root_logger.setLevel(_get_default_logging_level()						)
        UpperCAmelCase__			:		str													=				False





def 					a__       (					)    ->	Dict:
    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__			:		Optional[Any]													=				None





def 					a__       (					)    ->	Dict:
    return log_levels





def 					a__       (					lowerCAmelCase__ = None						)    ->	List[str]:





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

    _configure_library_root_logger()
    return logging.getLogger(SCREAMING_SNAKE_CASE__						)





def 					a__       (					)    ->	Union[str, Any]:
    _configure_library_root_logger()
    return _get_library_root_logger().getEffectiveLevel()





def 					a__       (					lowerCAmelCase__						)    ->	Any:
    _configure_library_root_logger()
    _get_library_root_logger().setLevel(SCREAMING_SNAKE_CASE__						)





def 					a__       (					)    ->	Tuple:
    return set_verbosity(SCREAMING_SNAKE_CASE__						)





def 					a__       (					)    ->	Dict:
    return set_verbosity(SCREAMING_SNAKE_CASE__						)





def 					a__       (					)    ->	Optional[Any]:
    return set_verbosity(SCREAMING_SNAKE_CASE__						)





def 					a__       (					)    ->	str:
    return set_verbosity(SCREAMING_SNAKE_CASE__						)





def 					a__       (					)    ->	Dict:
    _configure_library_root_logger()

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





def 					a__       (					)    ->	Dict:
    _configure_library_root_logger()

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





def 					a__       (					lowerCAmelCase__						)    ->	Dict:
    _configure_library_root_logger()

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





def 					a__       (					lowerCAmelCase__						)    ->	Tuple:
    _configure_library_root_logger()

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





def 					a__       (					)    ->	Optional[Any]:
    _configure_library_root_logger()
    UpperCAmelCase__			:		List[str]													=				False





def 					a__       (					)    ->	int:
    _configure_library_root_logger()
    UpperCAmelCase__			:		List[Any]													=				True





def 					a__       (					)    ->	Union[str, Any]:
    UpperCAmelCase__			:		Dict													=				_get_library_root_logger().handlers

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





def 					a__       (					)    ->	Tuple:
    UpperCAmelCase__			:		Union[str, Any]													=				_get_library_root_logger().handlers

    for handler in handlers:
        handler.setFormatter(SCREAMING_SNAKE_CASE__						)





def 					a__       (					self  ,					*lowerCAmelCase__  ,					**lowerCAmelCase__						)    ->	List[Any]:
    UpperCAmelCase__			:		int													=				os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS'''  ,					SCREAMING_SNAKE_CASE__						)
    if no_advisory_warnings:
        return
    self.warning(*SCREAMING_SNAKE_CASE__  ,					**SCREAMING_SNAKE_CASE__						)


UpperCamelCase__    					=      warning_advice





@functools.lru_cache(SCREAMING_SNAKE_CASE__						)
def 					a__       (					self  ,					*lowerCAmelCase__  ,					**lowerCAmelCase__						)    ->	Union[str, Any]:
    self.warning(*SCREAMING_SNAKE_CASE__  ,					**SCREAMING_SNAKE_CASE__						)


UpperCamelCase__    					=      warning_once




class 			lowerCamelCase_   :






      def __init__(					self				:    Union[str, Any]						,						*_A				:    str						,						**_A				:    Tuple ):  # pylint: disable=unused-argument


          '''simple docstring'''


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






      def __iter__(					self				:    Optional[Any] ):


          '''simple docstring'''


          return iter(self._iterator )






      def __getattr__(					self				:    Any						,						_A				:    Union[str, Any] ):


          '''simple docstring'''


          def empty_fn(*_A				:    List[Any]						,						**_A				:    str ):  # pylint: disable=unused-argument
              return

          return empty_fn






      def __enter__(					self				:    Union[str, Any] ):


          '''simple docstring'''


          return self






      def __exit__(					self				:    List[Any]						,						_A				:    int						,						_A				:    Optional[int]						,						_A				:    Dict ):


          '''simple docstring'''


          return




class 			lowerCamelCase_   :






      def __call__(					self				:    str						,						*_A				:    str						,						**_A				:    Any ):


          '''simple docstring'''


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






      def lowercase_							(					self				:    Tuple						,						*_A				:    Any						,						**_A				:    Optional[int] ):


          '''simple docstring'''


          UpperCAmelCase__			:		List[Any]													=				None
          if _tqdm_active:
              return tqdm_lib.tqdm.set_lock(*__snake_case						,						**__snake_case )






      def lowercase_							(					self				:    Optional[int] ):


          '''simple docstring'''


          if _tqdm_active:
              return tqdm_lib.tqdm.get_lock()

UpperCamelCase__    					=      _tqdm_cls()





def 					a__       (					)    ->	Union[str, Any]:
    global _tqdm_active
    return bool(_tqdm_active						)





def 					a__       (					)    ->	Tuple:
    global _tqdm_active
    UpperCAmelCase__			:		Optional[int]													=				True
    hf_hub_utils.enable_progress_bars()







def 					a__       (					)    ->	Dict:
    global _tqdm_active
    UpperCAmelCase__			:		Any													=				False
    hf_hub_utils.disable_progress_bars()




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


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import MobileNetVaImageProcessor





class     lowercase__  (						unittest.TestCase					):





							'''simple docstring'''


							def __init__(    self    ,					__snake_case    ,					__snake_case=7    ,					__snake_case=3    ,					__snake_case=18    ,					__snake_case=30    ,					__snake_case=400    ,					__snake_case=True    ,					__snake_case=None    ,					__snake_case=True    ,					__snake_case=None    ,					):
											_SCREAMING_SNAKE_CASE :       Any     		=      size if size is not None else {"""shortest_edge""": 20}
											_SCREAMING_SNAKE_CASE :       int     		=      crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
											_SCREAMING_SNAKE_CASE :       Dict     		=      parent
											_SCREAMING_SNAKE_CASE :       Any     		=      batch_size
											_SCREAMING_SNAKE_CASE :       Any     		=      num_channels
											_SCREAMING_SNAKE_CASE :       Dict     		=      image_size
											_SCREAMING_SNAKE_CASE :       Any     		=      min_resolution
											_SCREAMING_SNAKE_CASE :       Any     		=      max_resolution
											_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      do_resize
											_SCREAMING_SNAKE_CASE :       Tuple     		=      size
											_SCREAMING_SNAKE_CASE :       Optional[int]     		=      do_center_crop
											_SCREAMING_SNAKE_CASE :       str     		=      crop_size






							def UpperCAmelCase_	(    self  ):
											return {
											    "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     lowercase__  (						_snake_case     ,     unittest.TestCase					):





							'''simple docstring'''


							A_							:      Union[str, Any]      	=  MobileNetVaImageProcessor if is_vision_available() else None






							def UpperCAmelCase_	(    self  ):
											_SCREAMING_SNAKE_CASE :       int     		=      MobileNetVaImageProcessingTester(self  )






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






							def UpperCAmelCase_	(    self  ):
											_SCREAMING_SNAKE_CASE :       str     		=      self.image_processing_class(**self.image_processor_dict  )
											self.assertTrue(hasattr(__snake_case    ,					"""do_resize"""  )  )
											self.assertTrue(hasattr(__snake_case    ,					"""size"""  )  )
											self.assertTrue(hasattr(__snake_case    ,					"""do_center_crop"""  )  )
											self.assertTrue(hasattr(__snake_case    ,					"""crop_size"""  )  )






							def UpperCAmelCase_	(    self  ):
											_SCREAMING_SNAKE_CASE :       str     		=      self.image_processing_class.from_dict(self.image_processor_dict  )
											self.assertEqual(image_processor.size    ,					{"""shortest_edge""": 20}  )
											self.assertEqual(image_processor.crop_size    ,					{"""height""": 18, """width""": 18}  )

											_SCREAMING_SNAKE_CASE :       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  ):
											pass






							def UpperCAmelCase_	(    self  ):
											# Initialize image_processing
											_SCREAMING_SNAKE_CASE :       str     		=      self.image_processing_class(**self.image_processor_dict  )
											# create random PIL images
											_SCREAMING_SNAKE_CASE :       List[str]     		=      prepare_image_inputs(self.image_processor_tester    ,					equal_resolution=__snake_case  )
											for image in image_inputs:
															self.assertIsInstance(__snake_case    ,					Image.Image  )

											# Test not batched input
											_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      image_processing(image_inputs[0]    ,					return_tensors="""pt"""  ).pixel_values
											self.assertEqual(
											    encoded_images.shape    ,					(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )    ,					)

											# Test batched
											_SCREAMING_SNAKE_CASE :       int     		=      image_processing(__snake_case    ,					return_tensors="""pt"""  ).pixel_values
											self.assertEqual(
											    encoded_images.shape    ,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )    ,					)






							def UpperCAmelCase_	(    self  ):
											# Initialize image_processing
											_SCREAMING_SNAKE_CASE :       Optional[int]     		=      self.image_processing_class(**self.image_processor_dict  )
											# create random numpy tensors
											_SCREAMING_SNAKE_CASE :       Tuple     		=      prepare_image_inputs(self.image_processor_tester    ,					equal_resolution=__snake_case    ,					numpify=__snake_case  )
											for image in image_inputs:
															self.assertIsInstance(__snake_case    ,					np.ndarray  )

											# Test not batched input
											_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      image_processing(image_inputs[0]    ,					return_tensors="""pt"""  ).pixel_values
											self.assertEqual(
											    encoded_images.shape    ,					(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )    ,					)

											# Test batched
											_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      image_processing(__snake_case    ,					return_tensors="""pt"""  ).pixel_values
											self.assertEqual(
											    encoded_images.shape    ,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )    ,					)






							def UpperCAmelCase_	(    self  ):
											# Initialize image_processing
											_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      self.image_processing_class(**self.image_processor_dict  )
											# create random PyTorch tensors
											_SCREAMING_SNAKE_CASE :       str     		=      prepare_image_inputs(self.image_processor_tester    ,					equal_resolution=__snake_case    ,					torchify=__snake_case  )
											for image in image_inputs:
															self.assertIsInstance(__snake_case    ,					torch.Tensor  )

											# Test not batched input
											_SCREAMING_SNAKE_CASE :       List[Any]     		=      image_processing(image_inputs[0]    ,					return_tensors="""pt"""  ).pixel_values
											self.assertEqual(
											    encoded_images.shape    ,					(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )    ,					)

											# Test batched
											_SCREAMING_SNAKE_CASE :       str     		=      image_processing(__snake_case    ,					return_tensors="""pt"""  ).pixel_values
											self.assertEqual(
											    encoded_images.shape    ,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )    ,					)




