


'''simple docstring'''



from copy import deepcopy
from typing import Optional, Union

import numpy as np

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
from ...utils import TensorType, is_tf_available, is_torch_available


if is_torch_available():
	import torch

if is_tf_available():
	import tensorflow as tf






class 	UpperCamelCase__(       lowerCAmelCase	):
				__magic_name__    :				Optional[Any]  		=	["image_processor"]
				__magic_name__    :				Union[str, Any]  		=	"SamImageProcessor"




				def __init__(		self      :			Dict				,   lowerCAmelCase      :			int				)->					Any:

										"""simple docstring"""




										super().__init__(lowerCAmelCase				)
										UpperCAmelCase					    =     self.image_processor
										UpperCAmelCase					    =     -10
										UpperCAmelCase					    =     self.image_processor.size['''longest_edge''']




				def __call__(		self      :			str				,   lowerCAmelCase      :			str=None				,   lowerCAmelCase      :			Any=None				,   lowerCAmelCase      :			Tuple=None				,   lowerCAmelCase      :			Optional[Any]=None				,   lowerCAmelCase      :			Optional[Union[str, TensorType]] = None				,   **lowerCAmelCase      :			Optional[int]				,   )->					BatchEncoding:

										"""simple docstring"""




										UpperCAmelCase					    =     self.image_processor(
										    lowerCAmelCase				,   return_tensors=lowerCAmelCase				,   **lowerCAmelCase				,   )

										# pop arguments that are not used in the foward but used nevertheless
										UpperCAmelCase					    =     encoding_image_processor['''original_sizes''']

										if hasattr(lowerCAmelCase				,   '''numpy'''				):  # Checks if Torch or TF tensor
																UpperCAmelCase					    =     original_sizes.numpy()

										UpperCAmelCase    ,    UpperCAmelCase    ,    UpperCAmelCase					    =     self._check_and_preprocess_points(
										    input_points=lowerCAmelCase				,   input_labels=lowerCAmelCase				,   input_boxes=lowerCAmelCase				,   )

										UpperCAmelCase					    =     self._normalize_and_convert(
										    lowerCAmelCase				,   lowerCAmelCase				,   input_points=lowerCAmelCase				,   input_labels=lowerCAmelCase				,   input_boxes=lowerCAmelCase				,   return_tensors=lowerCAmelCase				,   )

										return encoding_image_processor




				def 					a__(		self      :			List[Any]				,   lowerCAmelCase      :			int				,   lowerCAmelCase      :			Optional[int]				,   lowerCAmelCase      :			Optional[int]=None				,   lowerCAmelCase      :			Optional[int]=None				,   lowerCAmelCase      :			Optional[int]=None				,   lowerCAmelCase      :			Union[str, Any]="pt"				,   )->					Optional[Any]:

										"""simple docstring"""




										if input_points is not None:
																if len(lowerCAmelCase				) != len(lowerCAmelCase				):
																						UpperCAmelCase					    =     [
																						    self._normalize_coordinates(self.target_size				,   lowerCAmelCase				,   original_sizes[0]				) for point in input_points
																						]
																else:
																						UpperCAmelCase					    =     [
																						    self._normalize_coordinates(self.target_size				,   lowerCAmelCase				,   lowerCAmelCase				)
																						    for point, original_size in zip(lowerCAmelCase				,   lowerCAmelCase				)
																						]
																# check that all arrays have the same shape
																if not all(point.shape == input_points[0].shape for point in input_points				):
																						if input_labels is not None:
																												UpperCAmelCase    ,    UpperCAmelCase					    =     self._pad_points_and_labels(lowerCAmelCase				,   lowerCAmelCase				)

																UpperCAmelCase					    =     np.array(lowerCAmelCase				)

										if input_labels is not None:
																UpperCAmelCase					    =     np.array(lowerCAmelCase				)

										if input_boxes is not None:
																if len(lowerCAmelCase				) != len(lowerCAmelCase				):
																						UpperCAmelCase					    =     [
																						    self._normalize_coordinates(self.target_size				,   lowerCAmelCase				,   original_sizes[0]				,   is_bounding_box=lowerCAmelCase				)
																						    for box in input_boxes
																						]
																else:
																						UpperCAmelCase					    =     [
																						    self._normalize_coordinates(self.target_size				,   lowerCAmelCase				,   lowerCAmelCase				,   is_bounding_box=lowerCAmelCase				)
																						    for box, original_size in zip(lowerCAmelCase				,   lowerCAmelCase				)
																						]
																UpperCAmelCase					    =     np.array(lowerCAmelCase				)

										if input_boxes is not None:
																if return_tensors == "pt":
																						UpperCAmelCase					    =     torch.from_numpy(lowerCAmelCase				)
																						# boxes batch size of 1 by default
																						UpperCAmelCase					    =     input_boxes.unsqueeze(1				) if len(input_boxes.shape				) != 3 else input_boxes
																elif return_tensors == "tf":
																						UpperCAmelCase					    =     tf.convert_to_tensor(lowerCAmelCase				)
																						# boxes batch size of 1 by default
																						UpperCAmelCase					    =     tf.expand_dims(lowerCAmelCase				,   1				) if len(input_boxes.shape				) != 3 else input_boxes
																encoding_image_processor.update({'''input_boxes''': input_boxes}				)
										if input_points is not None:
																if return_tensors == "pt":
																						UpperCAmelCase					    =     torch.from_numpy(lowerCAmelCase				)
																						# point batch size of 1 by default
																						UpperCAmelCase					    =     input_points.unsqueeze(1				) if len(input_points.shape				) != 4 else input_points
																elif return_tensors == "tf":
																						UpperCAmelCase					    =     tf.convert_to_tensor(lowerCAmelCase				)
																						# point batch size of 1 by default
																						UpperCAmelCase					    =     tf.expand_dims(lowerCAmelCase				,   1				) if len(input_points.shape				) != 4 else input_points
																encoding_image_processor.update({'''input_points''': input_points}				)
										if input_labels is not None:
																if return_tensors == "pt":
																						UpperCAmelCase					    =     torch.from_numpy(lowerCAmelCase				)
																						# point batch size of 1 by default
																						UpperCAmelCase					    =     input_labels.unsqueeze(1				) if len(input_labels.shape				) != 3 else input_labels
																elif return_tensors == "tf":
																						UpperCAmelCase					    =     tf.convert_to_tensor(lowerCAmelCase				)
																						# point batch size of 1 by default
																						UpperCAmelCase					    =     tf.expand_dims(lowerCAmelCase				,   1				) if len(input_labels.shape				) != 3 else input_labels
																encoding_image_processor.update({'''input_labels''': input_labels}				)

										return encoding_image_processor




				def 					a__(		self      :			List[str]				,   lowerCAmelCase      :			List[Any]				,   lowerCAmelCase      :			Any				)->					int:

										"""simple docstring"""




										UpperCAmelCase					    =     max([point.shape[0] for point in input_points]				)
										UpperCAmelCase					    =     []
										for i, point in enumerate(lowerCAmelCase				):
																if point.shape[0] != expected_nb_points:
																						UpperCAmelCase					    =     np.concatenate(
																						    [point, np.zeros((expected_nb_points - point.shape[0], 2)				) + self.point_pad_value]				,   axis=0				)
																						UpperCAmelCase					    =     np.append(input_labels[i]				,   [self.point_pad_value]				)
																processed_input_points.append(lowerCAmelCase				)
										UpperCAmelCase					    =     processed_input_points
										return input_points, input_labels




				def 					a__(		self      :			Tuple				,   lowerCAmelCase      :			int				,   lowerCAmelCase      :			np.ndarray				,   lowerCAmelCase      :			Any				,   lowerCAmelCase      :			List[str]=False				)->					np.ndarray:

										"""simple docstring"""




										UpperCAmelCase    ,    UpperCAmelCase					    =     original_size
										UpperCAmelCase    ,    UpperCAmelCase					    =     self.image_processor._get_preprocess_shape(lowerCAmelCase				,   longest_edge=lowerCAmelCase				)
										UpperCAmelCase					    =     deepcopy(lowerCAmelCase				).astype(lowerCAmelCase				)

										if is_bounding_box:
																UpperCAmelCase					    =     coords.reshape(-1				,   2				,   2				)

										UpperCAmelCase					    =     coords[..., 0] * (new_w / old_w)
										UpperCAmelCase					    =     coords[..., 1] * (new_h / old_h)

										if is_bounding_box:
																UpperCAmelCase					    =     coords.reshape(-1				,   4				)

										return coords




				def 					a__(		self      :			Tuple				,   lowerCAmelCase      :			Any=None				,   lowerCAmelCase      :			List[Any]=None				,   lowerCAmelCase      :			Dict=None				,   )->					Any:

										"""simple docstring"""




										if input_points is not None:
																if hasattr(lowerCAmelCase				,   '''numpy'''				):  # Checks for TF or Torch tensor
																						UpperCAmelCase					    =     input_points.numpy().tolist()

																if not isinstance(lowerCAmelCase				,   lowerCAmelCase				) or not isinstance(input_points[0]				,   lowerCAmelCase				):
																						raise ValueError('''Input points must be a list of list of floating points.'''				)
																UpperCAmelCase					    =     [np.array(lowerCAmelCase				) for input_point in input_points]
										else:
																UpperCAmelCase					    =     None

										if input_labels is not None:
																if hasattr(lowerCAmelCase				,   '''numpy'''				):
																						UpperCAmelCase					    =     input_labels.numpy().tolist()

																if not isinstance(lowerCAmelCase				,   lowerCAmelCase				) or not isinstance(input_labels[0]				,   lowerCAmelCase				):
																						raise ValueError('''Input labels must be a list of list integers.'''				)
																UpperCAmelCase					    =     [np.array(lowerCAmelCase				) for label in input_labels]
										else:
																UpperCAmelCase					    =     None

										if input_boxes is not None:
																if hasattr(lowerCAmelCase				,   '''numpy'''				):
																						UpperCAmelCase					    =     input_boxes.numpy().tolist()

																if (
																    not isinstance(lowerCAmelCase				,   lowerCAmelCase				)
																    or not isinstance(input_boxes[0]				,   lowerCAmelCase				)
																    or not isinstance(input_boxes[0][0]				,   lowerCAmelCase				)
																):
																						raise ValueError('''Input boxes must be a list of list of list of floating points.'''				)
																UpperCAmelCase					    =     [np.array(lowerCAmelCase				).astype(np.floataa				) for box in input_boxes]
										else:
																UpperCAmelCase					    =     None

										return input_points, input_labels, input_boxes




				@property
				def 					a__(		self      :			Optional[int]				)->					Optional[Any]:

										"""simple docstring"""




										UpperCAmelCase					    =     self.image_processor.model_input_names
										return list(dict.fromkeys(lowerCAmelCase				)				)





				def 					a__(		self      :			str				,   *lowerCAmelCase      :			List[str]				,   **lowerCAmelCase      :			int				)->					Union[str, Any]:

										"""simple docstring"""




										return self.image_processor.post_process_masks(*lowerCAmelCase				,   **lowerCAmelCase				)









'''simple docstring'''



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


_lowercase      :      int            =					logging.get_logger(__name__)

_lowercase      :      Optional[Any]            =					{"""openai-gpt""": """https://huggingface.co/openai-gpt/resolve/main/config.json"""}






class 	UpperCamelCase__(       lowerCAmelCase	):
				__magic_name__    :				Union[str, Any]  		=	"openai-gpt"
				__magic_name__    :				Optional[int]  		=	{
				    "max_position_embeddings": "n_positions",
				    "hidden_size": "n_embd",
				    "num_attention_heads": "n_head",
				    "num_hidden_layers": "n_layer",
				}




				def __init__(		self      :			Optional[int]				,   lowerCAmelCase      :			Optional[Any]=40478				,   lowerCAmelCase      :			str=512				,   lowerCAmelCase      :			List[Any]=768				,   lowerCAmelCase      :			Tuple=12				,   lowerCAmelCase      :			int=12				,   lowerCAmelCase      :			List[str]="gelu"				,   lowerCAmelCase      :			List[str]=0.1				,   lowerCAmelCase      :			List[Any]=0.1				,   lowerCAmelCase      :			Dict=0.1				,   lowerCAmelCase      :			Tuple=1E-5				,   lowerCAmelCase      :			Tuple=0.02				,   lowerCAmelCase      :			Optional[int]="cls_index"				,   lowerCAmelCase      :			Dict=True				,   lowerCAmelCase      :			Optional[int]=None				,   lowerCAmelCase      :			Dict=True				,   lowerCAmelCase      :			int=0.1				,   **lowerCAmelCase      :			Optional[int]				,   )->					str:

										"""simple docstring"""




										UpperCAmelCase					    =     vocab_size
										UpperCAmelCase					    =     n_positions
										UpperCAmelCase					    =     n_embd
										UpperCAmelCase					    =     n_layer
										UpperCAmelCase					    =     n_head
										UpperCAmelCase					    =     afn
										UpperCAmelCase					    =     resid_pdrop
										UpperCAmelCase					    =     embd_pdrop
										UpperCAmelCase					    =     attn_pdrop
										UpperCAmelCase					    =     layer_norm_epsilon
										UpperCAmelCase					    =     initializer_range
										UpperCAmelCase					    =     summary_type
										UpperCAmelCase					    =     summary_use_proj
										UpperCAmelCase					    =     summary_activation
										UpperCAmelCase					    =     summary_first_dropout
										UpperCAmelCase					    =     summary_proj_to_labels
										super().__init__(**lowerCAmelCase				)





