


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       :			int							,     _a       :			Optional[Any]							,     _a       :			List[str]=7							,     _a       :			str=3							,     _a       :			str=1_8							,     _a       :			Union[str, Any]=3_0							,     _a       :			str=4_0_0							,     _a       :			List[Any]=True							,     _a       :			Union[str, Any]=None							,     _a       :			Union[str, Any]=True							,     _a       :			Dict=None							,     _a       :			Tuple=True							,     _a       :			Optional[int]=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]							,     _a       :			List[Any]=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]							,     _a       :			List[str]=True							,     )     ->      str:
      UpperCAmelCase    :					Dict			=      parent
      UpperCAmelCase    :					List[Any]			=      batch_size
      UpperCAmelCase    :					str			=      num_channels
      UpperCAmelCase    :					Dict			=      image_size
      UpperCAmelCase    :					List[Any]			=      min_resolution
      UpperCAmelCase    :					List[str]			=      max_resolution
      UpperCAmelCase    :					Union[str, Any]			=      do_resize
      UpperCAmelCase    :					Dict			=      size if size is not None else {"height": 1_8, "width": 1_8}
      UpperCAmelCase    :					Tuple			=      do_center_crop
      UpperCAmelCase    :					str			=      crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}
      UpperCAmelCase    :					Tuple			=      do_normalize
      UpperCAmelCase    :					str			=      image_mean
      UpperCAmelCase    :					Any			=      image_std
      UpperCAmelCase    :					Optional[int]			=      do_convert_rgb

 def 	_UpperCamelCase     (      self       :			int					)     ->      Optional[int]:
      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_ (			lowerCamelCase_   ,    unittest.TestCase  ):







 """simple docstring"""





 _UpperCamelCase					:			List[Any]     	=       OwlViTImageProcessor if is_vision_available() else None
 def 	_UpperCamelCase     (      self       :			Tuple					)     ->      Any:
      UpperCAmelCase    :					List[str]			=      OwlViTImageProcessingTester(self					)
 @property
 def 	_UpperCamelCase     (      self       :			List[Any]					)     ->      Union[str, Any]:
      return self.image_processor_tester.prepare_image_processor_dict()
 def 	_UpperCamelCase     (      self       :			str					)     ->      Dict:
      UpperCAmelCase    :					List[str]			=      self.image_processing_class(**self.image_processor_dict					)
      self.assertTrue(hasattr(_lowercase							,     "do_resize"					)					)
      self.assertTrue(hasattr(_lowercase							,     "size"					)					)
      self.assertTrue(hasattr(_lowercase							,     "do_center_crop"					)					)
      self.assertTrue(hasattr(_lowercase							,     "center_crop"					)					)
      self.assertTrue(hasattr(_lowercase							,     "do_normalize"					)					)
      self.assertTrue(hasattr(_lowercase							,     "image_mean"					)					)
      self.assertTrue(hasattr(_lowercase							,     "image_std"					)					)
      self.assertTrue(hasattr(_lowercase							,     "do_convert_rgb"					)					)
 def 	_UpperCamelCase     (      self       :			List[str]					)     ->      List[Any]:
      UpperCAmelCase    :					Optional[Any]			=      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}					)

      UpperCAmelCase    :					Optional[int]			=      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       :			List[str]					)     ->      Any:
      UpperCAmelCase    :					Union[str, Any]			=      self.image_processing_class(**self.image_processor_dict					)
      # create random PIL images
      UpperCAmelCase    :					Union[str, Any]			=      prepare_image_inputs(self.image_processor_tester							,     equal_resolution=_lowercase					)

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

      # Test not batched input
      UpperCAmelCase    :					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.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )							,     )

      # Test batched
      UpperCAmelCase    :					Optional[Any]			=      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     (      self       :			Optional[int]					)     ->      str:
      UpperCAmelCase    :					Dict			=      self.image_processing_class(**self.image_processor_dict					)
      # create random numpy tensors
      UpperCAmelCase    :					Union[str, Any]			=      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
      UpperCAmelCase    :					Dict			=      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
      UpperCAmelCase    :					List[Any]			=      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     (      self       :			Union[str, Any]					)     ->      Tuple:
      UpperCAmelCase    :					Union[str, Any]			=      self.image_processing_class(**self.image_processor_dict					)
      # create random PyTorch tensors
      UpperCAmelCase    :					List[str]			=      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
      UpperCAmelCase    :					List[str]			=      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
      UpperCAmelCase    :					Union[str, Any]			=      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"],
          )							,     )




import unittest

from transformers import is_torch_available, load_tool

from .test_tools_common import ToolTesterMixin


if is_torch_available():
   import torch







class __snake_case							(		unittest.TestCase  ,						lowerCamelCase_						):




   def       __a		(       self     :							Dict ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= load_tool("""speech-to-text""" )
     self.tool.setup()




   def       __a		(       self     :							Tuple ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.tool(torch.ones(30_00 ) )
     self.assertEqual(_lowercase			,      """ you""" )




   def       __a		(       self     :							Any ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.tool(audio=torch.ones(30_00 ) )
     self.assertEqual(_lowercase			,      """ you""" )
