






'''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			(		lowercase_      ):



				"""simple docstring"""



				_lowercase				:   Optional[int]      =  (
				    '''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.'''
				)
				_lowercase				:   Optional[Any]      =  '''CIDAS/clipseg-rd64-refined'''
				_lowercase				:   Optional[Any]      =  '''image_segmenter'''
				_lowercase				:   int      =  CLIPSegForImageSegmentation

				_lowercase				:   str      =  ['''image''', '''text''']
				_lowercase				:   Optional[Any]      =  ['''image''']



				def __init__(      self    :    Any			,		*UpperCamelCase__    :    Optional[int]			,		**UpperCamelCase__    :    int):






											'''simple docstring'''







											requires_backends(self			,		["""vision"""])
											super().__init__(*_SCREAMING_SNAKE_CASE			,		**_SCREAMING_SNAKE_CASE)



				def 					__magic_name__							(      self    :    Union[str, Any]			,		UpperCamelCase__    :    Any			,		UpperCamelCase__    :    Union[str, Any]):






											'''simple docstring'''







											return self.pre_processor(text=[label]			,		images=[image]			,		padding=_SCREAMING_SNAKE_CASE			,		return_tensors="""pt""")



				def 					__magic_name__							(      self    :    List[Any]			,		UpperCamelCase__    :    List[Any]):






											'''simple docstring'''







											with torch.no_grad():
																		snake_case__	  =       self.model(**_SCREAMING_SNAKE_CASE).logits
											return logits



				def 					__magic_name__							(      self    :    Union[str, Any]			,		UpperCamelCase__    :    List[str]):






											'''simple docstring'''







											snake_case__	  =       outputs.cpu().detach().numpy()
											snake_case__	  =       0
											snake_case__	  =       1
											return Image.fromarray((array * 2_5_5).astype(np.uinta))








def _UpperCAmelCase   (	a						:	int = 400_0000 ):
							snake_case__	  =       [0, 1]
							snake_case__	  =       0
							while fib[i] <= n:
														fib.append(fib[i] + fib[i + 1] )
														if fib[i + 2] > n:
																					break
														i += 1
							snake_case__	  =       0
							for j in range(len(a ) - 1 ):
														if fib[j] % 2 == 0:
																					total += fib[j]

							return total


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