




'''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_image_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import ViTImageProcessor




class      UpperCamelCase       (	unittest.TestCase       ):



  def __init__(			self		,     __lowerCAmelCase		,     __lowerCAmelCase=7		,     __lowerCAmelCase=3		,     __lowerCAmelCase=18		,     __lowerCAmelCase=30		,     __lowerCAmelCase=400		,     __lowerCAmelCase=True		,     __lowerCAmelCase=None		,     __lowerCAmelCase=True		,     __lowerCAmelCase=[0.5, 0.5, 0.5]		,     __lowerCAmelCase=[0.5, 0.5, 0.5]		,     ):







      '''simple docstring'''


      _a				:							Dict							       =      size if size is not None else {"""height""": 18, """width""": 18}
      _a				:							Optional[int]							       =      parent
      _a				:							str							       =      batch_size
      _a				:							Any							       =      num_channels
      _a				:							Union[str, Any]							       =      image_size
      _a				:							int							       =      min_resolution
      _a				:							Any							       =      max_resolution
      _a				:							Dict							       =      do_resize
      _a				:							Optional[int]							       =      size
      _a				:							Any							       =      do_normalize
      _a				:							List[str]							       =      image_mean
      _a				:							str							       =      image_std



  def     a_							(			self ):







      '''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,
      }






@require_torch
@require_vision
class      UpperCamelCase       (	snake_case__      ,		unittest.TestCase       ):
  a     :List[str]          =					ViTImageProcessor if is_vision_available() else None



  def     a_							(			self ):







      '''simple docstring'''


      _a				:							Tuple							       =      ViTImageProcessingTester(self )



  @property
  def     a_							(			self ):







      '''simple docstring'''


      return self.image_processor_tester.prepare_image_processor_dict()



  def     a_							(			self ):







      '''simple docstring'''


      _a				:							Tuple							       =      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		,     """size""" ) )



  def     a_							(			self ):







      '''simple docstring'''


      _a				:							Tuple							       =      self.image_processing_class.from_dict(self.image_processor_dict )
      self.assertEqual(image_processor.size		,     {"""height""": 18, """width""": 18} )

      _a				:							Dict							       =      self.image_processing_class.from_dict(self.image_processor_dict		,     size=42 )
      self.assertEqual(image_processor.size		,     {"""height""": 42, """width""": 42} )



  def     a_							(			self ):







      '''simple docstring'''


      pass



  def     a_							(			self ):







      '''simple docstring'''


      _a				:							Optional[Any]							       =      self.image_processing_class(**self.image_processor_dict )
      # create random PIL images
      _a				:							List[Any]							       =      prepare_image_inputs(self.image_processor_tester		,     equal_resolution=__lowerCAmelCase )
      for image in image_inputs:
          self.assertIsInstance(__lowerCAmelCase		,     Image.Image )

      # Test not batched input
      _a				:							List[Any]							       =      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				:							int							       =      image_processing(__lowerCAmelCase		,     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"""],
          )		,     )



  def     a_							(			self ):







      '''simple docstring'''


      _a				:							Tuple							       =      self.image_processing_class(**self.image_processor_dict )
      # create random numpy tensors
      _a				:							Dict							       =      prepare_image_inputs(self.image_processor_tester		,     equal_resolution=__lowerCAmelCase		,     numpify=__lowerCAmelCase )
      for image in image_inputs:
          self.assertIsInstance(__lowerCAmelCase		,     np.ndarray )

      # Test not batched input
      _a				:							Any							       =      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				:							Optional[Any]							       =      image_processing(__lowerCAmelCase		,     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"""],
          )		,     )



  def     a_							(			self ):







      '''simple docstring'''


      _a				:							Optional[Any]							       =      self.image_processing_class(**self.image_processor_dict )
      # create random PyTorch tensors
      _a				:							Tuple							       =      prepare_image_inputs(self.image_processor_tester		,     equal_resolution=__lowerCAmelCase		,     torchify=__lowerCAmelCase )
      for image in image_inputs:
          self.assertIsInstance(__lowerCAmelCase		,     torch.Tensor )

      # Test not batched input
      _a				:							Optional[int]							       =      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				:							Optional[int]							       =      image_processing(__lowerCAmelCase		,     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"""],
          )		,     )



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


_SCREAMING_SNAKE_CASE:    Optional[Any]     						=							{
    '''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:
			_SCREAMING_SNAKE_CASE:    Dict     						=							[
			    '''SAM_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''SamModel''',
			    '''SamPreTrainedModel''',
			]
try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_SCREAMING_SNAKE_CASE:    Optional[Any]     						=							[
			    '''TF_SAM_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''TFSamModel''',
			    '''TFSamPreTrainedModel''',
			]
try:
			if not is_vision_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_SCREAMING_SNAKE_CASE:    List[Any]     						=							['''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

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

