





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 			__A(    unittest.TestCase			):

     def __init__(   self,							A,							A=7,							A=3,							A=18,							A=30,							A=400,							A=True,							A=None,							A=True,							A=False,							A=[0.48_145_466, 0.4_578_275, 0.40_821_073],							A=[0.26_862_954, 0.26_130_258, 0.27_577_711],							A=True,							):





            """simple docstring"""

            _UpperCamelCase														=    size if size is not None else {'''height''': 20, '''width''': 20}
            _UpperCamelCase														=    parent
            _UpperCamelCase														=    batch_size
            _UpperCamelCase														=    num_channels
            _UpperCamelCase														=    image_size
            _UpperCamelCase														=    min_resolution
            _UpperCamelCase														=    max_resolution
            _UpperCamelCase														=    do_resize
            _UpperCamelCase														=    size
            _UpperCamelCase														=    do_normalize
            _UpperCamelCase														=    image_mean
            _UpperCamelCase														=    image_std
            _UpperCamelCase														=    do_pad
            _UpperCamelCase														=    do_convert_rgb

     def 						_UpperCamelCase  (   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 						_UpperCamelCase  (   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:
                   _UpperCamelCase														=    []
                   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:
                   _UpperCamelCase														=    []
                   for i in range(self.batch_size   ):
                          _UpperCamelCase							,		_UpperCamelCase														=    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
                   _UpperCamelCase														=    [Image.fromarray(np.moveaxis(A__,							0,							-1   )   ) for x in image_inputs]

            if torchify:
                   _UpperCamelCase														=    [torch.from_numpy(A__   ) for x in image_inputs]

            return image_inputs






@require_torch
@require_vision
class 			__A(    __lowercase    ,      unittest.TestCase			):
     __A							=							BlipImageProcessor if is_vision_available() else None

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    BlipImageProcessingTester(self   )

     @property
     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            return self.image_processor_tester.prepare_image_processor_dict()

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    self.image_processing_class(**self.image_processor_dict   )
            self.assertTrue(hasattr(A__,							'''do_resize'''   )   )
            self.assertTrue(hasattr(A__,							'''size'''   )   )
            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 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            pass

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

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

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

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    self.image_processing_class(**self.image_processor_dict   )
            # create random numpy tensors
            _UpperCamelCase														=    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
            _UpperCamelCase														=    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
            _UpperCamelCase														=    image_processor(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.size['''height'''],
                    self.image_processor_tester.size['''width'''],
                ),							)



     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    self.image_processing_class(**self.image_processor_dict   )
            # create random PyTorch tensors
            _UpperCamelCase														=    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
            _UpperCamelCase														=    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
            _UpperCamelCase														=    image_processor(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.size['''height'''],
                    self.image_processor_tester.size['''width'''],
                ),							)






@require_torch
@require_vision
class 			__A(    __lowercase    ,      unittest.TestCase			):
     __A							=							BlipImageProcessor if is_vision_available() else None

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    BlipImageProcessingTester(self,							num_channels=4   )
            _UpperCamelCase														=    3

     @property
     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            return self.image_processor_tester.prepare_image_processor_dict()

     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            _UpperCamelCase														=    self.image_processing_class(**self.image_processor_dict   )
            self.assertTrue(hasattr(A__,							'''do_resize'''   )   )
            self.assertTrue(hasattr(A__,							'''size'''   )   )
            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 						_UpperCamelCase  (   self   ):





            """simple docstring"""

            pass



     def 						_UpperCamelCase  (   self   ):





            """simple docstring"""

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

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









from typing import TYPE_CHECKING

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


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

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


try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __A     						=      [
     '''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

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

