





"""simple docstring"""






import numpy as np
import torch

from ..models.clipseg import CLIPSegForImageSegmentation
from ..utils import is_vision_available, requires_backends
from .base import PipelineTool


if is_vision_available():
    from PIL import Image



class 	lowerCAmelCase					(      snake_case							):

       '''simple docstring'''





       lowerCAmelCase__						 =  (
           """This is a tool that creates a segmentation mask of an image according to a label. It cannot create an image."""
           """It takes two arguments named `image` which should be the original image, and `label` which should be a text """
           """describing the elements what should be identified in the segmentation mask. The tool returns the mask."""
       )
       lowerCAmelCase__						 =  """CIDAS/clipseg-rd64-refined"""
       lowerCAmelCase__						 =  """image_segmenter"""
       lowerCAmelCase__						 =  CLIPSegForImageSegmentation

       lowerCAmelCase__						 =  ["""image""", """text"""]
       lowerCAmelCase__						 =  ["""image"""]






       def __init__(   self    ,  *a__    ,  **a__     ):
              requires_backends(self    ,  ['vision']     )
              super().__init__(*a__    ,  **a__     )






       def 							__A (   self    ,  a__    ,  a__     ):
              return self.pre_processor(text=[label]    ,  images=[image]    ,  padding=a__    ,  return_tensors='pt'     )






       def 							__A (   self    ,  a__     ):
              with torch.no_grad():
                     _UpperCAmelCase     =     self.model(**a__     ).logits
              return logits






       def 							__A (   self    ,  a__     ):
              _UpperCAmelCase     =     outputs.cpu().detach().numpy()
              _UpperCAmelCase     =     0
              _UpperCAmelCase     =     1
              return Image.fromarray((array * 2_55).astype(np.uinta     )     )













"""simple docstring"""






from itertools import product

def       __lowerCamelCase    (       SCREAMING_SNAKE_CASE,SCREAMING_SNAKE_CASE							)		->       list[int]:






       """simple docstring"""




       _UpperCAmelCase     =     sides_number
       _UpperCAmelCase     =     max_face_number * dice_number
       _UpperCAmelCase     =     [0] * (max_total + 1)

       _UpperCAmelCase     =     1
       _UpperCAmelCase     =     range(SCREAMING_SNAKE_CASE,max_face_number + 1							)
       for dice_numbers in product(SCREAMING_SNAKE_CASE,repeat=SCREAMING_SNAKE_CASE							):
              _UpperCAmelCase     =     sum(SCREAMING_SNAKE_CASE							)
              totals_frequencies[total] += 1

       return totals_frequencies

def       __lowerCamelCase    (       )		->       float:






       """simple docstring"""




       _UpperCAmelCase     =     total_frequency_distribution(
           sides_number=4,dice_number=9							)
       _UpperCAmelCase     =     total_frequency_distribution(
           sides_number=6,dice_number=6							)

       _UpperCAmelCase     =     0
       _UpperCAmelCase     =     9
       _UpperCAmelCase     =     4 * 9
       _UpperCAmelCase     =     6
       for peter_total in range(SCREAMING_SNAKE_CASE,max_peter_total + 1							):
              peter_wins_count += peter_totals_frequencies[peter_total] * sum(
                  colin_totals_frequencies[min_colin_total:peter_total]							)

       _UpperCAmelCase     =     (4**9) * (6**6)
       _UpperCAmelCase     =     peter_wins_count / total_games_number

       _UpperCAmelCase     =     round(SCREAMING_SNAKE_CASE,ndigits=7							)

       return rounded_peter_win_probability


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






