'''simple docstring'''
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 VideoMAEImageProcessor




class _lowerCAmelCase			(	unittest.TestCase					):







      def __init__(  self  ,    lowercase  ,    lowercase=7  ,    lowercase=3  ,    lowercase=10  ,    lowercase=18  ,    lowercase=30  ,    lowercase=400  ,    lowercase=True  ,    lowercase=None  ,    lowercase=True  ,    lowercase=[0.5, 0.5, 0.5]  ,    lowercase=[0.5, 0.5, 0.5]  ,    lowercase=None  ,    ):
        lowercase				:							Any									=   size if size is not None else {'shortest_edge': 18}
        lowercase				:							Dict									=   crop_size if crop_size is not None else {'height': 18, 'width': 18}

        lowercase				:							Any									=   parent
        lowercase				:							Dict									=   batch_size
        lowercase				:							List[str]									=   num_channels
        lowercase				:							int									=   num_frames
        lowercase				:							List[str]									=   image_size
        lowercase				:							Tuple									=   min_resolution
        lowercase				:							int									=   max_resolution
        lowercase				:							List[str]									=   do_resize
        lowercase				:							Union[str, Any]									=   size
        lowercase				:							Tuple									=   do_normalize
        lowercase				:							str									=   image_mean
        lowercase				:							Optional[Any]									=   image_std
        lowercase				:							Tuple									=   crop_size







      def      lowerCamelCase__      (  self     ):
        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 _lowerCAmelCase			(	_lowerCamelCase							,   unittest.TestCase					):
      UpperCAmelCase_	:						List[str]	 =       VideoMAEImageProcessor if is_vision_available() else None







      def      lowerCamelCase__      (  self     ):
        lowercase				:							List[Any]									=   VideoMAEImageProcessingTester(self     )







      @property
      def      lowerCamelCase__      (  self     ):
        return self.image_processor_tester.prepare_image_processor_dict()







      def      lowerCamelCase__      (  self     ):
        lowercase				:							Optional[int]									=   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  ,    '''do_center_crop'''     )     )
        self.assertTrue(hasattr(_lowerCamelCase  ,    '''size'''     )     )







      def      lowerCamelCase__      (  self     ):
        lowercase				:							Optional[int]									=   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}     )

        lowercase				:							List[str]									=   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      lowerCamelCase__      (  self     ):
        pass







      def      lowerCamelCase__      (  self     ):
        # Initialize image_processing
        lowercase				:							Union[str, Any]									=   self.image_processing_class(**self.image_processor_dict     )
        # create random PIL videos
        lowercase				:							Any									=   prepare_video_inputs(self.image_processor_tester  ,    equal_resolution=_lowerCamelCase     )
        for video in video_inputs:
          self.assertIsInstance(_lowerCamelCase  ,    _lowerCamelCase     )
          self.assertIsInstance(video[0]  ,    Image.Image     )

        # Test not batched input
        lowercase				:							Optional[int]									=   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
        lowercase				:							List[Any]									=   image_processing(_lowerCamelCase  ,    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      lowerCamelCase__      (  self     ):
        # Initialize image_processing
        lowercase				:							List[Any]									=   self.image_processing_class(**self.image_processor_dict     )
        # create random numpy tensors
        lowercase				:							List[Any]									=   prepare_video_inputs(self.image_processor_tester  ,    equal_resolution=_lowerCamelCase  ,    numpify=_lowerCamelCase     )
        for video in video_inputs:
          self.assertIsInstance(_lowerCamelCase  ,    _lowerCamelCase     )
          self.assertIsInstance(video[0]  ,    np.ndarray     )

        # Test not batched input
        lowercase				:							Tuple									=   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
        lowercase				:							Any									=   image_processing(_lowerCamelCase  ,    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      lowerCamelCase__      (  self     ):
        # Initialize image_processing
        lowercase				:							str									=   self.image_processing_class(**self.image_processor_dict     )
        # create random PyTorch tensors
        lowercase				:							Dict									=   prepare_video_inputs(self.image_processor_tester  ,    equal_resolution=_lowerCamelCase  ,    torchify=_lowerCamelCase     )
        for video in video_inputs:
          self.assertIsInstance(_lowerCamelCase  ,    _lowerCamelCase     )
          self.assertIsInstance(video[0]  ,    torch.Tensor     )

        # Test not batched input
        lowercase				:							List[Any]									=   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
        lowercase				:							Dict									=   image_processing(_lowerCamelCase  ,    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'''],
            )  ,    )
'''simple docstring'''
from .prime_check import Test

Test()



