





'''simple docstring'''

import copy

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


lowerCAmelCase__	:					Optional[Any]	     =       logging.get_logger(__name__)

lowerCAmelCase__	:					List[Any]	     =       {
    '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 			SCREAMING_SNAKE_CASE__	(					_a						):







					"""simple docstring"""






					def __init__(					self    :	str						,     UpperCAmelCase_    :	Optional[Any]=256						,     UpperCAmelCase_    :	List[str]=1_024						,     UpperCAmelCase_    :	Dict=16						,     UpperCAmelCase_    :	int=16						,     UpperCAmelCase_    :	Tuple=4						,     UpperCAmelCase_    :	Any="gelu"						,     UpperCAmelCase_    :	int=1e-6						,     **UpperCAmelCase_    :	Optional[Any]						,     ):







							"""simple docstring"""
							super().__init__(**lowerCAmelCase_						)
							__UpperCAmelCase     :				Union[str, Any]					   =			hidden_size
							__UpperCAmelCase     :				Union[str, Any]					   =			image_size
							__UpperCAmelCase     :				Any					   =			patch_size
							__UpperCAmelCase     :				str					   =			image_size // patch_size
							__UpperCAmelCase     :				str					   =			mask_input_channels
							__UpperCAmelCase     :				Any					   =			num_point_embeddings
							__UpperCAmelCase     :				List[Any]					   =			hidden_act
							__UpperCAmelCase     :				List[str]					   =			layer_norm_eps






class 			SCREAMING_SNAKE_CASE__	(					_a						):







					"""simple docstring"""






					def __init__(					self    :	Dict						,     UpperCAmelCase_    :	Tuple=256						,     UpperCAmelCase_    :	Union[str, Any]="relu"						,     UpperCAmelCase_    :	List[Any]=2_048						,     UpperCAmelCase_    :	str=2						,     UpperCAmelCase_    :	Optional[Any]=8						,     UpperCAmelCase_    :	int=2						,     UpperCAmelCase_    :	Any=3						,     UpperCAmelCase_    :	int=3						,     UpperCAmelCase_    :	Union[str, Any]=256						,     UpperCAmelCase_    :	Any=1e-6						,     **UpperCAmelCase_    :	Any						,     ):







							"""simple docstring"""
							super().__init__(**lowerCAmelCase_						)
							__UpperCAmelCase     :				List[Any]					   =			hidden_size
							__UpperCAmelCase     :				List[Any]					   =			hidden_act
							__UpperCAmelCase     :				str					   =			mlp_dim
							__UpperCAmelCase     :				Union[str, Any]					   =			num_hidden_layers
							__UpperCAmelCase     :				str					   =			num_attention_heads
							__UpperCAmelCase     :				Any					   =			attention_downsample_rate
							__UpperCAmelCase     :				List[str]					   =			num_multimask_outputs
							__UpperCAmelCase     :				List[str]					   =			iou_head_depth
							__UpperCAmelCase     :				Any					   =			iou_head_hidden_dim
							__UpperCAmelCase     :				List[Any]					   =			layer_norm_eps






class 			SCREAMING_SNAKE_CASE__	(					_a						):







					"""simple docstring"""






					def __init__(					self    :	Union[str, Any]						,     UpperCAmelCase_    :	List[str]=768						,     UpperCAmelCase_    :	Dict=256						,     UpperCAmelCase_    :	int=12						,     UpperCAmelCase_    :	Optional[Any]=12						,     UpperCAmelCase_    :	Any=3						,     UpperCAmelCase_    :	str=1_024						,     UpperCAmelCase_    :	Optional[Any]=16						,     UpperCAmelCase_    :	Dict="gelu"						,     UpperCAmelCase_    :	List[str]=1e-06						,     UpperCAmelCase_    :	Tuple=0.0						,     UpperCAmelCase_    :	List[Any]=1e-10						,     UpperCAmelCase_    :	Dict=True						,     UpperCAmelCase_    :	str=4.0						,     UpperCAmelCase_    :	Optional[Any]=True						,     UpperCAmelCase_    :	List[Any]=True						,     UpperCAmelCase_    :	List[str]=14						,     UpperCAmelCase_    :	Optional[Any]=[2, 5, 8, 11]						,     UpperCAmelCase_    :	List[str]=128						,     UpperCAmelCase_    :	List[str]=None						,     **UpperCAmelCase_    :	Union[str, Any]						,     ):







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

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






class 			SCREAMING_SNAKE_CASE__	(					_a						):







					"""simple docstring"""






					SCREAMING_SNAKE_CASE				=     '''sam'''
					SCREAMING_SNAKE_CASE				=     True
					def __init__(					self    :	Dict						,     UpperCAmelCase_    :	List[str]=None						,     UpperCAmelCase_    :	List[str]=None						,     UpperCAmelCase_    :	Optional[Any]=None						,     UpperCAmelCase_    :	str=0.02						,     **UpperCAmelCase_    :	Optional[int]						,     ):







							"""simple docstring"""
							super().__init__(**lowerCAmelCase_						)
							__UpperCAmelCase     :				Any					   =			vision_config if vision_config is not None else {}
							__UpperCAmelCase     :				Union[str, Any]					   =			prompt_encoder_config if prompt_encoder_config is not None else {}
							__UpperCAmelCase     :				Optional[Any]					   =			mask_decoder_config if mask_decoder_config is not None else {}

							if isinstance(lowerCAmelCase_						,     lowerCAmelCase_						):
									__UpperCAmelCase     :				List[str]					   =			vision_config.to_dict()
							if isinstance(lowerCAmelCase_						,     lowerCAmelCase_						):
									__UpperCAmelCase     :				List[str]					   =			prompt_encoder_config.to_dict()
							if isinstance(lowerCAmelCase_						,     lowerCAmelCase_						):
									__UpperCAmelCase     :				Dict					   =			mask_decoder_config.to_dict()

							__UpperCAmelCase     :				int					   =			SamVisionConfig(**lowerCAmelCase_						)
							__UpperCAmelCase     :				List[str]					   =			SamPromptEncoderConfig(**lowerCAmelCase_						)
							__UpperCAmelCase     :				Optional[int]					   =			SamMaskDecoderConfig(**lowerCAmelCase_						)
							__UpperCAmelCase     :				Optional[int]					   =			initializer_range






					def 						lowerCamelCase_					(					self    :	List[str]						):







							"""simple docstring"""
							__UpperCAmelCase     :				Tuple					   =			copy.deepcopy(self.__dict__						)
							__UpperCAmelCase     :				Optional[int]					   =			self.vision_config.to_dict()
							__UpperCAmelCase     :				Dict					   =			self.prompt_encoder_config.to_dict()
							__UpperCAmelCase     :				Dict					   =			self.mask_decoder_config.to_dict()
							__UpperCAmelCase     :				Tuple					   =			self.__class__.model_type
							return output










'''simple docstring'''


import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
				from PIL import Image

class 			A    (		unittest.TestCase     ,_a    ):







							def    __lowerCAmelCase			(  self       :  Optional[int]					)			->							Optional[int]:


														"""simple docstring"""


														_a	     =				load_tool('''image-question-answering'''					)
														self.tool.setup()
														_a	     =				load_tool('''image-question-answering'''							,			remote=lowerCAmelCase_					)







							def    __lowerCAmelCase			(  self       :  Tuple					)			->							Optional[int]:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.tool(lowerCAmelCase_							,			'''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)







							def    __lowerCAmelCase			(  self       :  List[str]					)			->							Union[str, Any]:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.remote_tool(lowerCAmelCase_							,			'''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)







							def    __lowerCAmelCase			(  self       :  Dict					)			->							Tuple:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.tool(image=lowerCAmelCase_							,			question='''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)







							def    __lowerCAmelCase			(  self       :  Tuple					)			->							Dict:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.remote_tool(image=lowerCAmelCase_							,			question='''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)

