






'''simple docstring'''



from collections import defaultdict
from typing import Optional

from ..image_utils import load_image
from ..utils import (
    add_end_docstrings,
    is_torch_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, ChunkPipeline


if is_torch_available():
 import torch

 from ..models.auto.modeling_auto import MODEL_FOR_MASK_GENERATION_MAPPING

__UpperCamelCase   :							Optional[int]         =   logging.get_logger(__name__)
@add_end_docstrings(_lowerCAmelCase  )
class 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase  ):




      def __init__(	self			, **lowerCamelCase   )				->Any:



         '''simple docstring'''
         super().__init__(**lowerCamelCase   )
         requires_backends(self			, 'vision'   )
         requires_backends(self			, 'torch'   )

         if self.framework != "pt":
            raise ValueError(F"""The {self.__class__} is only available in PyTorch."""   )

         self.check_model_type(lowerCamelCase   )




      def 			__UpperCamelCase				(	self			, **lowerCamelCase   )				->int:



         '''simple docstring'''
         __a					  =     {}
         __a					  =     {}
         __a					  =     {}
         # preprocess args
         if "points_per_batch" in kwargs:
            __a					  =     kwargs['points_per_batch']
         if "points_per_crop" in kwargs:
            __a					  =     kwargs['points_per_crop']
         if "crops_n_layers" in kwargs:
            __a					  =     kwargs['crops_n_layers']
         if "crop_overlap_ratio" in kwargs:
            __a					  =     kwargs['crop_overlap_ratio']
         if "crop_n_points_downscale_factor" in kwargs:
            __a					  =     kwargs['crop_n_points_downscale_factor']
         # postprocess args
         if "pred_iou_thresh" in kwargs:
            __a					  =     kwargs['pred_iou_thresh']
         if "stability_score_offset" in kwargs:
            __a					  =     kwargs['stability_score_offset']
         if "mask_threshold" in kwargs:
            __a					  =     kwargs['mask_threshold']
         if "stability_score_thresh" in kwargs:
            __a					  =     kwargs['stability_score_thresh']
         if "crops_nms_thresh" in kwargs:
            __a					  =     kwargs['crops_nms_thresh']
         if "output_rle_mask" in kwargs:
            __a					  =     kwargs['output_rle_mask']
         if "output_bboxes_mask" in kwargs:
            __a					  =     kwargs['output_bboxes_mask']
         return preprocess_kwargs, forward_params, postprocess_kwargs




      def __call__(	self			, lowerCamelCase			, *lowerCamelCase			, lowerCamelCase=None			, lowerCamelCase=None			, **lowerCamelCase   )				->Dict:



         '''simple docstring'''
         return super().__call__(lowerCamelCase			, *lowerCamelCase			, num_workers=lowerCamelCase			, batch_size=lowerCamelCase			, **lowerCamelCase   )




      def 			__UpperCamelCase				(	self			, lowerCamelCase			, lowerCamelCase=64			, lowerCamelCase = 0			, lowerCamelCase = 512 / 1500			, lowerCamelCase = 32			, lowerCamelCase = 1			, )				->Union[str, Any]:



         '''simple docstring'''
         __a					  =     load_image(lowerCamelCase   )
         __a					  =     self.image_processor.size['longest_edge']
         __a  ,      __a  ,      __a  ,      __a					  =     self.image_processor.generate_crop_boxes(
             lowerCamelCase			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase   )
         __a					  =     self.image_processor(images=lowerCamelCase			, return_tensors='pt'   )

         with self.device_placement():
            if self.framework == "pt":
               __a					  =     self.get_inference_context()
               with inference_context():
                  __a					  =     self._ensure_tensor_on_device(lowerCamelCase			, device=self.device   )
                  __a					  =     self.model.get_image_embeddings(model_inputs.pop('pixel_values'   )   )
                  __a					  =     image_embeddings

         __a					  =     grid_points.shape[1]
         __a					  =     points_per_batch if points_per_batch is not None else n_points

         if points_per_batch <= 0:
            raise ValueError(
                'Cannot have points_per_batch<=0. Must be >=1 to returned batched outputs. '
                'To return all points at once, set points_per_batch to None'   )

         for i in range(0			, lowerCamelCase			, lowerCamelCase   ):
            __a					  =     grid_points[:, i : i + points_per_batch, :, :]
            __a					  =     input_labels[:, i : i + points_per_batch]
            __a					  =     i == n_points - points_per_batch
            yield {
                "input_points": batched_points,
                "input_labels": labels,
                "input_boxes": crop_boxes,
                "is_last": is_last,
                **model_inputs,
            }




      def 			__UpperCamelCase				(	self			, lowerCamelCase			, lowerCamelCase=0.88			, lowerCamelCase=0.95			, lowerCamelCase=0			, lowerCamelCase=1			, )				->List[str]:



         '''simple docstring'''
         __a					  =     model_inputs.pop('input_boxes'   )
         __a					  =     model_inputs.pop('is_last'   )
         __a					  =     model_inputs.pop('original_sizes'   ).tolist()
         __a					  =     model_inputs.pop('reshaped_input_sizes'   ).tolist()

         __a					  =     self.model(**lowerCamelCase   )

         # post processing happens here in order to avoid CPU GPU copies of ALL the masks
         __a					  =     model_outputs['pred_masks']
         __a					  =     self.image_processor.post_process_masks(
             lowerCamelCase			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase			, binarize=lowerCamelCase   )
         __a					  =     model_outputs['iou_scores']
         __a  ,      __a  ,      __a					  =     self.image_processor.filter_masks(
             masks[0]			, iou_scores[0]			, original_sizes[0]			, input_boxes[0]			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase			, )
         return {
             "masks": masks,
             "is_last": is_last,
             "boxes": boxes,
             "iou_scores": iou_scores,
         }






      def 			__UpperCamelCase				(	self			, lowerCamelCase			, lowerCamelCase=False			, lowerCamelCase=False			, lowerCamelCase=0.7			, )				->Tuple:



         '''simple docstring'''
         __a					  =     []
         __a					  =     []
         __a					  =     []
         for model_output in model_outputs:
            all_scores.append(model_output.pop('iou_scores'   )   )
            all_masks.extend(model_output.pop('masks'   )   )
            all_boxes.append(model_output.pop('boxes'   )   )

         __a					  =     torch.cat(lowerCamelCase   )
         __a					  =     torch.cat(lowerCamelCase   )
         __a  ,      __a  ,      __a  ,      __a					  =     self.image_processor.post_process_for_mask_generation(
             lowerCamelCase			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase   )

         __a					  =     defaultdict(lowerCamelCase   )
         for output in model_outputs:
            for k, v in output.items():
               extra[k].append(lowerCamelCase   )

         __a					  =     {}
         if output_rle_mask:
            __a					  =     rle_mask

         if output_bboxes_mask:
            __a					  =     bounding_boxes

         return {"masks": output_masks, "scores": iou_scores, **optional, **extra}







'''simple docstring'''



import sys

__UpperCamelCase   :							List[str]         =   (
    """73167176531330624919225119674426574742355349194934"""
    """96983520312774506326239578318016984801869478851843"""
    """85861560789112949495459501737958331952853208805511"""
    """12540698747158523863050715693290963295227443043557"""
    """66896648950445244523161731856403098711121722383113"""
    """62229893423380308135336276614282806444486645238749"""
    """30358907296290491560440772390713810515859307960866"""
    """70172427121883998797908792274921901699720888093776"""
    """65727333001053367881220235421809751254540594752243"""
    """52584907711670556013604839586446706324415722155397"""
    """53697817977846174064955149290862569321978468622482"""
    """83972241375657056057490261407972968652414535100474"""
    """82166370484403199890008895243450658541227588666881"""
    """16427171479924442928230863465674813919123162824586"""
    """17866458359124566529476545682848912883142607690042"""
    """24219022671055626321111109370544217506941658960408"""
    """07198403850962455444362981230987879927244284909188"""
    """84580156166097919133875499200524063689912560717606"""
    """05886116467109405077541002256983155200055935729725"""
    """71636269561882670428252483600823257530420752963450"""
)



def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						str = N     )	->      int:

   """simple docstring"""
   __a					  =     -sys.maxsize - 1
   for i in range(len(SCREAMING_SNAKE_CASE__     ) - 12     ):
      __a					  =     1
      for j in range(13     ):
         product *= int(n[i + j]     )
      if product > largest_product:
         __a					  =     product
   return largest_product


if __name__ == "__main__":
 print(f"""{solution() = }""")