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


class 						__UpperCAmelCase      (					unittest.TestCase						):


							def __init__(       self    ,   lowerCAmelCase_    ,   lowerCAmelCase_=13    ,   lowerCAmelCase_=3    ,   lowerCAmelCase_=2_24    ,   lowerCAmelCase_=30    ,   lowerCAmelCase_=4_00    ,   lowerCAmelCase_=True    ,   lowerCAmelCase_=None    ,   lowerCAmelCase_=True    ,   lowerCAmelCase_=[0.5, 0.5, 0.5]    ,   lowerCAmelCase_=[0.5, 0.5, 0.5]    ,   ):





								"""simple docstring"""






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




							def  lowerCamelCase				(       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,
								}


@require_torch
@require_vision
class 						__UpperCAmelCase      (					_lowerCAmelCase						,   unittest.TestCase						):
							__lowercase      		=       ViTImageProcessor if is_vision_available() else None


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								_snake_case   						=		EfficientFormerImageProcessorTester(self  )


							@property
							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								return self.image_proc_tester.prepare_image_processor_dict()


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






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


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






								pass


							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






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

								# Test not batched input
								_snake_case   						=		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
								_snake_case   						=		image_processor(_lowerCamelCase    ,   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  lowerCamelCase				(       self  ):





								"""simple docstring"""






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

								# Test not batched input
								_snake_case   						=		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
								_snake_case   						=		image_processor(_lowerCamelCase    ,   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  lowerCamelCase				(       self  ):





								"""simple docstring"""






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

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









"""simple docstring"""


import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
       import ctypes
       import msvcrt  # noqa


       class 					snake_case		(							ctypes.Structure						):


          '''simple docstring'''

          A_						:	List[str]						 = [("size", ctypes.c_int), ("visible", ctypes.c_byte)]



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  if os.name == "nt":
    __A									= CursorInfo()
    __A									= ctypes.windll.kernelaa.GetStdHandle(-1_1 )
    ctypes.windll.kernelaa.GetConsoleCursorInfo(__UpperCamelCase		,       ctypes.byref(__UpperCamelCase ) )
    __A									= False
    ctypes.windll.kernelaa.SetConsoleCursorInfo(__UpperCamelCase		,       ctypes.byref(__UpperCamelCase ) )
  elif os.name == "posix":
    sys.stdout.write('''\033[?25l''' )
    sys.stdout.flush()



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  if os.name == "nt":
    __A									= CursorInfo()
    __A									= ctypes.windll.kernelaa.GetStdHandle(-1_1 )
    ctypes.windll.kernelaa.GetConsoleCursorInfo(__UpperCamelCase		,       ctypes.byref(__UpperCamelCase ) )
    __A									= True
    ctypes.windll.kernelaa.SetConsoleCursorInfo(__UpperCamelCase		,       ctypes.byref(__UpperCamelCase ) )
  elif os.name == "posix":
    sys.stdout.write('''\033[?25h''' )
    sys.stdout.flush()





@contextmanager
def 					lowerCAmelCase				(    ):




  """simple docstring"""







  try:
    hide_cursor()
    yield
  finally:
    show_cursor()




