



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       __lowerCamelCase	(   unittest.TestCase    ):







   def __init__(self       ,	lowerCamelCase       ,	lowerCamelCase=7       ,	lowerCamelCase=3       ,	lowerCamelCase=18       ,	lowerCamelCase=30       ,	lowerCamelCase=400       ,	lowerCamelCase=True       ,	lowerCamelCase=None       ,	lowerCamelCase=0.875       ,	lowerCamelCase=True       ,	lowerCamelCase=[0.5, 0.5, 0.5]       ,	lowerCamelCase=[0.5, 0.5, 0.5]       ,	):




      '''simple docstring'''




      _lowerCAmelCase					     =		size if size is not None else {"""shortest_edge""": 20}
      _lowerCAmelCase					     =		parent
      _lowerCAmelCase					     =		batch_size
      _lowerCAmelCase					     =		num_channels
      _lowerCAmelCase					     =		image_size
      _lowerCAmelCase					     =		min_resolution
      _lowerCAmelCase					     =		max_resolution
      _lowerCAmelCase					     =		do_resize
      _lowerCAmelCase					     =		size
      _lowerCAmelCase					     =		crop_pct
      _lowerCAmelCase					     =		do_normalize
      _lowerCAmelCase					     =		image_mean
      _lowerCAmelCase					     =		image_std







   def 							A__						(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,
          "crop_pct": self.crop_pct,
      }





@require_torch
@require_vision
class       __lowerCamelCase	(   __lowercase   ,							unittest.TestCase    ):
   __UpperCamelCase									=   ConvNextImageProcessor if is_vision_available() else None







   def 							A__						(self				):




      '''simple docstring'''




      _lowerCAmelCase					     =		ConvNextImageProcessingTester(self				)







   @property
   def 							A__						(self				):




      '''simple docstring'''




      return self.image_processor_tester.prepare_image_processor_dict()







   def 							A__						(self				):




      '''simple docstring'''




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







   def 							A__						(self				):




      '''simple docstring'''




      _lowerCAmelCase					     =		self.image_processing_class.from_dict(self.image_processor_dict				)
      self.assertEqual(image_processor.size       ,	{"""shortest_edge""": 20}				)

      _lowerCAmelCase					     =		self.image_processing_class.from_dict(self.image_processor_dict       ,	size=42				)
      self.assertEqual(image_processor.size       ,	{"""shortest_edge""": 42}				)







   def 							A__						(self				):




      '''simple docstring'''




      pass







   def 							A__						(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=lowerCamelCase				)
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase       ,	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.size["""shortest_edge"""],
              self.image_processor_tester.size["""shortest_edge"""],
          )       ,	)

      # Test batched
      _lowerCAmelCase					     =		image_processing(lowerCamelCase       ,	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 							A__						(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=lowerCamelCase       ,	numpify=lowerCamelCase				)
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase       ,	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.size["""shortest_edge"""],
              self.image_processor_tester.size["""shortest_edge"""],
          )       ,	)

      # Test batched
      _lowerCAmelCase					     =		image_processing(lowerCamelCase       ,	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 							A__						(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=lowerCamelCase       ,	torchify=lowerCamelCase				)
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase       ,	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.size["""shortest_edge"""],
              self.image_processor_tester.size["""shortest_edge"""],
          )       ,	)

      # Test batched
      _lowerCAmelCase					     =		image_processing(lowerCamelCase       ,	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"""],
          )       ,	)




"""simple docstring"""





def 	__UpperCAmelCase					(       snake_case_  :  float   )							->	int:






   """simple docstring"""


   return int(snake_case_   ) if x - int(snake_case_   ) <= 0 else int(snake_case_   ) + 1


if __name__ == "__main__":
  import doctest

  doctest.testmod()