



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 LevitImageProcessor





class 					__lowerCAmelCase (     unittest.TestCase       ):




				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						,				_snake_case=True						,				_snake_case=[0.5, 0.5, 0.5]						,				_snake_case=[0.5, 0.5, 0.5]						,				):



									"""simple docstring"""





									_lowerCAmelCase						=    size if size is not None else {"""shortest_edge""": 18}
									_lowerCAmelCase						=    crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
									_lowerCAmelCase						=    parent
									_lowerCAmelCase						=    batch_size
									_lowerCAmelCase						=    num_channels
									_lowerCAmelCase						=    image_size
									_lowerCAmelCase						=    min_resolution
									_lowerCAmelCase						=    max_resolution
									_lowerCAmelCase						=    do_resize
									_lowerCAmelCase						=    size
									_lowerCAmelCase						=    do_center_crop
									_lowerCAmelCase						=    crop_size
									_lowerCAmelCase						=    do_normalize
									_lowerCAmelCase						=    image_mean
									_lowerCAmelCase						=    image_std




				def 							snake_case   (							self		):



									"""simple docstring"""





									return {
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									    "do_normalize": self.do_normalize,
									    "do_resize": self.do_resize,
									    "do_center_crop": self.do_center_crop,
									    "size": self.size,
									    "crop_size": self.crop_size,
									}





@require_torch
@require_vision
class 					__lowerCAmelCase (     lowerCamelCase__       ,						unittest.TestCase       ):
				__lowerCamelCase =				LevitImageProcessor if is_vision_available() else None




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    LevitImageProcessingTester(self		)




				@property
				def 							snake_case   (							self		):



									"""simple docstring"""





									return self.image_processor_tester.prepare_image_processor_dict()




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.image_processing_class(**self.image_processor_dict		)
									self.assertTrue(hasattr(lowercase_						,				"""image_mean"""		)		)
									self.assertTrue(hasattr(lowercase_						,				"""image_std"""		)		)
									self.assertTrue(hasattr(lowercase_						,				"""do_normalize"""		)		)
									self.assertTrue(hasattr(lowercase_						,				"""do_resize"""		)		)
									self.assertTrue(hasattr(lowercase_						,				"""do_center_crop"""		)		)
									self.assertTrue(hasattr(lowercase_						,				"""size"""		)		)




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    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}		)

									_lowerCAmelCase						=    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 							snake_case   (							self		):



									"""simple docstring"""





									pass




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.image_processing_class(**self.image_processor_dict		)
									# create random PIL images
									_lowerCAmelCase						=    prepare_image_inputs(self.image_processor_tester						,				equal_resolution=lowercase_		)
									for image in image_inputs:
														self.assertIsInstance(lowercase_						,				Image.Image		)

									# Test not batched input
									_lowerCAmelCase						=    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
									_lowerCAmelCase						=    image_processing(lowercase_						,				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 							snake_case   (							self		):



									"""simple docstring"""





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

									# Test not batched input
									_lowerCAmelCase						=    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
									_lowerCAmelCase						=    image_processing(lowercase_						,				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 							snake_case   (							self		):



									"""simple docstring"""





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

									# Test not batched input
									_lowerCAmelCase						=    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
									_lowerCAmelCase						=    image_processing(lowercase_						,				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__				(			_A      : dict							):





  '''simple docstring'''







  a__  =set()
  # To detect a back edge, keep track of vertices currently in the recursion stack
  a__  =set()
  return any(
      node not in visited and depth_first_search(_A	,      _A	,      _A	,      _A							)
      for node in graph							)




def 			UpperCAmelCase__				(			_A      : dict	,      _A      : int	,      _A      : set	,      _A      : set							):





  '''simple docstring'''







  visited.add(_A							)
  rec_stk.add(_A							)

  for node in graph[vertex]:
    if node not in visited:
      if depth_first_search(_A	,      _A	,      _A	,      _A							):
        return True
    elif node in rec_stk:
      return True

    # The node needs to be removed from recursion stack before function ends
  rec_stk.remove(_A							)
  return False


if __name__ == "__main__":
       from doctest import testmod

       testmod()
