


'''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	(						lowercase__							):
							lowercase			:		Dict   		=  ['image_processor']
							lowercase			:		str   		=  'SamImageProcessor'





							def __init__(  self		:Optional[Any]  ,_UpperCamelCase		:Tuple			):
									super().__init__(_UpperCamelCase			)
									snake_case_		:							Union[str, Any]			       =						self.image_processor
									snake_case_		:							Optional[Any]			       =						-1_0
									snake_case_		:							int			       =						self.image_processor.size["""longest_edge"""]





							def __call__(  self		:Optional[int]  ,_UpperCamelCase		:List[Any]=None  ,_UpperCamelCase		:Union[str, Any]=None  ,_UpperCamelCase		:List[Any]=None  ,_UpperCamelCase		:Union[str, Any]=None  ,_UpperCamelCase		:Optional[Union[str, TensorType]] = None  ,**_UpperCamelCase		:Any  ,):
									snake_case_		:							str			       =						self.image_processor(
									    _UpperCamelCase  ,return_tensors=_UpperCamelCase  ,**_UpperCamelCase  ,)

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

									if hasattr(_UpperCamelCase  ,"""numpy"""			):  # Checks if Torch or TF tensor
											snake_case_		:							Dict			       =						original_sizes.numpy()

									snake_case_       ,      snake_case_       ,      snake_case_		:							Tuple			       =						self._check_and_preprocess_points(
									    input_points=_UpperCamelCase  ,input_labels=_UpperCamelCase  ,input_boxes=_UpperCamelCase  ,)

									snake_case_		:							str			       =						self._normalize_and_convert(
									    _UpperCamelCase  ,_UpperCamelCase  ,input_points=_UpperCamelCase  ,input_labels=_UpperCamelCase  ,input_boxes=_UpperCamelCase  ,return_tensors=_UpperCamelCase  ,)

									return encoding_image_processor





							def 		a__   (  self		:Union[str, Any]  ,_UpperCamelCase		:Optional[int]  ,_UpperCamelCase		:str  ,_UpperCamelCase		:Union[str, Any]=None  ,_UpperCamelCase		:str=None  ,_UpperCamelCase		:List[str]=None  ,_UpperCamelCase		:List[str]="pt"  ,):
									if input_points is not None:
											if len(_UpperCamelCase			) != len(_UpperCamelCase			):
													snake_case_		:							List[str]			       =						[
													    self._normalize_coordinates(self.target_size  ,_UpperCamelCase  ,original_sizes[0]			) for point in input_points
													]
											else:
													snake_case_		:							Union[str, Any]			       =						[
													    self._normalize_coordinates(self.target_size  ,_UpperCamelCase  ,_UpperCamelCase			)
													    for point, original_size in zip(_UpperCamelCase  ,_UpperCamelCase			)
													]
											# 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:
															snake_case_       ,      snake_case_		:							List[str]			       =						self._pad_points_and_labels(_UpperCamelCase  ,_UpperCamelCase			)

											snake_case_		:							List[str]			       =						np.array(_UpperCamelCase			)

									if input_labels is not None:
											snake_case_		:							Tuple			       =						np.array(_UpperCamelCase			)

									if input_boxes is not None:
											if len(_UpperCamelCase			) != len(_UpperCamelCase			):
													snake_case_		:							Tuple			       =						[
													    self._normalize_coordinates(self.target_size  ,_UpperCamelCase  ,original_sizes[0]  ,is_bounding_box=_UpperCamelCase			)
													    for box in input_boxes
													]
											else:
													snake_case_		:							str			       =						[
													    self._normalize_coordinates(self.target_size  ,_UpperCamelCase  ,_UpperCamelCase  ,is_bounding_box=_UpperCamelCase			)
													    for box, original_size in zip(_UpperCamelCase  ,_UpperCamelCase			)
													]
											snake_case_		:							List[Any]			       =						np.array(_UpperCamelCase			)

									if input_boxes is not None:
											if return_tensors == "pt":
													snake_case_		:							int			       =						torch.from_numpy(_UpperCamelCase			)
													# boxes batch size of 1 by default
													snake_case_		:							Optional[int]			       =						input_boxes.unsqueeze(1			) if len(input_boxes.shape			) != 3 else input_boxes
											elif return_tensors == "tf":
													snake_case_		:							Tuple			       =						tf.convert_to_tensor(_UpperCamelCase			)
													# boxes batch size of 1 by default
													snake_case_		:							Dict			       =						tf.expand_dims(_UpperCamelCase  ,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":
													snake_case_		:							Optional[Any]			       =						torch.from_numpy(_UpperCamelCase			)
													# point batch size of 1 by default
													snake_case_		:							Dict			       =						input_points.unsqueeze(1			) if len(input_points.shape			) != 4 else input_points
											elif return_tensors == "tf":
													snake_case_		:							Union[str, Any]			       =						tf.convert_to_tensor(_UpperCamelCase			)
													# point batch size of 1 by default
													snake_case_		:							List[str]			       =						tf.expand_dims(_UpperCamelCase  ,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":
													snake_case_		:							Optional[int]			       =						torch.from_numpy(_UpperCamelCase			)
													# point batch size of 1 by default
													snake_case_		:							int			       =						input_labels.unsqueeze(1			) if len(input_labels.shape			) != 3 else input_labels
											elif return_tensors == "tf":
													snake_case_		:							Dict			       =						tf.convert_to_tensor(_UpperCamelCase			)
													# point batch size of 1 by default
													snake_case_		:							Tuple			       =						tf.expand_dims(_UpperCamelCase  ,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		:Tuple  ,_UpperCamelCase		:List[str]  ,_UpperCamelCase		:int			):
									snake_case_		:							List[Any]			       =						max([point.shape[0] for point in input_points]			)
									snake_case_		:							str			       =						[]
									for i, point in enumerate(_UpperCamelCase			):
											if point.shape[0] != expected_nb_points:
													snake_case_		:							Optional[Any]			       =						np.concatenate(
													    [point, np.zeros((expected_nb_points - point.shape[0], 2)			) + self.point_pad_value]  ,axis=0			)
													snake_case_		:							Union[str, Any]			       =						np.append(input_labels[i]  ,[self.point_pad_value]			)
											processed_input_points.append(_UpperCamelCase			)
									snake_case_		:							int			       =						processed_input_points
									return input_points, input_labels





							def 		a__   (  self		:Union[str, Any]  ,_UpperCamelCase		:int  ,_UpperCamelCase		:np.ndarray  ,_UpperCamelCase		:Tuple  ,_UpperCamelCase		:List[str]=False			):
									snake_case_       ,      snake_case_		:							Any			       =						original_size
									snake_case_       ,      snake_case_		:							Optional[int]			       =						self.image_processor._get_preprocess_shape(_UpperCamelCase  ,longest_edge=_UpperCamelCase			)
									snake_case_		:							Any			       =						deepcopy(_UpperCamelCase			).astype(_UpperCamelCase			)

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

									snake_case_		:							List[Any]			       =						coords[..., 0] * (new_w / old_w)
									snake_case_		:							List[Any]			       =						coords[..., 1] * (new_h / old_h)

									if is_bounding_box:
											snake_case_		:							Optional[Any]			       =						coords.reshape(-1  ,4			)

									return coords





							def 		a__   (  self		:Union[str, Any]  ,_UpperCamelCase		:int=None  ,_UpperCamelCase		:int=None  ,_UpperCamelCase		:List[Any]=None  ,):
									if input_points is not None:
											if hasattr(_UpperCamelCase  ,"""numpy"""			):  # Checks for TF or Torch tensor
													snake_case_		:							int			       =						input_points.numpy().tolist()

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

									if input_labels is not None:
											if hasattr(_UpperCamelCase  ,"""numpy"""			):
													snake_case_		:							Optional[Any]			       =						input_labels.numpy().tolist()

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

									if input_boxes is not None:
											if hasattr(_UpperCamelCase  ,"""numpy"""			):
													snake_case_		:							int			       =						input_boxes.numpy().tolist()

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

									return input_points, input_labels, input_boxes





							@property
							def 		a__   (  self		:Tuple			):
									snake_case_		:							Union[str, Any]			       =						self.image_processor.model_input_names
									return list(dict.fromkeys(_UpperCamelCase			)			)





							def 		a__   (  self		:List[Any]  ,*_UpperCamelCase		:Any  ,**_UpperCamelCase		:Union[str, Any]			):
									return self.image_processor.post_process_masks(*_UpperCamelCase  ,**_UpperCamelCase			)



'''simple docstring'''






def      UpperCAmelCase      (		lowerCamelCase_  :int ):







		'''simple docstring'''
		if num < 0:
				return False

		snake_case_		:							int			       =						num
		snake_case_		:							int			       =						0
		while num > 0:
				snake_case_		:							Tuple			       =						rev_num * 10 + (num % 10)
				num //= 10

		return num_copy == rev_num


if __name__ == "__main__":
							import doctest

							doctest.testmod()