






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 OwlViTImageProcessor
class 	a_(		unittest.TestCase	):



     """simple docstring"""



     def __init__(		self					:	Optional[int]  ,  lowerCAmelCase__					:	Dict  ,  lowerCAmelCase__					:	List[str]=7  ,  lowerCAmelCase__					:	Any=3  ,  lowerCAmelCase__					:	Optional[Any]=1_8  ,  lowerCAmelCase__					:	Dict=3_0  ,  lowerCAmelCase__					:	Optional[int]=4_0_0  ,  lowerCAmelCase__					:	int=True  ,  lowerCAmelCase__					:	str=None  ,  lowerCAmelCase__					:	List[Any]=True  ,  lowerCAmelCase__					:	Optional[int]=None  ,  lowerCAmelCase__					:	Optional[int]=True  ,  lowerCAmelCase__					:	str=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]  ,  lowerCAmelCase__					:	Any=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]  ,  lowerCAmelCase__					:	Optional[int]=True  ,  )							->	Union[str, Any]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE				    =		parent
      SCREAMING_SNAKE_CASE				    =		batch_size
      SCREAMING_SNAKE_CASE				    =		num_channels
      SCREAMING_SNAKE_CASE				    =		image_size
      SCREAMING_SNAKE_CASE				    =		min_resolution
      SCREAMING_SNAKE_CASE				    =		max_resolution
      SCREAMING_SNAKE_CASE				    =		do_resize
      SCREAMING_SNAKE_CASE				    =		size if size is not None else {'height': 1_8, 'width': 1_8}
      SCREAMING_SNAKE_CASE				    =		do_center_crop
      SCREAMING_SNAKE_CASE				    =		crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}
      SCREAMING_SNAKE_CASE				    =		do_normalize
      SCREAMING_SNAKE_CASE				    =		image_mean
      SCREAMING_SNAKE_CASE				    =		image_std
      SCREAMING_SNAKE_CASE				    =		do_convert_rgb





     def     __UpperCamelCase						(		self					:	Dict)							->	Any:

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

@require_torch
@require_vision
class 	a_(		lowercase__			,							unittest.TestCase	):



     """simple docstring"""



     __snake_case		:				Tuple  					=OwlViTImageProcessor if is_vision_available() else None





     def     __UpperCamelCase						(		self					:	Tuple)							->	Dict:

      """simple docstring"""
      SCREAMING_SNAKE_CASE				    =		OwlViTImageProcessingTester(self)





     @property
     def     __UpperCamelCase						(		self					:	int)							->	Any:

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





     def     __UpperCamelCase						(		self					:	Optional[Any])							->	List[Any]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE				    =		self.image_processing_class(**self.image_processor_dict)
      self.assertTrue(hasattr(lowerCAmelCase__  ,  'do_resize'))
      self.assertTrue(hasattr(lowerCAmelCase__  ,  'size'))
      self.assertTrue(hasattr(lowerCAmelCase__  ,  'do_center_crop'))
      self.assertTrue(hasattr(lowerCAmelCase__  ,  'center_crop'))
      self.assertTrue(hasattr(lowerCAmelCase__  ,  'do_normalize'))
      self.assertTrue(hasattr(lowerCAmelCase__  ,  'image_mean'))
      self.assertTrue(hasattr(lowerCAmelCase__  ,  'image_std'))
      self.assertTrue(hasattr(lowerCAmelCase__  ,  'do_convert_rgb'))





     def     __UpperCamelCase						(		self					:	Optional[int])							->	Tuple:

      """simple docstring"""
      SCREAMING_SNAKE_CASE				    =		self.image_processing_class.from_dict(self.image_processor_dict)
      self.assertEqual(image_processor.size  ,  {'height': 1_8, 'width': 1_8})
      self.assertEqual(image_processor.crop_size  ,  {'height': 1_8, 'width': 1_8})

      SCREAMING_SNAKE_CASE				    =		self.image_processing_class.from_dict(self.image_processor_dict  ,  size=4_2  ,  crop_size=8_4)
      self.assertEqual(image_processor.size  ,  {'height': 4_2, 'width': 4_2})
      self.assertEqual(image_processor.crop_size  ,  {'height': 8_4, 'width': 8_4})





     def     __UpperCamelCase						(		self					:	Tuple)							->	Union[str, Any]:

      """simple docstring"""
      # Initialize image_processing
      SCREAMING_SNAKE_CASE				    =		self.image_processing_class(**self.image_processor_dict)
      # create random PIL images
      SCREAMING_SNAKE_CASE				    =		prepare_image_inputs(self.image_processor_tester  ,  equal_resolution=lowerCAmelCase__)

      for image in image_inputs:
       self.assertIsInstance(lowerCAmelCase__  ,  Image.Image)

      # Test not batched input
      SCREAMING_SNAKE_CASE				    =		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				    =		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.crop_size['height'],
              self.image_processor_tester.crop_size['width'],
          )  ,  )





     def     __UpperCamelCase						(		self					:	Dict)							->	Optional[Any]:

      """simple docstring"""
      # Initialize image_processing
      SCREAMING_SNAKE_CASE				    =		self.image_processing_class(**self.image_processor_dict)
      # create random numpy tensors
      SCREAMING_SNAKE_CASE				    =		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
      SCREAMING_SNAKE_CASE				    =		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				    =		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.crop_size['height'],
              self.image_processor_tester.crop_size['width'],
          )  ,  )





     def     __UpperCamelCase						(		self					:	Dict)							->	Dict:

      """simple docstring"""
      # Initialize image_processing
      SCREAMING_SNAKE_CASE				    =		self.image_processing_class(**self.image_processor_dict)
      # create random PyTorch tensors
      SCREAMING_SNAKE_CASE				    =		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
      SCREAMING_SNAKE_CASE				    =		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				    =		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.crop_size['height'],
              self.image_processor_tester.crop_size['width'],
          )  ,  )












# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
__UpperCAmelCase      =				abspath(join(dirname(dirname(dirname(__file__))), "src"))
sys.path.insert(1, git_repo_path)


# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action="ignore", category=FutureWarning)





def 						A_					(						lowercase_			)				->str:







 """simple docstring"""

 from transformers.testing_utils import pytest_addoption_shared

 pytest_addoption_shared(lowercase_			)





def 						A_					(						lowercase_			)				->Tuple:







 """simple docstring"""

 from transformers.testing_utils import pytest_terminal_summary_main

 SCREAMING_SNAKE_CASE				    =		terminalreporter.config.getoption('--make-reports'			)
 if make_reports:
  pytest_terminal_summary_main(lowercase_	,  id=lowercase_			)




