"""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


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import TvltImageProcessor


def    lowerCAmelCase			(__UpperCamelCase							:    List[str]							,					__UpperCamelCase							:    Tuple=1_0							,					__UpperCamelCase							:    Optional[Any]=1_0							,					__UpperCamelCase							:    int=False							,					__UpperCamelCase							:    Optional[int]=False			):
							"""simple docstring"""


							__UpperCamelCase							=[]
							for i in range(image_processor_tester.num_frames			):
														video.append(np.random.randint(2_5_5							,					size=(image_processor_tester.num_channels, width, height)							,					dtype=np.uinta			)			)

							if not numpify and not torchify:
														# PIL expects the channel dimension as last dimension
														__UpperCamelCase							=[Image.fromarray(np.moveaxis(__UpperCamelCase							,					0							,					-1			)			) for frame in video]

							if torchify:
														__UpperCamelCase							=[torch.from_numpy(__UpperCamelCase			) for frame in video]

							return video


def    lowerCAmelCase			(__UpperCamelCase							:    List[Any]							,					__UpperCamelCase							:    Tuple=False							,					__UpperCamelCase							:    List[str]=False							,					__UpperCamelCase							:    Optional[Any]=False			):
							"""simple docstring"""


							assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

							__UpperCamelCase							=[]
							for i in range(image_processor_tester.batch_size			):
														if equal_resolution:
																					__UpperCamelCase							=__UpperCamelCase							=image_processor_tester.max_resolution
														else:
																					__UpperCamelCase	,      __UpperCamelCase							=np.random.choice(
																					    np.arange(image_processor_tester.min_resolution							,					image_processor_tester.max_resolution			)							,					2			)
																					__UpperCamelCase							=prepare_video(
																					    image_processor_tester=__UpperCamelCase							,					width=__UpperCamelCase							,					height=__UpperCamelCase							,					numpify=__UpperCamelCase							,					torchify=__UpperCamelCase							,					)
														video_inputs.append(__UpperCamelCase			)

							return video_inputs






class 		_lowercase (						unittest.TestCase      ):



						"""simple docstring"""




						def __init__(				self							:    List[str]     , UpperCamelCase__							:    Optional[int]     , UpperCamelCase__							:    Tuple=7     , UpperCamelCase__							:    List[Any]=3     , UpperCamelCase__							:    Any=4     , UpperCamelCase__							:    Optional[int]=18     , UpperCamelCase__							:    Tuple=30     , UpperCamelCase__							:    int=400     , UpperCamelCase__							:    List[Any]=True     , UpperCamelCase__							:    Tuple=None     , UpperCamelCase__							:    Union[str, Any]=True     , UpperCamelCase__							:    List[str]=[0.5, 0.5, 0.5]     , UpperCamelCase__							:    List[Any]=[0.5, 0.5, 0.5]     , UpperCamelCase__							:    Any=True     , UpperCamelCase__							:    Dict=None     , )				->				str:
													'''simple docstring'''



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

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





						def   UpperCAmelCase_ (				self							:    Optional[Any]				)				->				Tuple:
													'''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,
													    "do_center_crop": self.do_center_crop,
													    "crop_size": self.crop_size,
													}






@require_torch
@require_vision
class 		_lowercase (						SCREAMING_SNAKE_CASE_					,					unittest.TestCase      ):



						"""simple docstring"""




						lowercase__       =  TvltImageProcessor if is_vision_available() else None





						def   UpperCAmelCase_ (				self							:    List[str]				)				->				Optional[Any]:
													'''simple docstring'''



													__UpperCamelCase							=TvltImageProcessorTester(self				)





						@property
						def   UpperCAmelCase_ (				self							:    List[Any]				)				->				int:
													'''simple docstring'''



													return self.image_processor_tester.prepare_image_processor_dict()





						def   UpperCAmelCase_ (				self							:    int				)				->				int:
													'''simple docstring'''



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





						def   UpperCAmelCase_ (				self							:    str				)				->				Any:
													'''simple docstring'''



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

													# Test not batched input
													__UpperCamelCase							=image_processor(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
													__UpperCamelCase							=image_processor(__UpperCAmelCase     , 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							:    Union[str, Any]				)				->				int:
													'''simple docstring'''



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

													# Test not batched input
													__UpperCamelCase							=image_processor(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
													__UpperCamelCase							=image_processor(__UpperCAmelCase     , 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[str]				)				->				Tuple:
													'''simple docstring'''



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

													# Test not batched input
													__UpperCamelCase							=image_processor(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
													__UpperCamelCase							=image_processor(__UpperCAmelCase     , 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_tf_available,
    is_torch_available,
    is_vision_available,
)


UpperCamelCase_						   =   {
    'configuration_sam': [
        'SAM_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'SamConfig',
        'SamMaskDecoderConfig',
        'SamPromptEncoderConfig',
        'SamVisionConfig',
    ],
    'processing_sam': ['SamProcessor'],
}


try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase_						   =   [
          'SAM_PRETRAINED_MODEL_ARCHIVE_LIST',
          'SamModel',
          'SamPreTrainedModel',
      ]
try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase_						   =   [
          'TF_SAM_PRETRAINED_MODEL_ARCHIVE_LIST',
          'TFSamModel',
          'TFSamPreTrainedModel',
      ]
try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase_						   =   ['SamImageProcessor']


if TYPE_CHECKING:
      from .configuration_sam import (
          SAM_PRETRAINED_CONFIG_ARCHIVE_MAP,
          SamConfig,
          SamMaskDecoderConfig,
          SamPromptEncoderConfig,
          SamVisionConfig,
      )
      from .processing_sam import SamProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_sam import SAM_PRETRAINED_MODEL_ARCHIVE_LIST, SamModel, SamPreTrainedModel

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_sam import TF_SAM_PRETRAINED_MODEL_ARCHIVE_LIST, TFSamModel, TFSamPreTrainedModel

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .image_processing_sam import SamImageProcessor

else:
      import sys

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