






"""simple docstring"""

from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


lowercase           =							logging.get_logger(__name__)

class     A_				(   snake_case_	):
				UpperCAmelCase__										=					['''pixel_values''']







				def __init__(				self				:    List[Any]    ,     __lowerCamelCase				:    bool = True    ,     __lowerCamelCase				:    Optional[Dict[str, int]] = None    ,     __lowerCamelCase				:    PILImageResampling = PILImageResampling.BILINEAR    ,     __lowerCamelCase				:    bool = True    ,     __lowerCamelCase				:    Union[int, float] = 1 / 2_5_5    ,     __lowerCamelCase				:    bool = True    ,     __lowerCamelCase				:    Optional[Union[float, List[float]]] = None    ,     __lowerCamelCase				:    Optional[Union[float, List[float]]] = None    ,     **__lowerCamelCase				:    Union[str, Any]    ,     )					->       None:
										super().__init__(**__lowerCamelCase						)
										__magic_name__      =  size if size is not None else {"height": 2_2_4, "width": 2_2_4}
										__magic_name__      =  get_size_dict(__lowerCamelCase						)
										__magic_name__      =  do_resize
										__magic_name__      =  do_rescale
										__magic_name__      =  do_normalize
										__magic_name__      =  size
										__magic_name__      =  resample
										__magic_name__      =  rescale_factor
										__magic_name__      =  image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
										__magic_name__      =  image_std if image_std is not None else IMAGENET_STANDARD_STD







				def      _snake_case       (				self				:    Any    ,     __lowerCamelCase				:    np.ndarray    ,     __lowerCamelCase				:    Dict[str, int]    ,     __lowerCamelCase				:    PILImageResampling = PILImageResampling.BILINEAR    ,     __lowerCamelCase				:    Optional[Union[str, ChannelDimension]] = None    ,     **__lowerCamelCase				:    List[str]    ,     )					->       np.ndarray:
										__magic_name__      =  get_size_dict(__lowerCamelCase						)
										if "height" not in size or "width" not in size:
																raise ValueError(f'''The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'''						)
										return resize(
										    __lowerCamelCase    ,     size=(size["height"], size["width"])    ,     resample=__lowerCamelCase    ,     data_format=__lowerCamelCase    ,     **__lowerCamelCase						)







				def      _snake_case       (				self				:    Union[str, Any]    ,     __lowerCamelCase				:    np.ndarray    ,     __lowerCamelCase				:    float    ,     __lowerCamelCase				:    Optional[Union[str, ChannelDimension]] = None    ,     **__lowerCamelCase				:    Dict						)					->       np.ndarray:
										return rescale(__lowerCamelCase    ,     scale=__lowerCamelCase    ,     data_format=__lowerCamelCase    ,     **__lowerCamelCase						)







				def      _snake_case       (				self				:    List[str]    ,     __lowerCamelCase				:    np.ndarray    ,     __lowerCamelCase				:    Union[float, List[float]]    ,     __lowerCamelCase				:    Union[float, List[float]]    ,     __lowerCamelCase				:    Optional[Union[str, ChannelDimension]] = None    ,     **__lowerCamelCase				:    Optional[Any]    ,     )					->       np.ndarray:
										return normalize(__lowerCamelCase    ,     mean=__lowerCamelCase    ,     std=__lowerCamelCase    ,     data_format=__lowerCamelCase    ,     **__lowerCamelCase						)







				def      _snake_case       (				self				:    Union[str, Any]    ,     __lowerCamelCase				:    ImageInput    ,     __lowerCamelCase				:    Optional[bool] = None    ,     __lowerCamelCase				:    Dict[str, int] = None    ,     __lowerCamelCase				:    PILImageResampling = None    ,     __lowerCamelCase				:    Optional[bool] = None    ,     __lowerCamelCase				:    Optional[float] = None    ,     __lowerCamelCase				:    Optional[bool] = None    ,     __lowerCamelCase				:    Optional[Union[float, List[float]]] = None    ,     __lowerCamelCase				:    Optional[Union[float, List[float]]] = None    ,     __lowerCamelCase				:    Optional[Union[str, TensorType]] = None    ,     __lowerCamelCase				:    Union[str, ChannelDimension] = ChannelDimension.FIRST    ,     **__lowerCamelCase				:    Any    ,     )					->       str:
										__magic_name__      =  do_resize if do_resize is not None else self.do_resize
										__magic_name__      =  do_rescale if do_rescale is not None else self.do_rescale
										__magic_name__      =  do_normalize if do_normalize is not None else self.do_normalize
										__magic_name__      =  resample if resample is not None else self.resample
										__magic_name__      =  rescale_factor if rescale_factor is not None else self.rescale_factor
										__magic_name__      =  image_mean if image_mean is not None else self.image_mean
										__magic_name__      =  image_std if image_std is not None else self.image_std

										__magic_name__      =  size if size is not None else self.size
										__magic_name__      =  get_size_dict(__lowerCamelCase						)

										__magic_name__      =  make_list_of_images(__lowerCamelCase						)

										if not valid_images(__lowerCamelCase						):
																raise ValueError(
																    "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
																    "torch.Tensor, tf.Tensor or jax.ndarray."						)

										if do_resize and size is None:
																raise ValueError("Size must be specified if do_resize is True."						)

										if do_rescale and rescale_factor is None:
																raise ValueError("Rescale factor must be specified if do_rescale is True."						)

										# All transformations expect numpy arrays.
										__magic_name__      =  [to_numpy_array(__lowerCamelCase						) for image in images]

										if do_resize:
																__magic_name__      =  [self.resize(image=__lowerCamelCase    ,     size=__lowerCamelCase    ,     resample=__lowerCamelCase						) for image in images]

										if do_rescale:
																__magic_name__      =  [self.rescale(image=__lowerCamelCase    ,     scale=__lowerCamelCase						) for image in images]

										if do_normalize:
																__magic_name__      =  [self.normalize(image=__lowerCamelCase    ,     mean=__lowerCamelCase    ,     std=__lowerCamelCase						) for image in images]

										__magic_name__      =  [to_channel_dimension_format(__lowerCamelCase    ,     __lowerCamelCase						) for image in images]

										__magic_name__      =  {"pixel_values": images}
										return BatchFeature(data=__lowerCamelCase    ,     tensor_type=__lowerCamelCase						)











"""simple docstring"""

import copy

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


lowercase           =							logging.get_logger(__name__)

lowercase           =							{
    '''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_				(   snake_case_	):







				def __init__(				self				:    List[Any]    ,     __lowerCamelCase				:    str=2_5_6    ,     __lowerCamelCase				:    str=1_0_2_4    ,     __lowerCamelCase				:    Optional[Any]=1_6    ,     __lowerCamelCase				:    Union[str, Any]=1_6    ,     __lowerCamelCase				:    str=4    ,     __lowerCamelCase				:    Union[str, Any]="gelu"    ,     __lowerCamelCase				:    Optional[int]=1e-6    ,     **__lowerCamelCase				:    str    ,     )					->       List[Any]:
										super().__init__(**__lowerCamelCase						)
										__magic_name__      =  hidden_size
										__magic_name__      =  image_size
										__magic_name__      =  patch_size
										__magic_name__      =  image_size // patch_size
										__magic_name__      =  mask_input_channels
										__magic_name__      =  num_point_embeddings
										__magic_name__      =  hidden_act
										__magic_name__      =  layer_norm_eps





class     A_				(   snake_case_	):







				def __init__(				self				:    List[str]    ,     __lowerCamelCase				:    Optional[Any]=2_5_6    ,     __lowerCamelCase				:    int="relu"    ,     __lowerCamelCase				:    List[str]=2_0_4_8    ,     __lowerCamelCase				:    Optional[Any]=2    ,     __lowerCamelCase				:    Optional[Any]=8    ,     __lowerCamelCase				:    Optional[Any]=2    ,     __lowerCamelCase				:    Dict=3    ,     __lowerCamelCase				:    Optional[int]=3    ,     __lowerCamelCase				:    Tuple=2_5_6    ,     __lowerCamelCase				:    List[str]=1e-6    ,     **__lowerCamelCase				:    Any    ,     )					->       str:
										super().__init__(**__lowerCamelCase						)
										__magic_name__      =  hidden_size
										__magic_name__      =  hidden_act
										__magic_name__      =  mlp_dim
										__magic_name__      =  num_hidden_layers
										__magic_name__      =  num_attention_heads
										__magic_name__      =  attention_downsample_rate
										__magic_name__      =  num_multimask_outputs
										__magic_name__      =  iou_head_depth
										__magic_name__      =  iou_head_hidden_dim
										__magic_name__      =  layer_norm_eps





class     A_				(   snake_case_	):







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

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





class     A_				(   snake_case_	):
				UpperCAmelCase__										=					'''sam'''
				UpperCAmelCase__										=					True







				def __init__(				self				:    Optional[Any]    ,     __lowerCamelCase				:    Dict=None    ,     __lowerCamelCase				:    Dict=None    ,     __lowerCamelCase				:    Optional[Any]=None    ,     __lowerCamelCase				:    int=0.02    ,     **__lowerCamelCase				:    List[Any]    ,     )					->       List[str]:
										super().__init__(**__lowerCamelCase						)
										__magic_name__      =  vision_config if vision_config is not None else {}
										__magic_name__      =  prompt_encoder_config if prompt_encoder_config is not None else {}
										__magic_name__      =  mask_decoder_config if mask_decoder_config is not None else {}

										if isinstance(__lowerCamelCase    ,     __lowerCamelCase						):
																__magic_name__      =  vision_config.to_dict()
										if isinstance(__lowerCamelCase    ,     __lowerCamelCase						):
																__magic_name__      =  prompt_encoder_config.to_dict()
										if isinstance(__lowerCamelCase    ,     __lowerCamelCase						):
																__magic_name__      =  mask_decoder_config.to_dict()

										__magic_name__      =  SamVisionConfig(**__lowerCamelCase						)
										__magic_name__      =  SamPromptEncoderConfig(**__lowerCamelCase						)
										__magic_name__      =  SamMaskDecoderConfig(**__lowerCamelCase						)
										__magic_name__      =  initializer_range







				def      _snake_case       (				self				:    Optional[int]						)					->       str:
										__magic_name__      =  copy.deepcopy(self.__dict__						)
										__magic_name__      =  self.vision_config.to_dict()
										__magic_name__      =  self.prompt_encoder_config.to_dict()
										__magic_name__      =  self.mask_decoder_config.to_dict()
										__magic_name__      =  self.__class__.model_type
										return output



