





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, prepare_video_inputs


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import VivitImageProcessor

class 		SCREAMING_SNAKE_CASE__    (	unittest.TestCase  ):


      def __init__(self	:				Tuple    ,      a__	:				Dict    ,      a__	:				str=7    ,      a__	:				Dict=3    ,      a__	:				Union[str, Any]=10    ,      a__	:				List[Any]=18    ,      a__	:				List[str]=30    ,      a__	:				Optional[Any]=400    ,      a__	:				int=True    ,      a__	:				List[Any]=None    ,      a__	:				Dict=True    ,      a__	:				List[str]=[0.5, 0.5, 0.5]    ,      a__	:				int=[0.5, 0.5, 0.5]    ,      a__	:				Any=None    ,      ):





         """simple docstring"""



         __snake_case								=       size if size is not None else {'''shortest_edge''': 18}
         __snake_case								=       crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

         __snake_case								=       parent
         __snake_case								=       batch_size
         __snake_case								=       num_channels
         __snake_case								=       num_frames
         __snake_case								=       image_size
         __snake_case								=       min_resolution
         __snake_case								=       max_resolution
         __snake_case								=       do_resize
         __snake_case								=       size
         __snake_case								=       do_normalize
         __snake_case								=       image_mean
         __snake_case								=       image_std
         __snake_case								=       crop_size


      def        a			(self	:				Optional[Any]				):





         """simple docstring"""



         return {
             "image_mean": self.image_mean,
             "image_std": self.image_std,
             "do_normalize": self.do_normalize,
             "do_resize": self.do_resize,
             "size": self.size,
             "crop_size": self.crop_size,
         }






@require_torch
@require_vision
class 		SCREAMING_SNAKE_CASE__    (	_UpperCAmelCase						,				unittest.TestCase  ):
      A_						:    Tuple							=   VivitImageProcessor if is_vision_available() else None


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





         """simple docstring"""



         __snake_case								=       VivitImageProcessingTester(self				)


      @property
      def        a			(self	:				Tuple				):





         """simple docstring"""



         return self.image_processor_tester.prepare_image_processor_dict()


      def        a			(self	:				List[str]				):





         """simple docstring"""



         __snake_case								=       self.image_processing_class(**self.image_processor_dict				)
         self.assertTrue(hasattr(a__    ,      '''image_mean'''				)				)
         self.assertTrue(hasattr(a__    ,      '''image_std'''				)				)
         self.assertTrue(hasattr(a__    ,      '''do_normalize'''				)				)
         self.assertTrue(hasattr(a__    ,      '''do_resize'''				)				)
         self.assertTrue(hasattr(a__    ,      '''do_center_crop'''				)				)
         self.assertTrue(hasattr(a__    ,      '''size'''				)				)


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





         """simple docstring"""



         __snake_case								=       self.image_processing_class.from_dict(self.image_processor_dict				)
         self.assertEqual(image_processor.size    ,      {'''shortest_edge''': 18}				)
         self.assertEqual(image_processor.crop_size    ,      {'''height''': 18, '''width''': 18}				)

         __snake_case								=       self.image_processing_class.from_dict(self.image_processor_dict    ,      size=42    ,      crop_size=84				)
         self.assertEqual(image_processor.size    ,      {'''shortest_edge''': 42}				)
         self.assertEqual(image_processor.crop_size    ,      {'''height''': 84, '''width''': 84}				)


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





         """simple docstring"""



         __snake_case								=       self.image_processing_class(**self.image_processor_dict				)
         # create random PIL videos
         __snake_case								=       prepare_video_inputs(self.image_processor_tester    ,      equal_resolution=a__				)
         for video in video_inputs:
            self.assertIsInstance(a__    ,      a__				)
            self.assertIsInstance(video[0]    ,      Image.Image				)

         # Test not batched input
         __snake_case								=       image_processing(video_inputs[0]    ,      return_tensors='''pt'''				).pixel_values
         self.assertEqual(
             encoded_videos.shape    ,      (
                 1,
                 self.image_processor_tester.num_frames,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )    ,      )

         # Test batched
         __snake_case								=       image_processing(a__    ,      return_tensors='''pt'''				).pixel_values
         self.assertEqual(
             encoded_videos.shape    ,      (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_frames,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )    ,      )


      def        a			(self	:				List[Any]				):





         """simple docstring"""



         __snake_case								=       self.image_processing_class(**self.image_processor_dict				)
         # create random numpy tensors
         __snake_case								=       prepare_video_inputs(self.image_processor_tester    ,      equal_resolution=a__    ,      numpify=a__				)
         for video in video_inputs:
            self.assertIsInstance(a__    ,      a__				)
            self.assertIsInstance(video[0]    ,      np.ndarray				)

         # Test not batched input
         __snake_case								=       image_processing(video_inputs[0]    ,      return_tensors='''pt'''				).pixel_values
         self.assertEqual(
             encoded_videos.shape    ,      (
                 1,
                 self.image_processor_tester.num_frames,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )    ,      )

         # Test batched
         __snake_case								=       image_processing(a__    ,      return_tensors='''pt'''				).pixel_values
         self.assertEqual(
             encoded_videos.shape    ,      (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_frames,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )    ,      )


      def        a			(self	:				Any				):





         """simple docstring"""



         __snake_case								=       self.image_processing_class(**self.image_processor_dict				)
         # create random PyTorch tensors
         __snake_case								=       prepare_video_inputs(self.image_processor_tester    ,      equal_resolution=a__    ,      torchify=a__				)
         for video in video_inputs:
            self.assertIsInstance(a__    ,      a__				)
            self.assertIsInstance(video[0]    ,      torch.Tensor				)

         # Test not batched input
         __snake_case								=       image_processing(video_inputs[0]    ,      return_tensors='''pt'''				).pixel_values
         self.assertEqual(
             encoded_videos.shape    ,      (
                 1,
                 self.image_processor_tester.num_frames,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )    ,      )

         # Test batched
         __snake_case								=       image_processing(a__    ,      return_tensors='''pt'''				).pixel_values
         self.assertEqual(
             encoded_videos.shape    ,      (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_frames,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )    ,      )








# 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


snake_case_           =      {
    'configuration_vivit': ['VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'VivitConfig'],
}
try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    snake_case_           =      ['VivitImageProcessor']


try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    snake_case_           =      [
        '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

    snake_case_           =      _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

