


'''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  __magic_name__							(		lowerCAmelCase    ):
       UpperCAmelCase										=["image_processor"]
       UpperCAmelCase										="SamImageProcessor"






       def __init__(      self  ,							snake_case)						->  Union[str, Any]:




          '''simple docstring'''
          super().__init__(snake_case)
          _UpperCAmelCase       :       Tuple							   =self.image_processor
          _UpperCAmelCase       :       Tuple							   =-1_0
          _UpperCAmelCase       :       Optional[int]							   =self.image_processor.size['longest_edge']






       def __call__(      self  ,							snake_case=None  ,							snake_case=None  ,							snake_case=None  ,							snake_case=None  ,							snake_case = None  ,							**snake_case  ,							)						->  BatchEncoding:




          '''simple docstring'''
          _UpperCAmelCase       :       Any							   =self.image_processor(
              snake_case  ,							return_tensors=snake_case  ,							**snake_case  ,							)

          # pop arguments that are not used in the foward but used nevertheless
          _UpperCAmelCase       :       Optional[Any]							   =encoding_image_processor['original_sizes']

          if hasattr(snake_case  ,							'numpy'):  # Checks if Torch or TF tensor
             _UpperCAmelCase       :       Any							   =original_sizes.numpy()

          _UpperCAmelCase       :       int							   =self._check_and_preprocess_points(
              input_points=snake_case  ,							input_labels=snake_case  ,							input_boxes=snake_case  ,							)

          _UpperCAmelCase       :       List[Any]							   =self._normalize_and_convert(
              snake_case  ,							snake_case  ,							input_points=snake_case  ,							input_labels=snake_case  ,							input_boxes=snake_case  ,							return_tensors=snake_case  ,							)

          return encoding_image_processor






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case  ,							snake_case=None  ,							snake_case=None  ,							snake_case=None  ,							snake_case="pt"  ,							)						->  Dict:




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

             _UpperCAmelCase       :       Union[str, Any]							   =np.array(snake_case)

          if input_labels is not None:
             _UpperCAmelCase       :       Dict							   =np.array(snake_case)

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

          if input_boxes is not None:
             if return_tensors == "pt":
                _UpperCAmelCase       :       List[Any]							   =torch.from_numpy(snake_case)
                # boxes batch size of 1 by default
                _UpperCAmelCase       :       Optional[Any]							   =input_boxes.unsqueeze(1) if len(input_boxes.shape) != 3 else input_boxes
             elif return_tensors == "tf":
                _UpperCAmelCase       :       int							   =tf.convert_to_tensor(snake_case)
                # boxes batch size of 1 by default
                _UpperCAmelCase       :       List[str]							   =tf.expand_dims(snake_case  ,							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       :       Optional[Any]							   =torch.from_numpy(snake_case)
                # point batch size of 1 by default
                _UpperCAmelCase       :       List[str]							   =input_points.unsqueeze(1) if len(input_points.shape) != 4 else input_points
             elif return_tensors == "tf":
                _UpperCAmelCase       :       Union[str, Any]							   =tf.convert_to_tensor(snake_case)
                # point batch size of 1 by default
                _UpperCAmelCase       :       str							   =tf.expand_dims(snake_case  ,							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       :       Tuple							   =torch.from_numpy(snake_case)
                # point batch size of 1 by default
                _UpperCAmelCase       :       Dict							   =input_labels.unsqueeze(1) if len(input_labels.shape) != 3 else input_labels
             elif return_tensors == "tf":
                _UpperCAmelCase       :       Optional[int]							   =tf.convert_to_tensor(snake_case)
                # point batch size of 1 by default
                _UpperCAmelCase       :       Optional[Any]							   =tf.expand_dims(snake_case  ,							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  ,							snake_case  ,							snake_case)						->  List[str]:




          '''simple docstring'''
          _UpperCAmelCase       :       Tuple							   =max([point.shape[0] for point in input_points])
          _UpperCAmelCase       :       Any							   =[]
          for i, point in enumerate(snake_case):
             if point.shape[0] != expected_nb_points:
                _UpperCAmelCase       :       str							   =np.concatenate(
                    [point, np.zeros((expected_nb_points - point.shape[0], 2)) + self.point_pad_value]  ,							axis=0)
                _UpperCAmelCase       :       Optional[Any]							   =np.append(input_labels[i]  ,							[self.point_pad_value])
             processed_input_points.append(snake_case)
          _UpperCAmelCase       :       Optional[Any]							   =processed_input_points
          return input_points, input_labels






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case=False)						->  np.ndarray:




          '''simple docstring'''
          _UpperCAmelCase       :       int							   =original_size
          _UpperCAmelCase       :       Dict							   =self.image_processor._get_preprocess_shape(snake_case  ,							longest_edge=snake_case)
          _UpperCAmelCase       :       Optional[Any]							   =deepcopy(snake_case).astype(snake_case)

          if is_bounding_box:
             _UpperCAmelCase       :       List[str]							   =coords.reshape(-1  ,							2  ,							2)

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

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

          return coords






       def       lowerCAmelCase		(      self  ,							snake_case=None  ,							snake_case=None  ,							snake_case=None  ,							)						->  Any:




          '''simple docstring'''
          if input_points is not None:
             if hasattr(snake_case  ,							'numpy'):  # Checks for TF or Torch tensor
                _UpperCAmelCase       :       List[str]							   =input_points.numpy().tolist()

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

          if input_labels is not None:
             if hasattr(snake_case  ,							'numpy'):
                _UpperCAmelCase       :       Any							   =input_labels.numpy().tolist()

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

          if input_boxes is not None:
             if hasattr(snake_case  ,							'numpy'):
                _UpperCAmelCase       :       int							   =input_boxes.numpy().tolist()

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

          return input_points, input_labels, input_boxes






       @property
       def       lowerCAmelCase		(      self)						->  Dict:




          '''simple docstring'''
          _UpperCAmelCase       :       Optional[int]							   =self.image_processor.model_input_names
          return list(dict.fromkeys(snake_case))






       def       lowerCAmelCase		(      self  ,							*snake_case  ,							**snake_case)						->  Optional[int]:




          '''simple docstring'''
          return self.image_processor.post_process_masks(*snake_case  ,							**snake_case)





'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


lowercase							={
    'configuration_groupvit': [
        'GROUPVIT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'GroupViTConfig',
        'GroupViTOnnxConfig',
        'GroupViTTextConfig',
        'GroupViTVisionConfig',
    ],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowercase							=[
     'GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
     'GroupViTModel',
     'GroupViTPreTrainedModel',
     'GroupViTTextModel',
     'GroupViTVisionModel',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowercase							=[
     'TF_GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
     'TFGroupViTModel',
     'TFGroupViTPreTrainedModel',
     'TFGroupViTTextModel',
     'TFGroupViTVisionModel',
 ]

if TYPE_CHECKING:
 from .configuration_groupvit import (
     GROUPVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
     GroupViTConfig,
     GroupViTOnnxConfig,
     GroupViTTextConfig,
     GroupViTVisionConfig,
 )

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_groupvit import (
      GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
      GroupViTModel,
      GroupViTPreTrainedModel,
      GroupViTTextModel,
      GroupViTVisionModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_groupvit import (
      TF_GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFGroupViTModel,
      TFGroupViTPreTrainedModel,
      TFGroupViTTextModel,
      TFGroupViTVisionModel,
  )

else:
 import sys

 lowercase							=_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

