






"""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 					a						( unittest.TestCase		):






				def __init__(	self					:							List[str]	,						__SCREAMING_SNAKE_CASE					:							Any	,						__SCREAMING_SNAKE_CASE					:							Tuple=7	,						__SCREAMING_SNAKE_CASE					:							Dict=3	,						__SCREAMING_SNAKE_CASE					:							Union[str, Any]=10	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=18	,						__SCREAMING_SNAKE_CASE					:							List[str]=30	,						__SCREAMING_SNAKE_CASE					:							List[str]=400	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=True	,						__SCREAMING_SNAKE_CASE					:							str=None	,						__SCREAMING_SNAKE_CASE					:							Dict=True	,						__SCREAMING_SNAKE_CASE					:							Any=[0.5, 0.5, 0.5]	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=[0.5, 0.5, 0.5]	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=None	,						)					->		int:
						lowerCamelCase_   					=						size if size is not None else {"shortest_edge": 18}
						lowerCamelCase_   					=						crop_size if crop_size is not None else {"height": 18, "width": 18}

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






				def        UpperCamelCase	(	self					:							int )					->		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,
						    "crop_size": self.crop_size,
						}






@require_torch
@require_vision
class 					a						( snake_case__  ,				unittest.TestCase		):
				SCREAMING_SNAKE_CASE						:					Union[str, Any]						=			VideoMAEImageProcessor if is_vision_available() else None






				def        UpperCamelCase	(	self					:							Optional[int] )					->		Optional[int]:
						lowerCamelCase_   					=						VideoMAEImageProcessingTester(self )






				@property
				def        UpperCamelCase	(	self					:							Optional[int] )					->		int:
						return self.image_processor_tester.prepare_image_processor_dict()






				def        UpperCamelCase	(	self					:							List[str] )					->		Dict:
						lowerCamelCase_   					=						self.image_processing_class(**self.image_processor_dict )
						self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'image_mean' ) )
						self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'image_std' ) )
						self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'do_normalize' ) )
						self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'do_resize' ) )
						self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'do_center_crop' ) )
						self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'size' ) )






				def        UpperCamelCase	(	self					:							Any )					->		List[Any]:
						lowerCamelCase_   					=						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} )

						lowerCamelCase_   					=						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        UpperCamelCase	(	self					:							Tuple )					->		Union[str, Any]:
						pass






				def        UpperCamelCase	(	self					:							Optional[int] )					->		Union[str, Any]:
						# Initialize image_processing
						lowerCamelCase_   					=						self.image_processing_class(**self.image_processor_dict )
						# create random PIL videos
						lowerCamelCase_   					=						prepare_video_inputs(self.image_processor_tester	,						equal_resolution=__SCREAMING_SNAKE_CASE )
						for video in video_inputs:
								self.assertIsInstance(__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE )
								self.assertIsInstance(video[0]	,						Image.Image )

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

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

						# Test not batched input
						lowerCamelCase_   					=						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
						lowerCamelCase_   					=						image_processing(__SCREAMING_SNAKE_CASE	,						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 typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_SCREAMING_SNAKE_CASE :    Union[str, Any]    =						{
    '''configuration_decision_transformer''': [
        '''DECISION_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''DecisionTransformerConfig''',
    ],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _SCREAMING_SNAKE_CASE :    Optional[Any]    =						[
      '''DECISION_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''DecisionTransformerGPT2Model''',
      '''DecisionTransformerGPT2PreTrainedModel''',
      '''DecisionTransformerModel''',
      '''DecisionTransformerPreTrainedModel''',
  ]


if TYPE_CHECKING:
  from .configuration_decision_transformer import (
      DECISION_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
      DecisionTransformerConfig,
  )

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_decision_transformer import (
        DECISION_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
        DecisionTransformerGPTaModel,
        DecisionTransformerGPTaPreTrainedModel,
        DecisionTransformerModel,
        DecisionTransformerPreTrainedModel,
    )


else:
  import sys

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




