





'''simple docstring'''







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

from tqdm import auto as tqdm_lib


snake_case_       :    Tuple          =					threading.Lock()
snake_case_       :    Dict          =					None

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

snake_case_       :    Dict          =					logging.WARNING

snake_case_       :    str          =					True





def     lowerCamelCase_ (					)	->		Optional[Any]:
						UpperCAmelCase_     : str         =					os.getenv('''DIFFUSERS_VERBOSITY''',     __UpperCamelCase				)
						if env_level_str:
												if env_level_str in log_levels:
																		return log_levels[env_level_str]
												else:
																		logging.getLogger().warning(
																		    F"""Unknown option DIFFUSERS_VERBOSITY={env_level_str}, """
																		    F"""has to be one of: { ", ".join(log_levels.keys()				) }"""				)
						return _default_log_level





def     lowerCamelCase_ (					)	->		Any:
						return __name__.split('''.'''				)[0]





def     lowerCamelCase_ (					)	->		Any:
						return logging.getLogger(_get_library_name()				)





def     lowerCamelCase_ (					)	->		Union[str, Any]:
						global _default_handler

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

												# Apply our default configuration to the library root logger.
												UpperCAmelCase_     : int         =					_get_library_root_logger()
												library_root_logger.addHandler(_default_handler				)
												library_root_logger.setLevel(_get_default_logging_level()				)
												UpperCAmelCase_     : Any         =					False





def     lowerCamelCase_ (					)	->		List[Any]:
						global _default_handler

						with _lock:
												if not _default_handler:
																		return

												UpperCAmelCase_     : Optional[int]         =					_get_library_root_logger()
												library_root_logger.removeHandler(_default_handler				)
												library_root_logger.setLevel(logging.NOTSET				)
												UpperCAmelCase_     : Any         =					None





def     lowerCamelCase_ (					)	->		List[str]:
						return log_levels





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     Optional[Any] = None				)	->		Any:







						if name is None:
												UpperCAmelCase_     : Optional[Any]         =					_get_library_name()

						_configure_library_root_logger()
						return logging.getLogger(__UpperCamelCase				)





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





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     Union[str, Any]				)	->		List[str]:
						_configure_library_root_logger()
						_get_library_root_logger().setLevel(__UpperCamelCase				)





def     lowerCamelCase_ (					)	->		Tuple:
						return set_verbosity(__UpperCamelCase				)





def     lowerCamelCase_ (					)	->		Union[str, Any]:
						return set_verbosity(__UpperCamelCase				)





def     lowerCamelCase_ (					)	->		Tuple:
						return set_verbosity(__UpperCamelCase				)





def     lowerCamelCase_ (					)	->		Tuple:
						return set_verbosity(__UpperCamelCase				)





def     lowerCamelCase_ (					)	->		Tuple:
						_configure_library_root_logger()

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





def     lowerCamelCase_ (					)	->		str:
						_configure_library_root_logger()

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





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     List[Any]				)	->		List[str]:
						_configure_library_root_logger()

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





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     Union[str, Any]				)	->		Any:
						_configure_library_root_logger()

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





def     lowerCamelCase_ (					)	->		Dict:
						_configure_library_root_logger()
						UpperCAmelCase_     : Any         =					False





def     lowerCamelCase_ (					)	->		Optional[int]:
						_configure_library_root_logger()
						UpperCAmelCase_     : Optional[int]         =					True





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

						for handler in handlers:
												UpperCAmelCase_     : Any         =					logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'''				)
												handler.setFormatter(__UpperCamelCase				)





def     lowerCamelCase_ (					)	->		List[str]:
						UpperCAmelCase_     : Union[str, Any]         =					_get_library_root_logger().handlers

						for handler in handlers:
												handler.setFormatter(__UpperCamelCase				)





def     lowerCamelCase_ (					self :     str,     *SCREAMING_SNAKE_CASE__ :     int,     **SCREAMING_SNAKE_CASE__ :     Any				)	->		Optional[Any]:
						UpperCAmelCase_     : Dict         =					os.getenv('''DIFFUSERS_NO_ADVISORY_WARNINGS''',     __UpperCamelCase				)
						if no_advisory_warnings:
												return
						self.warning(*__UpperCamelCase,     **__UpperCamelCase				)


snake_case_       :    Dict          =					warning_advice


class    __a :

							def __init__(							self							:       Union[str, Any]    ,       *__magic_name__							:       Optional[Any]    ,       **__magic_name__							:       Dict				)   ->    Union[str, Any]:  # pylint: disable=unused-argument







													"""simple docstring"""
													UpperCAmelCase_     : Optional[int]         =					args[0] if args else None

							def __iter__(							self							:       Optional[Any]				)   ->    Tuple:







													"""simple docstring"""
													return iter(self._iterator				)

							def __getattr__(							self							:       Optional[int]    ,       __magic_name__							:       Optional[Any]				)   ->    Dict:







													"""simple docstring"""

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

													return empty_fn

							def __enter__(							self							:       List[Any]				)   ->    str:







													"""simple docstring"""
													return self



							def __exit__(							self							:       Union[str, Any]    ,       __magic_name__							:       str    ,       __magic_name__							:       Optional[int]    ,       __magic_name__							:       Any				)   ->    Dict:







													"""simple docstring"""
													return





class    __a :

							def __call__(							self							:       Union[str, Any]    ,       *__magic_name__							:       Any    ,       **__magic_name__							:       List[str]				)   ->    str:







													"""simple docstring"""
													if _tqdm_active:
																			return tqdm_lib.tqdm(*_lowerCamelCase    ,       **_lowerCamelCase				)
													else:
																			return EmptyTqdm(*_lowerCamelCase    ,       **_lowerCamelCase				)

							def       UpperCAmelCase__		(							self							:       List[str]    ,       *__magic_name__							:       Dict    ,       **__magic_name__							:       List[Any]				)   ->    Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_     : Optional[int]         =					None
													if _tqdm_active:
																			return tqdm_lib.tqdm.set_lock(*_lowerCamelCase    ,       **_lowerCamelCase				)



							def       UpperCAmelCase__		(							self							:       int				)   ->    str:







													"""simple docstring"""
													if _tqdm_active:
																			return tqdm_lib.tqdm.get_lock()





snake_case_       :    Dict          =					_tqdm_cls()





def     lowerCamelCase_ (					)	->		Optional[Any]:
						global _tqdm_active
						return bool(_tqdm_active				)





def     lowerCamelCase_ (					)	->		Dict:
						global _tqdm_active
						UpperCAmelCase_     : int         =					True





def     lowerCamelCase_ (					)	->		Any:
						global _tqdm_active
						UpperCAmelCase_     : Tuple         =					False








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


class    __a (unittest.TestCase       ):

							def __init__(							self							:       Dict    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       str=7    ,       __magic_name__							:       Optional[int]=3    ,       __magic_name__							:       Union[str, Any]=18    ,       __magic_name__							:       Dict=30    ,       __magic_name__							:       List[Any]=4_00    ,       __magic_name__							:       Dict=True    ,       __magic_name__							:       Union[str, Any]=None    ,       __magic_name__							:       Optional[Any]=0.8_7_5    ,       __magic_name__							:       List[Any]=True    ,       __magic_name__							:       Optional[int]=[0.5, 0.5, 0.5]    ,       __magic_name__							:       Optional[int]=[0.5, 0.5, 0.5]    ,       )   ->    Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : str         =					size if size is not None else {'''shortest_edge''': 20}
													UpperCAmelCase_     : Optional[Any]         =					parent
													UpperCAmelCase_     : Any         =					batch_size
													UpperCAmelCase_     : Optional[Any]         =					num_channels
													UpperCAmelCase_     : Optional[Any]         =					image_size
													UpperCAmelCase_     : Optional[int]         =					min_resolution
													UpperCAmelCase_     : Optional[Any]         =					max_resolution
													UpperCAmelCase_     : Optional[int]         =					do_resize
													UpperCAmelCase_     : Optional[Any]         =					size
													UpperCAmelCase_     : int         =					crop_pct
													UpperCAmelCase_     : Optional[int]         =					do_normalize
													UpperCAmelCase_     : Dict         =					image_mean
													UpperCAmelCase_     : int         =					image_std



							def       UpperCAmelCase__		(							self							:       Optional[int]				)   ->    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,
													    "crop_pct": self.crop_pct,
													}





@require_torch
@require_vision
class    __a (lowerCamelCase    ,						unittest.TestCase       ):
							__a   :				Dict       =    ConvNextImageProcessor if is_vision_available() else None

							def       UpperCAmelCase__		(							self							:       Optional[int]				)   ->    Dict:







													"""simple docstring"""
													UpperCAmelCase_     : str         =					ConvNextImageProcessingTester(self				)

							@property
							def       UpperCAmelCase__		(							self							:       List[Any]				)   ->    Any:







													"""simple docstring"""
													return self.image_processor_tester.prepare_image_processor_dict()

							def       UpperCAmelCase__		(							self							:       List[Any]				)   ->    Tuple:







													"""simple docstring"""
													UpperCAmelCase_     : Dict         =					self.image_processing_class(**self.image_processor_dict				)
													self.assertTrue(hasattr(__magic_name__    ,       '''do_resize'''				)				)
													self.assertTrue(hasattr(__magic_name__    ,       '''size'''				)				)
													self.assertTrue(hasattr(__magic_name__    ,       '''crop_pct'''				)				)
													self.assertTrue(hasattr(__magic_name__    ,       '''do_normalize'''				)				)
													self.assertTrue(hasattr(__magic_name__    ,       '''image_mean'''				)				)
													self.assertTrue(hasattr(__magic_name__    ,       '''image_std'''				)				)

							def       UpperCAmelCase__		(							self							:       Dict				)   ->    List[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					self.image_processing_class.from_dict(self.image_processor_dict				)
													self.assertEqual(image_processor.size    ,       {'''shortest_edge''': 20}				)

													UpperCAmelCase_     : List[Any]         =					self.image_processing_class.from_dict(self.image_processor_dict    ,       size=42				)
													self.assertEqual(image_processor.size    ,       {'''shortest_edge''': 42}				)

							def       UpperCAmelCase__		(							self							:       str				)   ->    Optional[int]:







													"""simple docstring"""
													pass

							def       UpperCAmelCase__		(							self							:       List[str]				)   ->    int:







													"""simple docstring"""
													# Initialize image_processing
													UpperCAmelCase_     : int         =					self.image_processing_class(**self.image_processor_dict				)
													# create random PIL images
													UpperCAmelCase_     : List[Any]         =					prepare_image_inputs(self.image_processor_tester    ,       equal_resolution=__magic_name__				)
													for image in image_inputs:
																			self.assertIsInstance(__magic_name__    ,       Image.Image				)

													# Test not batched input
													UpperCAmelCase_     : int         =					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.size['''shortest_edge'''],
													        self.image_processor_tester.size['''shortest_edge'''],
													    )    ,       )

													# Test batched
													UpperCAmelCase_     : Tuple         =					image_processing(__magic_name__    ,       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.size['''shortest_edge'''],
													        self.image_processor_tester.size['''shortest_edge'''],
													    )    ,       )

							def       UpperCAmelCase__		(							self							:       str				)   ->    Optional[int]:







													"""simple docstring"""
													# Initialize image_processing
													UpperCAmelCase_     : Optional[Any]         =					self.image_processing_class(**self.image_processor_dict				)
													# create random numpy tensors
													UpperCAmelCase_     : Tuple         =					prepare_image_inputs(self.image_processor_tester    ,       equal_resolution=__magic_name__    ,       numpify=__magic_name__				)
													for image in image_inputs:
																			self.assertIsInstance(__magic_name__    ,       np.ndarray				)

													# Test not batched input
													UpperCAmelCase_     : int         =					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.size['''shortest_edge'''],
													        self.image_processor_tester.size['''shortest_edge'''],
													    )    ,       )

													# Test batched
													UpperCAmelCase_     : Union[str, Any]         =					image_processing(__magic_name__    ,       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.size['''shortest_edge'''],
													        self.image_processor_tester.size['''shortest_edge'''],
													    )    ,       )



							def       UpperCAmelCase__		(							self							:       str				)   ->    int:







													"""simple docstring"""
													# Initialize image_processing
													UpperCAmelCase_     : Union[str, Any]         =					self.image_processing_class(**self.image_processor_dict				)
													# create random PyTorch tensors
													UpperCAmelCase_     : List[Any]         =					prepare_image_inputs(self.image_processor_tester    ,       equal_resolution=__magic_name__    ,       torchify=__magic_name__				)
													for image in image_inputs:
																			self.assertIsInstance(__magic_name__    ,       torch.Tensor				)

													# Test not batched input
													UpperCAmelCase_     : 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.size['''shortest_edge'''],
													        self.image_processor_tester.size['''shortest_edge'''],
													    )    ,       )

													# Test batched
													UpperCAmelCase_     : str         =					image_processing(__magic_name__    ,       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.size['''shortest_edge'''],
													        self.image_processor_tester.size['''shortest_edge'''],
													    )    ,       )





