





'''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   UpperCAmelCase      (			unittest.TestCase							):
 def __init__(							self :Optional[Any]		,			lowercase_ :Any		,			lowercase_ :Tuple=7		,			lowercase_ :Optional[Any]=3		,			lowercase_ :Optional[Any]=18		,			lowercase_ :Optional[Any]=30		,			lowercase_ :Union[str, Any]=4_00		,			lowercase_ :Tuple=True		,			lowercase_ :Any=None		,			lowercase_ :Union[str, Any]=True		,			lowercase_ :List[Any]=False		,			lowercase_ :Tuple=True		,			lowercase_ :Tuple=True		,			lowercase_ :int=[0.5, 0.5, 0.5]		,			lowercase_ :str=[0.5, 0.5, 0.5]		,			)->				Dict:
     A__							=     parent
     A__							=     batch_size
     A__							=     num_channels
     A__							=     image_size
     A__							=     min_resolution
     A__							=     max_resolution
     A__							=     do_resize
     A__							=     size if size is not None else {"height": 18, "width": 20}
     A__							=     do_thumbnail
     A__							=     do_align_axis
     A__							=     do_pad
     A__							=     do_normalize
     A__							=     image_mean
     A__							=     image_std



 def 	UpperCAmelCase_				(							self :str				)->				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   UpperCAmelCase      (			UpperCamelCase__     ,			unittest.TestCase							):
 __lowercase  						=							DonutImageProcessor if is_vision_available() else None
 def 	UpperCAmelCase_				(							self :Any				)->				Optional[Any]:
     A__							=     DonutImageProcessingTester(self				)
 @property
 def 	UpperCAmelCase_				(							self :Dict				)->				Union[str, Any]:
     return self.image_processor_tester.prepare_image_processor_dict()
 def 	UpperCAmelCase_				(							self :str				)->				Dict:
     A__							=     self.image_processing_class(**self.image_processor_dict				)
     self.assertTrue(hasattr(lowercase_		,			"do_resize"				)				)
     self.assertTrue(hasattr(lowercase_		,			"size"				)				)
     self.assertTrue(hasattr(lowercase_		,			"do_thumbnail"				)				)
     self.assertTrue(hasattr(lowercase_		,			"do_align_long_axis"				)				)
     self.assertTrue(hasattr(lowercase_		,			"do_pad"				)				)
     self.assertTrue(hasattr(lowercase_		,			"do_normalize"				)				)
     self.assertTrue(hasattr(lowercase_		,			"image_mean"				)				)
     self.assertTrue(hasattr(lowercase_		,			"image_std"				)				)
 def 	UpperCAmelCase_				(							self :List[str]				)->				Union[str, Any]:
     A__							=     self.image_processing_class.from_dict(self.image_processor_dict				)
     self.assertEqual(image_processor.size		,			{"height": 18, "width": 20}				)

     A__							=     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
     A__							=     self.image_processing_class.from_dict(self.image_processor_dict		,			size=(42, 84)				)
     self.assertEqual(image_processor.size		,			{"height": 84, "width": 42}				)
 def 	UpperCAmelCase_				(							self :Optional[int]				)->				Dict:
     pass
 @is_flaky()
 def 	UpperCAmelCase_				(							self :int				)->				Tuple:
     # 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=lowercase_				)
     for image in image_inputs:
         self.assertIsInstance(lowercase_		,			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(lowercase_		,			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 :Tuple				)->				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=lowercase_		,			numpify=lowercase_				)
     for image in image_inputs:
         self.assertIsInstance(lowercase_		,			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(lowercase_		,			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 :Optional[Any]				)->				List[str]:
     # 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=lowercase_		,			torchify=lowercase_				)
     for image in image_inputs:
         self.assertIsInstance(lowercase_		,			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(lowercase_		,			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'''

# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

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


__lowerCAmelCase				:      Optional[int]						      ={
    "configuration_vivit": ["VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "VivitConfig"],
}
try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __lowerCAmelCase				:      int						      =["VivitImageProcessor"]


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __lowerCAmelCase				:      int						      =[
      "VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST",
      "VivitModel",
      "VivitPreTrainedModel",
      "VivitForVideoClassification",
  ]


if TYPE_CHECKING:
  from .configuration_vivit import VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP, VivitConfig

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .image_processing_vivit import VivitImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_vivit import (
        VIVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
        VivitForVideoClassification,
        VivitModel,
        VivitPreTrainedModel,
    )


else:
  import sys

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



