


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 BlipImageProcessor
class      UpperCAmelCase_ ( unittest.TestCase   ):

   '''simple docstring'''




   def __init__(		self						,    __A						,    __A=7						,    __A=3						,    __A=18						,    __A=30						,    __A=400						,    __A=True						,    __A=None						,    __A=True						,    __A=False						,    __A=[0.48145466, 0.4578275, 0.40821073]						,    __A=[0.26862954, 0.26130258, 0.27577711]						,    __A=True						,    ):






     """simple docstring"""





     lowerCamelCase			: List[Any]   =    size if size is not None else {"height": 20, "width": 20}
     lowerCamelCase			: Union[str, Any]   =    parent
     lowerCamelCase			: List[Any]   =    batch_size
     lowerCamelCase			: Tuple   =    num_channels
     lowerCamelCase			: Optional[int]   =    image_size
     lowerCamelCase			: int   =    min_resolution
     lowerCamelCase			: Optional[int]   =    max_resolution
     lowerCamelCase			: int   =    do_resize
     lowerCamelCase			: Dict   =    size
     lowerCamelCase			: Any   =    do_normalize
     lowerCamelCase			: Tuple   =    image_mean
     lowerCamelCase			: List[Any]   =    image_std
     lowerCamelCase			: Dict   =    do_pad
     lowerCamelCase			: List[str]   =    do_convert_rgb






   def _snake_case   (		self			):






     """simple docstring"""





     return {
         "do_resize": self.do_resize,
         "size": self.size,
         "do_normalize": self.do_normalize,
         "image_mean": self.image_mean,
         "image_std": self.image_std,
         "do_convert_rgb": self.do_convert_rgb,
         "do_pad": self.do_pad,
     }






   def _snake_case   (		self						,    __A=False						,    __A=False						,    __A=False			):






     """simple docstring"""





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

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

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

     if torchify:
       lowerCamelCase			: Dict   =    [torch.from_numpy(lowercase__			) for x in image_inputs]

     return image_inputs



@require_torch
@require_vision
class      UpperCAmelCase_ ( UpperCamelCase		,			unittest.TestCase   ):

   '''simple docstring'''




   __A			:				List[Any]							=		BlipImageProcessor if is_vision_available() else None






   def _snake_case   (		self			):






     """simple docstring"""





     lowerCamelCase			: int   =    BlipImageProcessingTester(self			)






   @property
   def _snake_case   (		self			):






     """simple docstring"""





     return self.image_processor_tester.prepare_image_processor_dict()






   def _snake_case   (		self			):






     """simple docstring"""





     lowerCamelCase			: Tuple   =    self.image_processing_class(**self.image_processor_dict			)
     self.assertTrue(hasattr(lowercase__						,    "do_resize"			)			)
     self.assertTrue(hasattr(lowercase__						,    "size"			)			)
     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 _snake_case   (		self			):






     """simple docstring"""





     pass






   def _snake_case   (		self			):






     """simple docstring"""





     lowerCamelCase			: List[Any]   =    self.image_processing_class(**self.image_processor_dict			)
     # create random PIL images
     lowerCamelCase			: Union[str, Any]   =    self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__			)
     for image in image_inputs:
       self.assertIsInstance(lowercase__						,    Image.Image			)

     # Test not batched input
     lowerCamelCase			: Any   =    image_processor(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["height"],
             self.image_processor_tester.size["width"],
         )						,    )

     # Test batched
     lowerCamelCase			: str   =    image_processor(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.size["height"],
             self.image_processor_tester.size["width"],
         )						,    )






   def _snake_case   (		self			):






     """simple docstring"""





     lowerCamelCase			: List[Any]   =    self.image_processing_class(**self.image_processor_dict			)
     # create random numpy tensors
     lowerCamelCase			: List[Any]   =    self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__						,    numpify=lowercase__			)
     for image in image_inputs:
       self.assertIsInstance(lowercase__						,    np.ndarray			)

     # Test not batched input
     lowerCamelCase			: Optional[int]   =    image_processor(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["height"],
             self.image_processor_tester.size["width"],
         )						,    )

     # Test batched
     lowerCamelCase			: str   =    image_processor(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.size["height"],
             self.image_processor_tester.size["width"],
         )						,    )






   def _snake_case   (		self			):






     """simple docstring"""





     lowerCamelCase			: Optional[int]   =    self.image_processing_class(**self.image_processor_dict			)
     # create random PyTorch tensors
     lowerCamelCase			: Tuple   =    self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__						,    torchify=lowercase__			)
     for image in image_inputs:
       self.assertIsInstance(lowercase__						,    torch.Tensor			)

     # Test not batched input
     lowerCamelCase			: Any   =    image_processor(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["height"],
             self.image_processor_tester.size["width"],
         )						,    )

     # Test batched
     lowerCamelCase			: Optional[int]   =    image_processor(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.size["height"],
             self.image_processor_tester.size["width"],
         )						,    )



@require_torch
@require_vision
class      UpperCAmelCase_ ( UpperCamelCase		,			unittest.TestCase   ):

   '''simple docstring'''




   __A			:				int							=		BlipImageProcessor if is_vision_available() else None






   def _snake_case   (		self			):






     """simple docstring"""





     lowerCamelCase			: str   =    BlipImageProcessingTester(self						,    num_channels=4			)
     lowerCamelCase			: int   =    3






   @property
   def _snake_case   (		self			):






     """simple docstring"""





     return self.image_processor_tester.prepare_image_processor_dict()






   def _snake_case   (		self			):






     """simple docstring"""





     lowerCamelCase			: Optional[Any]   =    self.image_processing_class(**self.image_processor_dict			)
     self.assertTrue(hasattr(lowercase__						,    "do_resize"			)			)
     self.assertTrue(hasattr(lowercase__						,    "size"			)			)
     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 _snake_case   (		self			):






     """simple docstring"""





     pass






   def _snake_case   (		self			):






     """simple docstring"""





     lowerCamelCase			: Union[str, Any]   =    self.image_processing_class(**self.image_processor_dict			)
     # create random PIL images
     lowerCamelCase			: Any   =    self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__			)
     for image in image_inputs:
       self.assertIsInstance(lowercase__						,    Image.Image			)

     # Test not batched input
     lowerCamelCase			: str   =    image_processor(image_inputs[0]						,    return_tensors="pt"			).pixel_values
     self.assertEqual(
         encoded_images.shape						,    (
             1,
             self.expected_encoded_image_num_channels,
             self.image_processor_tester.size["height"],
             self.image_processor_tester.size["width"],
         )						,    )

     # Test batched
     lowerCamelCase			: List[Any]   =    image_processor(lowercase__						,    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.size["height"],
             self.image_processor_tester.size["width"],
         )						,    )







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


_snake_case					=					{'''configuration_hubert''': ['''HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''HubertConfig''']}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _snake_case					=					[
       '''HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''HubertForCTC''',
       '''HubertForSequenceClassification''',
       '''HubertModel''',
       '''HubertPreTrainedModel''',
   ]


try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _snake_case					=					[
       '''TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''TFHubertForCTC''',
       '''TFHubertModel''',
       '''TFHubertPreTrainedModel''',
   ]

if TYPE_CHECKING:
   from .configuration_hubert import HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, HubertConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_hubert import (
          HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          HubertForCTC,
          HubertForSequenceClassification,
          HubertModel,
          HubertPreTrainedModel,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_hubert import (
          TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFHubertForCTC,
          TFHubertModel,
          TFHubertPreTrainedModel,
      )


else:
   import sys

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



