

"""simple docstring"""


import unittest

import numpy as np

from transformers.file_utils import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision

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 DPTImageProcessor





class lowerCamelCase__   (				unittest.TestCase    ):



    '''simple docstring'''




    def __init__( self ,lowerCamelCase_ ,lowerCamelCase_=7 ,lowerCamelCase_=3 ,lowerCamelCase_=1_8 ,lowerCamelCase_=3_0 ,lowerCamelCase_=4_0_0 ,lowerCamelCase_=True ,lowerCamelCase_=None ,lowerCamelCase_=True ,lowerCamelCase_=[0.5, 0.5, 0.5] ,lowerCamelCase_=[0.5, 0.5, 0.5] ,)    ->      List[Any]:
          A				  =		size if size is not None else {"""height""": 1_8, """width""": 1_8}
          A				  =		parent
          A				  =		batch_size
          A				  =		num_channels
          A				  =		image_size
          A				  =		min_resolution
          A				  =		max_resolution
          A				  =		do_resize
          A				  =		size
          A				  =		do_normalize
          A				  =		image_mean
          A				  =		image_std




    def UpperCamelCase__		( self    )    ->      List[str]:
          return {
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_normalize": self.do_normalize,
              "do_resize": self.do_resize,
              "size": self.size,
          }





@require_torch
@require_vision
class lowerCamelCase__   (				SCREAMING_SNAKE_CASE     ,   unittest.TestCase    ):



    '''simple docstring'''




    _lowerCamelCase					=   DPTImageProcessor if is_vision_available() else None




    def UpperCamelCase__		( self    )    ->      Union[str, Any]:
          A				  =		DPTImageProcessingTester(self    )




    @property
    def UpperCamelCase__		( self    )    ->      Dict:
          return self.image_processor_tester.prepare_image_processor_dict()




    def UpperCamelCase__		( self    )    ->      str:
          A				  =		self.image_processing_class(**self.image_processor_dict    )
          self.assertTrue(hasattr(lowerCamelCase_ ,"""image_mean"""    )    )
          self.assertTrue(hasattr(lowerCamelCase_ ,"""image_std"""    )    )
          self.assertTrue(hasattr(lowerCamelCase_ ,"""do_normalize"""    )    )
          self.assertTrue(hasattr(lowerCamelCase_ ,"""do_resize"""    )    )
          self.assertTrue(hasattr(lowerCamelCase_ ,"""size"""    )    )




    def UpperCamelCase__		( self    )    ->      Union[str, Any]:
          A				  =		self.image_processing_class.from_dict(self.image_processor_dict    )
          self.assertEqual(image_processor.size ,{"""height""": 1_8, """width""": 1_8}    )

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




    def UpperCamelCase__		( self    )    ->      str:
          # Initialize image_processing
          A				  =		self.image_processing_class(**self.image_processor_dict    )
          # create random PIL images
          A				  =		prepare_image_inputs(self.image_processor_tester ,equal_resolution=lowerCamelCase_    )
          for image in image_inputs:
                self.assertIsInstance(lowerCamelCase_ ,Image.Image    )

          # Test not batched input
          A				  =		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
          A				  =		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"""],
              ) ,)




    def UpperCamelCase__		( self    )    ->      Dict:
          # Initialize image_processing
          A				  =		self.image_processing_class(**self.image_processor_dict    )
          # create random numpy tensors
          A				  =		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
          A				  =		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
          A				  =		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"""],
              ) ,)




    def UpperCamelCase__		( self    )    ->      Optional[int]:
          # Initialize image_processing
          A				  =		self.image_processing_class(**self.image_processor_dict    )
          # create random PyTorch tensors
          A				  =		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
          A				  =		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
          A				  =		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

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase													={
    "configuration_informer": [
        "INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "InformerConfig",
    ],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase													=[
      "INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
      "InformerForPrediction",
      "InformerModel",
      "InformerPreTrainedModel",
  ]


if TYPE_CHECKING:
  from .configuration_informer import INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, InformerConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_informer import (
        INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
        InformerForPrediction,
        InformerModel,
        InformerPreTrainedModel,
    )

else:
  import sys

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




