






import copy

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


__UpperCAmelCase      =				logging.get_logger(__name__)

__UpperCAmelCase      =				{
    "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_(		lowercase__	):



     """simple docstring"""



     def __init__(		self					:	Union[str, Any]  ,  lowerCAmelCase__					:	int=2_5_6  ,  lowerCAmelCase__					:	str=1_0_2_4  ,  lowerCAmelCase__					:	Optional[Any]=1_6  ,  lowerCAmelCase__					:	Tuple=1_6  ,  lowerCAmelCase__					:	Tuple=4  ,  lowerCAmelCase__					:	int="gelu"  ,  lowerCAmelCase__					:	int=1e-6  ,  **lowerCAmelCase__					:	List[Any]  ,  )							->	Any:

      """simple docstring"""
      super().__init__(**lowerCAmelCase__)
      SCREAMING_SNAKE_CASE				    =		hidden_size
      SCREAMING_SNAKE_CASE				    =		image_size
      SCREAMING_SNAKE_CASE				    =		patch_size
      SCREAMING_SNAKE_CASE				    =		image_size // patch_size
      SCREAMING_SNAKE_CASE				    =		mask_input_channels
      SCREAMING_SNAKE_CASE				    =		num_point_embeddings
      SCREAMING_SNAKE_CASE				    =		hidden_act
      SCREAMING_SNAKE_CASE				    =		layer_norm_eps

class 	a_(		lowercase__	):



     """simple docstring"""



     def __init__(		self					:	Optional[Any]  ,  lowerCAmelCase__					:	Union[str, Any]=2_5_6  ,  lowerCAmelCase__					:	str="relu"  ,  lowerCAmelCase__					:	Optional[Any]=2_0_4_8  ,  lowerCAmelCase__					:	Any=2  ,  lowerCAmelCase__					:	int=8  ,  lowerCAmelCase__					:	Optional[int]=2  ,  lowerCAmelCase__					:	str=3  ,  lowerCAmelCase__					:	str=3  ,  lowerCAmelCase__					:	List[str]=2_5_6  ,  lowerCAmelCase__					:	Optional[int]=1e-6  ,  **lowerCAmelCase__					:	List[Any]  ,  )							->	Dict:

      """simple docstring"""
      super().__init__(**lowerCAmelCase__)
      SCREAMING_SNAKE_CASE				    =		hidden_size
      SCREAMING_SNAKE_CASE				    =		hidden_act
      SCREAMING_SNAKE_CASE				    =		mlp_dim
      SCREAMING_SNAKE_CASE				    =		num_hidden_layers
      SCREAMING_SNAKE_CASE				    =		num_attention_heads
      SCREAMING_SNAKE_CASE				    =		attention_downsample_rate
      SCREAMING_SNAKE_CASE				    =		num_multimask_outputs
      SCREAMING_SNAKE_CASE				    =		iou_head_depth
      SCREAMING_SNAKE_CASE				    =		iou_head_hidden_dim
      SCREAMING_SNAKE_CASE				    =		layer_norm_eps

class 	a_(		lowercase__	):



     """simple docstring"""



     def __init__(		self					:	Union[str, Any]  ,  lowerCAmelCase__					:	Optional[int]=7_6_8  ,  lowerCAmelCase__					:	Dict=2_5_6  ,  lowerCAmelCase__					:	Optional[Any]=1_2  ,  lowerCAmelCase__					:	List[str]=1_2  ,  lowerCAmelCase__					:	int=3  ,  lowerCAmelCase__					:	int=1_0_2_4  ,  lowerCAmelCase__					:	Dict=1_6  ,  lowerCAmelCase__					:	Dict="gelu"  ,  lowerCAmelCase__					:	List[str]=1e-06  ,  lowerCAmelCase__					:	Tuple=0.0  ,  lowerCAmelCase__					:	Optional[int]=1e-10  ,  lowerCAmelCase__					:	Dict=True  ,  lowerCAmelCase__					:	List[Any]=4.0  ,  lowerCAmelCase__					:	List[Any]=True  ,  lowerCAmelCase__					:	Union[str, Any]=True  ,  lowerCAmelCase__					:	int=1_4  ,  lowerCAmelCase__					:	int=[2, 5, 8, 1_1]  ,  lowerCAmelCase__					:	Optional[int]=1_2_8  ,  lowerCAmelCase__					:	List[Any]=None  ,  **lowerCAmelCase__					:	Optional[Any]  ,  )							->	int:

      """simple docstring"""
      super().__init__(**lowerCAmelCase__)

      SCREAMING_SNAKE_CASE				    =		hidden_size
      SCREAMING_SNAKE_CASE				    =		output_channels
      SCREAMING_SNAKE_CASE				    =		num_hidden_layers
      SCREAMING_SNAKE_CASE				    =		num_attention_heads
      SCREAMING_SNAKE_CASE				    =		num_channels
      SCREAMING_SNAKE_CASE				    =		image_size
      SCREAMING_SNAKE_CASE				    =		patch_size
      SCREAMING_SNAKE_CASE				    =		hidden_act
      SCREAMING_SNAKE_CASE				    =		layer_norm_eps
      SCREAMING_SNAKE_CASE				    =		attention_dropout
      SCREAMING_SNAKE_CASE				    =		initializer_range
      SCREAMING_SNAKE_CASE				    =		qkv_bias
      SCREAMING_SNAKE_CASE				    =		mlp_ratio
      SCREAMING_SNAKE_CASE				    =		use_abs_pos
      SCREAMING_SNAKE_CASE				    =		use_rel_pos
      SCREAMING_SNAKE_CASE				    =		window_size
      SCREAMING_SNAKE_CASE				    =		global_attn_indexes
      SCREAMING_SNAKE_CASE				    =		num_pos_feats
      SCREAMING_SNAKE_CASE				    =		int(hidden_size * mlp_ratio) if mlp_dim is None else mlp_dim

class 	a_(		lowercase__	):



     """simple docstring"""



     __snake_case		:				Optional[Any]  					='''sam'''
     __snake_case		:				Optional[Any]  					=True





     def __init__(		self					:	Optional[Any]  ,  lowerCAmelCase__					:	int=None  ,  lowerCAmelCase__					:	int=None  ,  lowerCAmelCase__					:	Any=None  ,  lowerCAmelCase__					:	Union[str, Any]=0.02  ,  **lowerCAmelCase__					:	Optional[int]  ,  )							->	List[str]:

      """simple docstring"""
      super().__init__(**lowerCAmelCase__)
      SCREAMING_SNAKE_CASE				    =		vision_config if vision_config is not None else {}
      SCREAMING_SNAKE_CASE				    =		prompt_encoder_config if prompt_encoder_config is not None else {}
      SCREAMING_SNAKE_CASE				    =		mask_decoder_config if mask_decoder_config is not None else {}

      if isinstance(lowerCAmelCase__  ,  lowerCAmelCase__):
       SCREAMING_SNAKE_CASE				    =		vision_config.to_dict()
      if isinstance(lowerCAmelCase__  ,  lowerCAmelCase__):
       SCREAMING_SNAKE_CASE				    =		prompt_encoder_config.to_dict()
      if isinstance(lowerCAmelCase__  ,  lowerCAmelCase__):
       SCREAMING_SNAKE_CASE				    =		mask_decoder_config.to_dict()

      SCREAMING_SNAKE_CASE				    =		SamVisionConfig(**lowerCAmelCase__)
      SCREAMING_SNAKE_CASE				    =		SamPromptEncoderConfig(**lowerCAmelCase__)
      SCREAMING_SNAKE_CASE				    =		SamMaskDecoderConfig(**lowerCAmelCase__)
      SCREAMING_SNAKE_CASE				    =		initializer_range





     def     __UpperCamelCase						(		self					:	Any)							->	List[str]:

      """simple docstring"""
      SCREAMING_SNAKE_CASE				    =		copy.deepcopy(self.__dict__)
      SCREAMING_SNAKE_CASE				    =		self.vision_config.to_dict()
      SCREAMING_SNAKE_CASE				    =		self.prompt_encoder_config.to_dict()
      SCREAMING_SNAKE_CASE				    =		self.mask_decoder_config.to_dict()
      SCREAMING_SNAKE_CASE				    =		self.__class__.model_type
      return output







import posixpath
from pathlib import Path
from unittest.mock import patch

import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry







class 						lowercase     (					_lowercase				):


		"""simple docstring"""




		a__       							=	"mock"


		def __init__(					self						,							*__snake_case						,							__snake_case						,							**__snake_case):
			super().__init__()
			_UpperCamelCase :		str								=    LocalFileSystem(*__snake_case						,							**__snake_case)
			_UpperCamelCase :		str								=    Path(__snake_case).resolve().as_posix() + '/'


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		int								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.mkdir(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		List[str]								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.makedirs(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.rmdir(__snake_case)


		def 		A__       (					self						,							__snake_case						,							__snake_case=True						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		Union[str, Any]								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			_UpperCamelCase :		Tuple								=    self._fs.ls(__snake_case						,							detail=__snake_case						,							*__snake_case						,							**__snake_case)
			if detail:
				return [{**info, "name": info["name"][len(self.local_root_dir) :]} for info in out]
			else:
				return [name[len(self.local_root_dir) :] for name in out]


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		Optional[Any]								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			_UpperCamelCase :		Optional[Any]								=    dict(self._fs.info(__snake_case						,							*__snake_case						,							**__snake_case))
			_UpperCamelCase :		Dict								=    out['name'][len(self.local_root_dir) :]
			return out


		def 		A__       (					self						,							__snake_case						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		str								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			_UpperCamelCase :		Tuple								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.cp_file(__snake_case						,							__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.rm_file(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		int								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.rm(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case						,							*__snake_case						,							**__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs._open(__snake_case						,							*__snake_case						,							**__snake_case)


		def 		A__       (					self						,							__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.created(__snake_case)


		def 		A__       (					self						,							__snake_case):
			_UpperCamelCase :		Dict								=    posixpath.join(self.local_root_dir						,							self._strip_protocol(__snake_case))
			return self._fs.modified(__snake_case)






		@classmethod
		def 		A__       (					cls						,							__snake_case):
			_UpperCamelCase :		List[Any]								=    stringify_path(__snake_case)
			if path.startswith('mock://'):
				_UpperCamelCase :		int								=    path[7:]
			return path







class 						lowercase     (					_lowercase				):


		"""simple docstring"""




		a__       							=	"tmp"
		a__       							=	None


		def __init__(					self						,							*__snake_case						,							**__snake_case):
			assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
			super().__init__(*__snake_case						,							**__snake_case						,							local_root_dir=self.tmp_dir						,							auto_mkdir=__snake_case)






		@classmethod
		def 		A__       (					cls						,							__snake_case):
			_UpperCamelCase :		Optional[int]								=    stringify_path(__snake_case)
			if path.startswith('tmp://'):
				_UpperCamelCase :		Optional[Any]								=    path[6:]
			return path






@pytest.fixture
def        lowerCamelCase_  (				)    ->					Dict:




	'''simple docstring'''




	_UpperCamelCase :		List[str]								=    MockFileSystem
	_UpperCamelCase :		Optional[int]								=    TmpDirFileSystem
	yield
	del _fsspec_registry["mock"]
	del _fsspec_registry["tmp"]






@pytest.fixture
def        lowerCamelCase_  (				UpperCAmelCase_				:  Any				,							UpperCAmelCase_				:  Optional[int]						)    ->					Optional[int]:




	'''simple docstring'''




	_UpperCamelCase :		str								=    tmp_path_factory.mktemp('mockfs'						)
	return MockFileSystem(local_root_dir=UpperCAmelCase_				,							auto_mkdir=UpperCAmelCase_						)







@pytest.fixture
def        lowerCamelCase_  (				UpperCAmelCase_				:  Tuple				,							UpperCAmelCase_				:  Union[str, Any]						)    ->					int:




	'''simple docstring'''




	_UpperCamelCase :		Dict								=    tmp_path_factory.mktemp('tmpfs'						)
	with patch.object(UpperCAmelCase_				,							'tmp_dir'				,							UpperCAmelCase_						):
		yield TmpDirFileSystem()




