






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


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import CLIPImageProcessor


class     _UpperCAmelCase  (						unittest.TestCase     ):




    def __init__(     self					:    Any					,       a					:    Any					,       a					:    List[Any]=7					,       a					:    int=3					,       a					:    str=1_8					,       a					:    Dict=3_0					,       a					:    Any=4_0_0					,       a					:    Any=True					,       a					:    Tuple=None					,       a					:    List[Any]=True					,       a					:    int=None					,       a					:    int=True					,       a					:    Dict=[0.4814_5466, 0.457_8275, 0.4082_1073]					,       a					:    List[str]=[0.2686_2954, 0.2613_0258, 0.2757_7711]					,       a					:    List[Any]=True					,       ):






       '''simple docstring'''






       lowercase_		:      Union[str, Any]          =       size if size is not None else {"shortest_edge": 2_0}
       lowercase_		:      Optional[Any]          =       crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}
       lowercase_		:      str          =       parent
       lowercase_		:      str          =       batch_size
       lowercase_		:      List[str]          =       num_channels
       lowercase_		:      Tuple          =       image_size
       lowercase_		:      int          =       min_resolution
       lowercase_		:      Union[str, Any]          =       max_resolution
       lowercase_		:      Any          =       do_resize
       lowercase_		:      List[str]          =       size
       lowercase_		:      Tuple          =       do_center_crop
       lowercase_		:      Optional[Any]          =       crop_size
       lowercase_		:      str          =       do_normalize
       lowercase_		:      List[Any]          =       image_mean
       lowercase_		:      int          =       image_std
       lowercase_		:      Optional[int]          =       do_convert_rgb




    def 			lowerCAmelCase__			(     self					:    List[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,
       }





    def 			lowerCAmelCase__			(     self					:    Any					,       a					:    Any=False					,       a					:    List[Any]=False					,       a					:    List[Any]=False     ):






       '''simple docstring'''






       assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

       if equal_resolution:
          lowercase_		:      Union[str, Any]          =       []
          for i in range(self.batch_size     ):
             image_inputs.append(
                 np.random.randint(
                     2_5_5					,       size=(self.num_channels, self.max_resolution, self.max_resolution)					,       dtype=np.uinta     )     )
       else:
          lowercase_		:      List[Any]          =       []
          for i in range(self.batch_size     ):
             lowercase_      ,						lowercase_		:      str          =       np.random.choice(np.arange(self.min_resolution					,       self.max_resolution     )					,       2     )
             image_inputs.append(np.random.randint(2_5_5					,       size=(self.num_channels, width, height)					,       dtype=np.uinta     )     )

       if not numpify and not torchify:
          # PIL expects the channel dimension as last dimension
          lowercase_		:      Optional[int]          =       [Image.fromarray(np.moveaxis(a					,       0					,       -1     )     ) for x in image_inputs]

       if torchify:
          lowercase_		:      int          =       [torch.from_numpy(a     ) for x in image_inputs]

       return image_inputs


@require_torch
@require_vision
class     _UpperCAmelCase  (						snake_case			,   unittest.TestCase     ):
    __lowerCamelCase:				Optional[Any]						    =      CLIPImageProcessor if is_vision_available() else None




    def 			lowerCAmelCase__			(     self					:    List[str]     ):






       '''simple docstring'''






       lowercase_		:      Optional[int]          =       CLIPImageProcessingTester(self     )




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






       '''simple docstring'''






       return self.image_processor_tester.prepare_image_processor_dict()




    def 			lowerCAmelCase__			(     self					:    Dict     ):






       '''simple docstring'''






       lowercase_		:      List[Any]          =       self.image_processing_class(**self.image_processor_dict     )
       self.assertTrue(hasattr(a					,       "do_resize"     )     )
       self.assertTrue(hasattr(a					,       "size"     )     )
       self.assertTrue(hasattr(a					,       "do_center_crop"     )     )
       self.assertTrue(hasattr(a					,       "center_crop"     )     )
       self.assertTrue(hasattr(a					,       "do_normalize"     )     )
       self.assertTrue(hasattr(a					,       "image_mean"     )     )
       self.assertTrue(hasattr(a					,       "image_std"     )     )
       self.assertTrue(hasattr(a					,       "do_convert_rgb"     )     )




    def 			lowerCAmelCase__			(     self					:    Tuple     ):






       '''simple docstring'''






       lowercase_		:      Optional[int]          =       self.image_processing_class.from_dict(self.image_processor_dict     )
       self.assertEqual(image_processor.size					,       {"shortest_edge": 2_0}     )
       self.assertEqual(image_processor.crop_size					,       {"height": 1_8, "width": 1_8}     )

       lowercase_		:      Tuple          =       self.image_processing_class.from_dict(self.image_processor_dict					,       size=4_2					,       crop_size=8_4     )
       self.assertEqual(image_processor.size					,       {"shortest_edge": 4_2}     )
       self.assertEqual(image_processor.crop_size					,       {"height": 8_4, "width": 8_4}     )




    def 			lowerCAmelCase__			(     self					:    Any     ):






       '''simple docstring'''






       pass




    def 			lowerCAmelCase__			(     self					:    Dict     ):






       '''simple docstring'''






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

       # Test not batched input
       lowercase_		:      Optional[int]          =       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
       lowercase_		:      int          =       image_processing(a					,       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 			lowerCAmelCase__			(     self					:    List[Any]     ):






       '''simple docstring'''






       lowercase_		:      str          =       self.image_processing_class(**self.image_processor_dict     )
       # create random numpy tensors
       lowercase_		:      Optional[int]          =       self.image_processor_tester.prepare_inputs(equal_resolution=a					,       numpify=a     )
       for image in image_inputs:
          self.assertIsInstance(a					,       np.ndarray     )

       # Test not batched input
       lowercase_		:      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
       lowercase_		:      Optional[Any]          =       image_processing(a					,       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 			lowerCAmelCase__			(     self					:    Dict     ):






       '''simple docstring'''






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

       # Test not batched input
       lowercase_		:      int          =       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
       lowercase_		:      Optional[int]          =       image_processing(a					,       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"],
           )					,       )


@require_torch
@require_vision
class     _UpperCAmelCase  (						snake_case			,   unittest.TestCase     ):
    __lowerCamelCase:				Union[str, Any]						    =      CLIPImageProcessor if is_vision_available() else None




    def 			lowerCAmelCase__			(     self					:    Optional[Any]     ):






       '''simple docstring'''






       lowercase_		:      Dict          =       CLIPImageProcessingTester(self					,       num_channels=4     )
       lowercase_		:      List[str]          =       3




    @property
    def 			lowerCAmelCase__			(     self					:    Any     ):






       '''simple docstring'''






       return self.image_processor_tester.prepare_image_processor_dict()




    def 			lowerCAmelCase__			(     self					:    Optional[int]     ):






       '''simple docstring'''






       lowercase_		:      str          =       self.image_processing_class(**self.image_processor_dict     )
       self.assertTrue(hasattr(a					,       "do_resize"     )     )
       self.assertTrue(hasattr(a					,       "size"     )     )
       self.assertTrue(hasattr(a					,       "do_center_crop"     )     )
       self.assertTrue(hasattr(a					,       "center_crop"     )     )
       self.assertTrue(hasattr(a					,       "do_normalize"     )     )
       self.assertTrue(hasattr(a					,       "image_mean"     )     )
       self.assertTrue(hasattr(a					,       "image_std"     )     )
       self.assertTrue(hasattr(a					,       "do_convert_rgb"     )     )




    def 			lowerCAmelCase__			(     self					:    Optional[Any]     ):






       '''simple docstring'''






       pass





    def 			lowerCAmelCase__			(     self					:    Optional[Any]     ):






       '''simple docstring'''






       lowercase_		:      int          =       self.image_processing_class(**self.image_processor_dict     )
       # create random PIL images
       lowercase_		:      Optional[Any]          =       self.image_processor_tester.prepare_inputs(equal_resolution=a     )
       for image in image_inputs:
          self.assertIsInstance(a					,       Image.Image     )

       # Test not batched input
       lowercase_		:      Dict          =       image_processing(image_inputs[0]					,       return_tensors="pt"     ).pixel_values
       self.assertEqual(
           encoded_images.shape					,       (
               1,
               self.expected_encoded_image_num_channels,
               self.image_processor_tester.crop_size["height"],
               self.image_processor_tester.crop_size["width"],
           )					,       )

       # Test batched
       lowercase_		:      str          =       image_processing(a					,       return_tensors="pt"     ).pixel_values
       self.assertEqual(
           encoded_images.shape					,       (
               self.image_processor_tester.batch_size,
               self.expected_encoded_image_num_channels,
               self.image_processor_tester.crop_size["height"],
               self.image_processor_tester.crop_size["width"],
           )					,       )












'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


UpperCamelCase__	=     {
    'configuration_unispeech_sat': ['UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'UniSpeechSatConfig'],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCamelCase__	=     [
     'UNISPEECH_SAT_PRETRAINED_MODEL_ARCHIVE_LIST',
     'UniSpeechSatForAudioFrameClassification',
     'UniSpeechSatForCTC',
     'UniSpeechSatForPreTraining',
     'UniSpeechSatForSequenceClassification',
     'UniSpeechSatForXVector',
     'UniSpeechSatModel',
     'UniSpeechSatPreTrainedModel',
 ]

if TYPE_CHECKING:
 from .configuration_unispeech_sat import UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP, UniSpeechSatConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_unispeech_sat import (
      UNISPEECH_SAT_PRETRAINED_MODEL_ARCHIVE_LIST,
      UniSpeechSatForAudioFrameClassification,
      UniSpeechSatForCTC,
      UniSpeechSatForPreTraining,
      UniSpeechSatForSequenceClassification,
      UniSpeechSatForXVector,
      UniSpeechSatModel,
      UniSpeechSatPreTrainedModel,
  )

else:
 import sys

 UpperCamelCase__	=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




