
"""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 __lowerCAmelCase				(					__lowercase      ):




			"""simple docstring"""







			snake_case	      =				["image_processor"]
			snake_case	      =				"SamImageProcessor"




			def __init__(				self						:					List[str]       ,   _snake_case						:					int	)      -> List[Any]:







								"""simple docstring"""
								super().__init__(_A	)
								A_				 =						self.image_processor
								A_				 =						-10
								A_				 =						self.image_processor.size["longest_edge"]




			def __call__(				self						:					Optional[Any]       ,   _snake_case						:					Tuple=None       ,   _snake_case						:					List[Any]=None       ,   _snake_case						:					Dict=None       ,   _snake_case						:					Any=None       ,   _snake_case						:					Optional[Union[str, TensorType]] = None       ,   **_snake_case						:					List[str]       ,   )      -> Dict:







								"""simple docstring"""
								A_				 =						self.image_processor(
								    _A       ,   return_tensors=_A       ,   **_A       ,   )

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

								if hasattr(_A       ,   "numpy"	):  # Checks if Torch or TF tensor
													A_				 =						original_sizes.numpy()

								A_ ,    A_ ,    A_				 =						self._check_and_preprocess_points(
								    input_points=_A       ,   input_labels=_A       ,   input_boxes=_A       ,   )

								A_				 =						self._normalize_and_convert(
								    _A       ,   _A       ,   input_points=_A       ,   input_labels=_A       ,   input_boxes=_A       ,   return_tensors=_A       ,   )

								return encoding_image_processor




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







								"""simple docstring"""
								if input_points is not None:
													if len(_A	) != len(_A	):
																		A_				 =						[
																		    self._normalize_coordinates(self.target_size       ,   _A       ,   original_sizes[0]	) for point in input_points
																		]
													else:
																		A_				 =						[
																		    self._normalize_coordinates(self.target_size       ,   _A       ,   _A	)
																		    for point, original_size in zip(_A       ,   _A	)
																		]
													# 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:
																							A_ ,    A_				 =						self._pad_points_and_labels(_A       ,   _A	)

													A_				 =						np.array(_A	)

								if input_labels is not None:
													A_				 =						np.array(_A	)

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

								if input_boxes is not None:
													if return_tensors == "pt":
																		A_				 =						torch.from_numpy(_A	)
																		# boxes batch size of 1 by default
																		A_				 =						input_boxes.unsqueeze(1	) if len(input_boxes.shape	) != 3 else input_boxes
													elif return_tensors == "tf":
																		A_				 =						tf.convert_to_tensor(_A	)
																		# boxes batch size of 1 by default
																		A_				 =						tf.expand_dims(_A       ,   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":
																		A_				 =						torch.from_numpy(_A	)
																		# point batch size of 1 by default
																		A_				 =						input_points.unsqueeze(1	) if len(input_points.shape	) != 4 else input_points
													elif return_tensors == "tf":
																		A_				 =						tf.convert_to_tensor(_A	)
																		# point batch size of 1 by default
																		A_				 =						tf.expand_dims(_A       ,   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":
																		A_				 =						torch.from_numpy(_A	)
																		# point batch size of 1 by default
																		A_				 =						input_labels.unsqueeze(1	) if len(input_labels.shape	) != 3 else input_labels
													elif return_tensors == "tf":
																		A_				 =						tf.convert_to_tensor(_A	)
																		# point batch size of 1 by default
																		A_				 =						tf.expand_dims(_A       ,   1	) if len(input_labels.shape	) != 3 else input_labels
													encoding_image_processor.update({"input_labels": input_labels}	)

								return encoding_image_processor




			def      lowerCamelCase__     (				self						:					Any       ,   _snake_case						:					str       ,   _snake_case						:					Dict	)      -> Any:







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




			def      lowerCamelCase__     (				self						:					List[Any]       ,   _snake_case						:					int       ,   _snake_case						:					np.ndarray       ,   _snake_case						:					Any       ,   _snake_case						:					Dict=False	)      -> Any:







								"""simple docstring"""
								A_ ,    A_				 =						original_size
								A_ ,    A_				 =						self.image_processor._get_preprocess_shape(_A       ,   longest_edge=_A	)
								A_				 =						deepcopy(_A	).astype(_A	)

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

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

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

								return coords




			def      lowerCamelCase__     (				self						:					Any       ,   _snake_case						:					Optional[int]=None       ,   _snake_case						:					List[str]=None       ,   _snake_case						:					Optional[int]=None       ,   )      -> Any:







								"""simple docstring"""
								if input_points is not None:
													if hasattr(_A       ,   "numpy"	):  # Checks for TF or Torch tensor
																		A_				 =						input_points.numpy().tolist()

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

								if input_labels is not None:
													if hasattr(_A       ,   "numpy"	):
																		A_				 =						input_labels.numpy().tolist()

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

								if input_boxes is not None:
													if hasattr(_A       ,   "numpy"	):
																		A_				 =						input_boxes.numpy().tolist()

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

								return input_points, input_labels, input_boxes




			@property
			def      lowerCamelCase__     (				self						:					List[str]	)      -> Optional[Any]:







								"""simple docstring"""
								A_				 =						self.image_processor.model_input_names
								return list(dict.fromkeys(_A	)	)






			def      lowerCamelCase__     (				self						:					List[Any]       ,   *_snake_case						:					Union[str, Any]       ,   **_snake_case						:					Optional[Any]	)      -> List[Any]:







								"""simple docstring"""
								return self.image_processor.post_process_masks(*_A       ,   **_A	)






"""simple docstring"""





import baseaa
def 							A_     (__a				):

					'''simple docstring'''





					return baseaa.aaaencode(string.encode("utf-8"				)				)
def 							A_     (__a				):

					'''simple docstring'''





					return baseaa.aaadecode(__a				).decode("utf-8"				)


if __name__ == "__main__":
		import doctest

		doctest.testmod()




