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







class 			__A					(			unittest.TestCase      ):
 def __init__( self      :     Tuple					, lowerCamelCase      :     Dict					, lowerCamelCase      :     Optional[Any]=13					, lowerCamelCase      :     Any=3					, lowerCamelCase      :     Tuple=18					, lowerCamelCase      :     str=30					, lowerCamelCase      :     Union[str, Any]=4_00					, lowerCamelCase      :     Union[str, Any]=True					, lowerCamelCase      :     Dict=None					, lowerCamelCase      :     Union[str, Any]=True					, lowerCamelCase      :     Any=[0.5, 0.5, 0.5]					, lowerCamelCase      :     Optional[Any]=[0.5, 0.5, 0.5]					, ):



   """simple docstring"""





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






 def 		lowercase_( self      :     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,
   }







@require_torch
@require_vision
class 			__A					(			_SCREAMING_SNAKE_CASE     ,    unittest.TestCase      ):
 lowerCamelCase												=EfficientNetImageProcessor if is_vision_available() else None
 def 		lowercase_( self      :     str							):



   """simple docstring"""





   __A		:  Optional[Any]       				=		EfficientNetImageProcessorTester(self							)
 @property
 def 		lowercase_( self      :     List[Any]							):



   """simple docstring"""





   return self.image_processor_tester.prepare_image_processor_dict()
 def 		lowercase_( self      :     str							):



   """simple docstring"""





   __A		:  Optional[Any]       				=		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 		lowercase_( self      :     str							):



   """simple docstring"""





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

   __A		:  Tuple       				=		self.image_processing_class.from_dict(self.image_processor_dict					, size=42							)
   self.assertEqual(image_processor.size					, {"""height""": 42, """width""": 42}							)
 def 		lowercase_( self      :     Tuple							):



   """simple docstring"""





   __A		:  Tuple       				=		self.image_processing_class(**self.image_processor_dict							)
   # create random PIL images
   __A		:  int       				=		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		:  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		:  List[str]       				=		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 		lowercase_( self      :     List[str]							):



   """simple docstring"""





   __A		:  Optional[int]       				=		self.image_processing_class(**self.image_processor_dict							)
   # create random numpy tensors
   __A		:  int       				=		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		:  str       				=		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 		lowercase_( self      :     str							):



   """simple docstring"""





   __A		:  List[str]       				=		self.image_processing_class(**self.image_processor_dict							)
   # create random PyTorch tensors
   __A		:  List[Any]       				=		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		:  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		:  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"""],
       )					, )





'''simple docstring'''
import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


A__ :		str					=logging.get_logger(__name__)

A__ :		Optional[int]					={
    'facebook/sam-vit-huge': 'https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json',
    'facebook/sam-vit-large': 'https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json',
    'facebook/sam-vit-base': 'https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json',
}







class 			__A					(			_SCREAMING_SNAKE_CASE      ):
 def __init__( self      :     Tuple					, lowerCamelCase      :     Tuple=2_56					, lowerCamelCase      :     Union[str, Any]=10_24					, lowerCamelCase      :     List[str]=16					, lowerCamelCase      :     str=16					, lowerCamelCase      :     Union[str, Any]=4					, lowerCamelCase      :     Optional[Any]="gelu"					, lowerCamelCase      :     Union[str, Any]=1e-6					, **lowerCamelCase      :     Union[str, Any]					, ):



   """simple docstring"""





   super().__init__(**lowerCamelCase							)
   __A		:  List[str]       				=		hidden_size
   __A		:  Any       				=		image_size
   __A		:  Dict       				=		patch_size
   __A		:  Union[str, Any]       				=		image_size // patch_size
   __A		:  List[Any]       				=		mask_input_channels
   __A		:  str       				=		num_point_embeddings
   __A		:  Tuple       				=		hidden_act
   __A		:  List[str]       				=		layer_norm_eps







class 			__A					(			_SCREAMING_SNAKE_CASE      ):
 def __init__( self      :     Optional[int]					, lowerCamelCase      :     int=2_56					, lowerCamelCase      :     Tuple="relu"					, lowerCamelCase      :     Optional[Any]=20_48					, lowerCamelCase      :     int=2					, lowerCamelCase      :     Tuple=8					, lowerCamelCase      :     int=2					, lowerCamelCase      :     List[str]=3					, lowerCamelCase      :     Dict=3					, lowerCamelCase      :     Any=2_56					, lowerCamelCase      :     int=1e-6					, **lowerCamelCase      :     Tuple					, ):



   """simple docstring"""





   super().__init__(**lowerCamelCase							)
   __A		:  List[Any]       				=		hidden_size
   __A		:  Union[str, Any]       				=		hidden_act
   __A		:  Tuple       				=		mlp_dim
   __A		:  Any       				=		num_hidden_layers
   __A		:  Dict       				=		num_attention_heads
   __A		:  Optional[Any]       				=		attention_downsample_rate
   __A		:  List[Any]       				=		num_multimask_outputs
   __A		:  Optional[Any]       				=		iou_head_depth
   __A		:  Optional[int]       				=		iou_head_hidden_dim
   __A		:  Any       				=		layer_norm_eps







class 			__A					(			_SCREAMING_SNAKE_CASE      ):
 def __init__( self      :     Optional[int]					, lowerCamelCase      :     List[str]=7_68					, lowerCamelCase      :     Tuple=2_56					, lowerCamelCase      :     Optional[Any]=12					, lowerCamelCase      :     Tuple=12					, lowerCamelCase      :     int=3					, lowerCamelCase      :     Dict=10_24					, lowerCamelCase      :     int=16					, lowerCamelCase      :     Any="gelu"					, lowerCamelCase      :     Tuple=1e-0_6					, lowerCamelCase      :     Optional[int]=0.0					, lowerCamelCase      :     List[str]=1e-1_0					, lowerCamelCase      :     Optional[int]=True					, lowerCamelCase      :     Union[str, Any]=4.0					, lowerCamelCase      :     List[Any]=True					, lowerCamelCase      :     Optional[Any]=True					, lowerCamelCase      :     str=14					, lowerCamelCase      :     str=[2, 5, 8, 11]					, lowerCamelCase      :     Dict=1_28					, lowerCamelCase      :     Any=None					, **lowerCamelCase      :     Optional[int]					, ):



   """simple docstring"""





   super().__init__(**lowerCamelCase							)

   __A		:  Any       				=		hidden_size
   __A		:  Union[str, Any]       				=		output_channels
   __A		:  int       				=		num_hidden_layers
   __A		:  Any       				=		num_attention_heads
   __A		:  Tuple       				=		num_channels
   __A		:  Tuple       				=		image_size
   __A		:  Optional[Any]       				=		patch_size
   __A		:  List[str]       				=		hidden_act
   __A		:  Dict       				=		layer_norm_eps
   __A		:  Optional[int]       				=		attention_dropout
   __A		:  Dict       				=		initializer_range
   __A		:  Union[str, Any]       				=		qkv_bias
   __A		:  Optional[Any]       				=		mlp_ratio
   __A		:  Optional[int]       				=		use_abs_pos
   __A		:  int       				=		use_rel_pos
   __A		:  str       				=		window_size
   __A		:  Union[str, Any]       				=		global_attn_indexes
   __A		:  Dict       				=		num_pos_feats
   __A		:  int       				=		int(hidden_size * mlp_ratio							) if mlp_dim is None else mlp_dim







class 			__A					(			_SCREAMING_SNAKE_CASE      ):
 lowerCamelCase												='''sam'''
 lowerCamelCase												=True
 def __init__( self      :     Optional[int]					, lowerCamelCase      :     Dict=None					, lowerCamelCase      :     Dict=None					, lowerCamelCase      :     Optional[Any]=None					, lowerCamelCase      :     List[Any]=0.02					, **lowerCamelCase      :     Any					, ):



   """simple docstring"""





   super().__init__(**lowerCamelCase							)
   __A		:  str       				=		vision_config if vision_config is not None else {}
   __A		:  int       				=		prompt_encoder_config if prompt_encoder_config is not None else {}
   __A		:  Dict       				=		mask_decoder_config if mask_decoder_config is not None else {}

   if isinstance(lowerCamelCase					, lowerCamelCase							):
     __A		:  List[str]       				=		vision_config.to_dict()
   if isinstance(lowerCamelCase					, lowerCamelCase							):
     __A		:  Any       				=		prompt_encoder_config.to_dict()
   if isinstance(lowerCamelCase					, lowerCamelCase							):
     __A		:  Any       				=		mask_decoder_config.to_dict()

   __A		:  Any       				=		SamVisionConfig(**lowerCamelCase							)
   __A		:  List[Any]       				=		SamPromptEncoderConfig(**lowerCamelCase							)
   __A		:  Union[str, Any]       				=		SamMaskDecoderConfig(**lowerCamelCase							)
   __A		:  Any       				=		initializer_range






 def 		lowercase_( self      :     List[Any]							):



   """simple docstring"""





   __A		:  str       				=		copy.deepcopy(self.__dict__							)
   __A		:  Dict       				=		self.vision_config.to_dict()
   __A		:  Any       				=		self.prompt_encoder_config.to_dict()
   __A		:  str       				=		self.mask_decoder_config.to_dict()
   __A		:  Optional[int]       				=		self.__class__.model_type
   return output



