



"""simple docstring"""
import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor


class    SCREAMING_SNAKE_CASE__ (							unittest.TestCase   ):

    def __init__(				self			:				Optional[Any] ,  lowerCAmelCase_			:				Optional[Any] ,  lowerCAmelCase_			:				Any=7 ,  lowerCAmelCase_			:				Optional[int]=3 ,  lowerCAmelCase_			:				int=1_8 ,  lowerCAmelCase_			:				Optional[int]=3_0 ,  lowerCAmelCase_			:				Union[str, Any]=4_0_0 ,  lowerCAmelCase_			:				Dict=True ,  lowerCAmelCase_			:				List[Any]=None ,  lowerCAmelCase_			:				int=True ,  lowerCAmelCase_			:				Tuple=False ,  lowerCAmelCase_			:				int=True ,  lowerCAmelCase_			:				Union[str, Any]=True ,  lowerCAmelCase_			:				Dict=[0.5, 0.5, 0.5] ,  lowerCAmelCase_			:				Optional[int]=[0.5, 0.5, 0.5] ,  ):







      """simple docstring"""







      lowercase_								= parent
      lowercase_								= batch_size
      lowercase_								= num_channels
      lowercase_								= image_size
      lowercase_								= min_resolution
      lowercase_								= max_resolution
      lowercase_								= do_resize
      lowercase_								= size if size is not None else {"""height""": 1_8, """width""": 2_0}
      lowercase_								= do_thumbnail
      lowercase_								= do_align_axis
      lowercase_								= do_pad
      lowercase_								= do_normalize
      lowercase_								= image_mean
      lowercase_								= image_std




    def 					_UpperCAmelCase	(				self			:				Any):







      """simple docstring"""







      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_thumbnail": self.do_thumbnail,
          "do_align_long_axis": self.do_align_axis,
          "do_pad": self.do_pad,
          "do_normalize": self.do_normalize,
          "image_mean": self.image_mean,
          "image_std": self.image_std,
      }







@require_torch
@require_vision
class    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase      ,  unittest.TestCase   ):
    lowercase__      =   DonutImageProcessor if is_vision_available() else None

    def 					_UpperCAmelCase	(				self			:				Optional[Any]):







      """simple docstring"""







      lowercase_								= DonutImageProcessingTester(self)

    @property
    def 					_UpperCAmelCase	(				self			:				Union[str, Any]):







      """simple docstring"""







      return self.image_processor_tester.prepare_image_processor_dict()

    def 					_UpperCAmelCase	(				self			:				Optional[int]):







      """simple docstring"""







      lowercase_								= self.image_processing_class(**self.image_processor_dict)
      self.assertTrue(hasattr(lowerCAmelCase_ ,  """do_resize"""))
      self.assertTrue(hasattr(lowerCAmelCase_ ,  """size"""))
      self.assertTrue(hasattr(lowerCAmelCase_ ,  """do_thumbnail"""))
      self.assertTrue(hasattr(lowerCAmelCase_ ,  """do_align_long_axis"""))
      self.assertTrue(hasattr(lowerCAmelCase_ ,  """do_pad"""))
      self.assertTrue(hasattr(lowerCAmelCase_ ,  """do_normalize"""))
      self.assertTrue(hasattr(lowerCAmelCase_ ,  """image_mean"""))
      self.assertTrue(hasattr(lowerCAmelCase_ ,  """image_std"""))

    def 					_UpperCAmelCase	(				self			:				Dict):







      """simple docstring"""







      lowercase_								= self.image_processing_class.from_dict(self.image_processor_dict)
      self.assertEqual(image_processor.size ,  {"""height""": 1_8, """width""": 2_0})

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

      # Previous config had dimensions in (width, height) order
      lowercase_								= self.image_processing_class.from_dict(self.image_processor_dict ,  size=(4_2, 8_4))
      self.assertEqual(image_processor.size ,  {"""height""": 8_4, """width""": 4_2})

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







      """simple docstring"""







      pass

    @is_flaky()
    def 					_UpperCAmelCase	(				self			:				List[str]):







      """simple docstring"""







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

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

      # Test batched
      lowercase_								= image_processing(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"""],
          ) ,  )

    @is_flaky()
    def 					_UpperCAmelCase	(				self			:				List[Any]):







      """simple docstring"""







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

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

      # Test batched
      lowercase_								= image_processing(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"""],
          ) ,  )




    @is_flaky()
    def 					_UpperCAmelCase	(				self			:				int):







      """simple docstring"""







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

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

      # Test batched
      lowercase_								= image_processing(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"""],
          ) ,  )






"""simple docstring"""
from typing import TYPE_CHECKING

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


UpperCAmelCase						:		Any			= {
    "configuration_blip": [
        "BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "BlipConfig",
        "BlipTextConfig",
        "BlipVisionConfig",
    ],
    "processing_blip": ["BlipProcessor"],
}

try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCAmelCase						:		Any			= ["BlipImageProcessor"]


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCAmelCase						:		Optional[int]			= [
           "BLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
           "BlipModel",
           "BlipPreTrainedModel",
           "BlipForConditionalGeneration",
           "BlipForQuestionAnswering",
           "BlipVisionModel",
           "BlipTextModel",
           "BlipForImageTextRetrieval",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCAmelCase						:		str			= [
           "TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TFBlipModel",
           "TFBlipPreTrainedModel",
           "TFBlipForConditionalGeneration",
           "TFBlipForQuestionAnswering",
           "TFBlipVisionModel",
           "TFBlipTextModel",
           "TFBlipForImageTextRetrieval",
       ]

if TYPE_CHECKING:
       from .configuration_blip import BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP, BlipConfig, BlipTextConfig, BlipVisionConfig
       from .processing_blip import BlipProcessor

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .image_processing_blip import BlipImageProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_blip import (
                  BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
                  BlipForConditionalGeneration,
                  BlipForImageTextRetrieval,
                  BlipForQuestionAnswering,
                  BlipModel,
                  BlipPreTrainedModel,
                  BlipTextModel,
                  BlipVisionModel,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_blip import (
                  TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFBlipForConditionalGeneration,
                  TFBlipForImageTextRetrieval,
                  TFBlipForQuestionAnswering,
                  TFBlipModel,
                  TFBlipPreTrainedModel,
                  TFBlipTextModel,
                  TFBlipVisionModel,
              )

else:
       import sys

       UpperCAmelCase						:		Any			= _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

