



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





class        SCREAMING_SNAKE_CASE   (				unittest.TestCase ):
  """simple docstring"""







  def __init__(  self   :					List[Any]					,					__lowerCAmelCase   :					List[str]					,					__lowerCAmelCase   :					int=7					,					__lowerCAmelCase   :					Optional[int]=3					,					__lowerCAmelCase   :					Union[str, Any]=18					,					__lowerCAmelCase   :					List[str]=30					,					__lowerCAmelCase   :					Union[str, Any]=400					,					__lowerCAmelCase   :					List[str]=True					,					__lowerCAmelCase   :					Dict=None					,					__lowerCAmelCase   :					str=True					,					__lowerCAmelCase   :					Any=None					,					__lowerCAmelCase   :					Union[str, Any]=True					,					__lowerCAmelCase   :					Tuple=[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]					,					__lowerCAmelCase   :					Optional[int]=[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]					,					__lowerCAmelCase   :					List[str]=True					,					):


        """simple docstring"""



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



  def   a   (  self   :					int					):


        """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        SCREAMING_SNAKE_CASE   (				__UpperCAmelCase	,						unittest.TestCase ):
  """simple docstring"""







  __A     =		OwlViTImageProcessor if is_vision_available() else None



  def   a   (  self   :					int					):


        """simple docstring"""



        _lowerCAmelCase		   =   OwlViTImageProcessingTester(self					)



  @property
  def   a   (  self   :					List[Any]					):


        """simple docstring"""



        return self.image_processor_tester.prepare_image_processor_dict()



  def   a   (  self   :					Union[str, Any]					):


        """simple docstring"""



        _lowerCAmelCase		   =   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   a   (  self   :					Union[str, Any]					):


        """simple docstring"""



        _lowerCAmelCase		   =   self.image_processing_class.from_dict(self.image_processor_dict					)
        self.assertEqual(image_processor.size					,					{'height': 18, 'width': 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					,					{'height': 42, 'width': 42}					)
        self.assertEqual(image_processor.crop_size					,					{'height': 84, 'width': 84}					)



  def   a   (  self   :					Union[str, Any]					):


        """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   a   (  self   :					Optional[int]					):


        """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   a   (  self   :					Union[str, Any]					):


        """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'],
            )					,					)






'''simple docstring'''




import unittest

from transformers import is_torch_available, load_tool

from .test_tools_common import ToolTesterMixin


if is_torch_available():
 import torch





class        SCREAMING_SNAKE_CASE   (				unittest.TestCase	,						__a ):
  """simple docstring"""







  def   a   (  self   :					List[str]					):


        """simple docstring"""



        _lowerCAmelCase		   =   load_tool('speech-to-text'					)
        self.tool.setup()



  def   a   (  self   :					Any					):


        """simple docstring"""



        _lowerCAmelCase		   =   self.tool(torch.ones(3000					)					)
        self.assertEqual(__lowerCAmelCase					,					' you'					)



  def   a   (  self   :					Optional[int]					):


        """simple docstring"""



        _lowerCAmelCase		   =   self.tool(audio=torch.ones(3000					)					)
        self.assertEqual(__lowerCAmelCase					,					' you'					)





