






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


    '''simple docstring'''

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

     '''simple docstring'''




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

    def  a__					(       self  :  Optional[int]  )				->				Any:

     '''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  a__					(       self  :  Any					,  __lowerCamelCase  :  Union[str, Any]=False					,  __lowerCamelCase  :  Any=False					,  __lowerCamelCase  :  List[Any]=False  )				->				List[str]:

     '''simple docstring'''




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

     if equal_resolution:
      lowerCamelCase__	=  []
      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__	=  []
      for i in range(self.batch_size  ):
       lowerCamelCase__	,						lowerCamelCase__	=  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__	=  [Image.fromarray(np.moveaxis(__lowerCamelCase					,  0					,  -1  )  ) for x in image_inputs]

     if torchify:
      lowerCamelCase__	=  [torch.from_numpy(__lowerCamelCase  ) for x in image_inputs]

     return image_inputs
@require_torch
@require_vision
class 					lowercase							(				_lowerCamelCase			,							unittest.TestCase   ):


    '''simple docstring'''

    lowerCAmelCase__   					=				BlipImageProcessor if is_vision_available() else None

    def  a__					(       self  :  List[Any]  )				->				Tuple:

     '''simple docstring'''




     lowerCamelCase__	=  BlipImageProcessingTester(self  )

    @property
    def  a__					(       self  :  List[str]  )				->				Dict:

     '''simple docstring'''




     return self.image_processor_tester.prepare_image_processor_dict()

    def  a__					(       self  :  str  )				->				str:

     '''simple docstring'''




     lowerCamelCase__	=  self.image_processing_class(**self.image_processor_dict  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "do_resize"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "size"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "do_normalize"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "image_mean"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "image_std"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "do_convert_rgb"  )  )

    def  a__					(       self  :  Dict  )				->				str:

     '''simple docstring'''




     pass

    def  a__					(       self  :  Union[str, Any]  )				->				Any:

     '''simple docstring'''




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

     # Test not batched input
     lowerCamelCase__	=  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__	=  image_processor(__lowerCamelCase					,  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  a__					(       self  :  Any  )				->				Optional[int]:

     '''simple docstring'''




     lowerCamelCase__	=  self.image_processing_class(**self.image_processor_dict  )
     # create random numpy tensors
     lowerCamelCase__	=  self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase					,  numpify=__lowerCamelCase  )
     for image in image_inputs:
      self.assertIsInstance(__lowerCamelCase					,  np.ndarray  )

     # Test not batched input
     lowerCamelCase__	=  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__	=  image_processor(__lowerCamelCase					,  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  a__					(       self  :  str  )				->				List[Any]:

     '''simple docstring'''




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

     # Test not batched input
     lowerCamelCase__	=  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__	=  image_processor(__lowerCamelCase					,  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 					lowercase							(				_lowerCamelCase			,							unittest.TestCase   ):


    '''simple docstring'''

    lowerCAmelCase__   					=				BlipImageProcessor if is_vision_available() else None

    def  a__					(       self  :  Optional[int]  )				->				Dict:

     '''simple docstring'''




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

    @property
    def  a__					(       self  :  Optional[int]  )				->				Dict:

     '''simple docstring'''




     return self.image_processor_tester.prepare_image_processor_dict()

    def  a__					(       self  :  List[Any]  )				->				List[Any]:

     '''simple docstring'''




     lowerCamelCase__	=  self.image_processing_class(**self.image_processor_dict  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "do_resize"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "size"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "do_normalize"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "image_mean"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "image_std"  )  )
     self.assertTrue(hasattr(__lowerCamelCase					,  "do_convert_rgb"  )  )

    def  a__					(       self  :  Any  )				->				str:

     '''simple docstring'''




     pass




    def  a__					(       self  :  int  )				->				Tuple:

     '''simple docstring'''




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

     # Test not batched input
     lowerCamelCase__	=  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__	=  image_processor(__lowerCamelCase					,  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"],
         )					,  )









'''simple docstring'''





from ..utils import DummyObject, requires_backends
class 					lowercase							(				metaclass=_lowerCamelCase   ):


    '''simple docstring'''

    lowerCAmelCase__   					=				["torch", "transformers", "invisible_watermark"]

    def __init__(       self  :  Optional[Any]					,  *__lowerCamelCase  :  List[Any]					,  **__lowerCamelCase  :  Union[str, Any]  )				->				Dict:

     '''simple docstring'''




     requires_backends(self					,  ["torch", "transformers", "invisible_watermark"]  )

    @classmethod
    def  a__					(       cls  :  Any					,  *__lowerCamelCase  :  List[Any]					,  **__lowerCamelCase  :  Tuple  )				->				List[str]:

     '''simple docstring'''




     requires_backends(cls					,  ["torch", "transformers", "invisible_watermark"]  )




    @classmethod
    def  a__					(       cls  :  Union[str, Any]					,  *__lowerCamelCase  :  Tuple					,  **__lowerCamelCase  :  Tuple  )				->				List[Any]:

     '''simple docstring'''




     requires_backends(cls					,  ["torch", "transformers", "invisible_watermark"]  )
class 					lowercase							(				metaclass=_lowerCamelCase   ):


    '''simple docstring'''

    lowerCAmelCase__   					=				["torch", "transformers", "invisible_watermark"]

    def __init__(       self  :  Optional[Any]					,  *__lowerCamelCase  :  str					,  **__lowerCamelCase  :  Optional[Any]  )				->				str:

     '''simple docstring'''




     requires_backends(self					,  ["torch", "transformers", "invisible_watermark"]  )

    @classmethod
    def  a__					(       cls  :  Union[str, Any]					,  *__lowerCamelCase  :  List[str]					,  **__lowerCamelCase  :  Dict  )				->				Any:

     '''simple docstring'''




     requires_backends(cls					,  ["torch", "transformers", "invisible_watermark"]  )




    @classmethod
    def  a__					(       cls  :  List[Any]					,  *__lowerCamelCase  :  Union[str, Any]					,  **__lowerCamelCase  :  Any  )				->				Any:

     '''simple docstring'''




     requires_backends(cls					,  ["torch", "transformers", "invisible_watermark"]  )

