




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






     def __init__(					self   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE=7   ,_SCREAMING_SNAKE_CASE=3   ,_SCREAMING_SNAKE_CASE=18   ,_SCREAMING_SNAKE_CASE=30   ,_SCREAMING_SNAKE_CASE=400   ,_SCREAMING_SNAKE_CASE=True   ,_SCREAMING_SNAKE_CASE=None   ,_SCREAMING_SNAKE_CASE=True   ,_SCREAMING_SNAKE_CASE=False   ,_SCREAMING_SNAKE_CASE=True   ,_SCREAMING_SNAKE_CASE=True   ,_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]   ,_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]   ,)				->     int:
          _snake_case				= parent
          _snake_case				= batch_size
          _snake_case				= num_channels
          _snake_case				= image_size
          _snake_case				= min_resolution
          _snake_case				= max_resolution
          _snake_case				= do_resize
          _snake_case				= size if size is not None else {"height": 18, "width": 20}
          _snake_case				= do_thumbnail
          _snake_case				= do_align_axis
          _snake_case				= do_pad
          _snake_case				= do_normalize
          _snake_case				= image_mean
          _snake_case				= image_std






     def 							_lowercase      (					self       )				->     Optional[Any]:
          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   _a							(		__lowerCAmelCase   ,   unittest.TestCase				):
     SCREAMING_SNAKE_CASE_				:       int       							=		DonutImageProcessor if is_vision_available() else None






     def 							_lowercase      (					self       )				->     List[str]:
          _snake_case				= DonutImageProcessingTester(self       )






     @property
     def 							_lowercase      (					self       )				->     List[Any]:
          return self.image_processor_tester.prepare_image_processor_dict()






     def 							_lowercase      (					self       )				->     str:
          _snake_case				= self.image_processing_class(**self.image_processor_dict       )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE   ,"do_resize"       )       )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE   ,"size"       )       )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE   ,"do_thumbnail"       )       )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE   ,"do_align_long_axis"       )       )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE   ,"do_pad"       )       )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE   ,"do_normalize"       )       )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE   ,"image_mean"       )       )
          self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE   ,"image_std"       )       )






     def 							_lowercase      (					self       )				->     Optional[int]:
          _snake_case				= self.image_processing_class.from_dict(self.image_processor_dict       )
          self.assertEqual(image_processor.size   ,{"height": 18, "width": 20}       )

          _snake_case				= self.image_processing_class.from_dict(self.image_processor_dict   ,size=42       )
          self.assertEqual(image_processor.size   ,{"height": 42, "width": 42}       )

          # Previous config had dimensions in (width, height) order
          _snake_case				= self.image_processing_class.from_dict(self.image_processor_dict   ,size=(42, 84)       )
          self.assertEqual(image_processor.size   ,{"height": 84, "width": 42}       )






     def 							_lowercase      (					self       )				->     List[Any]:
          pass






     @is_flaky()
     def 							_lowercase      (					self       )				->     Tuple:
          # Initialize image_processing
          _snake_case				= self.image_processing_class(**self.image_processor_dict       )
          # create random PIL images
          _snake_case				= prepare_image_inputs(self.image_processor_tester   ,equal_resolution=_SCREAMING_SNAKE_CASE       )
          for image in image_inputs:
               self.assertIsInstance(_SCREAMING_SNAKE_CASE   ,Image.Image       )

          # Test not batched input
          _snake_case				= 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
          _snake_case				= image_processing(_SCREAMING_SNAKE_CASE   ,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 							_lowercase      (					self       )				->     List[Any]:
          # Initialize image_processing
          _snake_case				= self.image_processing_class(**self.image_processor_dict       )
          # create random numpy tensors
          _snake_case				= prepare_image_inputs(self.image_processor_tester   ,equal_resolution=_SCREAMING_SNAKE_CASE   ,numpify=_SCREAMING_SNAKE_CASE       )
          for image in image_inputs:
               self.assertIsInstance(_SCREAMING_SNAKE_CASE   ,np.ndarray       )

          # Test not batched input
          _snake_case				= 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
          _snake_case				= image_processing(_SCREAMING_SNAKE_CASE   ,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 							_lowercase      (					self       )				->     List[str]:
          # Initialize image_processing
          _snake_case				= self.image_processing_class(**self.image_processor_dict       )
          # create random PyTorch tensors
          _snake_case				= prepare_image_inputs(self.image_processor_tester   ,equal_resolution=_SCREAMING_SNAKE_CASE   ,torchify=_SCREAMING_SNAKE_CASE       )
          for image in image_inputs:
               self.assertIsInstance(_SCREAMING_SNAKE_CASE   ,torch.Tensor       )

          # Test not batched input
          _snake_case				= 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
          _snake_case				= image_processing(_SCREAMING_SNAKE_CASE   ,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_torch_available


UpperCamelCase_		:     List[Any]          =		{
    '''configuration_git''': ['''GIT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''GitConfig''', '''GitVisionConfig'''],
    '''processing_git''': ['''GitProcessor'''],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   UpperCamelCase_		:     Optional[Any]          =		[
       '''GIT_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''GitForCausalLM''',
       '''GitModel''',
       '''GitPreTrainedModel''',
       '''GitVisionModel''',
   ]

if TYPE_CHECKING:
   from .configuration_git import GIT_PRETRAINED_CONFIG_ARCHIVE_MAP, GitConfig, GitVisionConfig
   from .processing_git import GitProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_git import (
          GIT_PRETRAINED_MODEL_ARCHIVE_LIST,
          GitForCausalLM,
          GitModel,
          GitPreTrainedModel,
          GitVisionModel,
      )

else:
   import sys

   UpperCamelCase_		:     List[Any]          =		_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


