
import itertools
import json
import os
import unittest

from transformers import AddedToken, LongformerTokenizer, LongformerTokenizerFast
from transformers.models.longformer.tokenization_longformer import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin




@require_tokenizers
class      __A(    __lowerCamelCase    ,				unittest.TestCase			):

  """simple docstring"""
  SCREAMING_SNAKE_CASE__         =      LongformerTokenizer
  SCREAMING_SNAKE_CASE__         =      True
  SCREAMING_SNAKE_CASE__         =      LongformerTokenizerFast
  SCREAMING_SNAKE_CASE__         =      True







  def 	UpperCAmelCase_ (self						):
       super().setUp()

       # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
       UpperCamelCase__				=    [
           """l""",
           """o""",
           """w""",
           """e""",
           """r""",
           """s""",
           """t""",
           """i""",
           """d""",
           """n""",
           """\u0120""",
           """\u0120l""",
           """\u0120n""",
           """\u0120lo""",
           """\u0120low""",
           """er""",
           """\u0120lowest""",
           """\u0120newer""",
           """\u0120wider""",
           """<unk>""",
       ]
       UpperCamelCase__				=    dict(zip(SCREAMING_SNAKE_CASE_	,      range(len(SCREAMING_SNAKE_CASE_						)						)						)						)
       UpperCamelCase__				=    ["""#version: 0.2""", """\u0120 l""", """\u0120l o""", """\u0120lo w""", """e r""", """"""]
       UpperCamelCase__				=    {"""unk_token""": """<unk>"""}

       UpperCamelCase__				=    os.path.join(self.tmpdirname	,      VOCAB_FILES_NAMES["""vocab_file"""]						)
       UpperCamelCase__				=    os.path.join(self.tmpdirname	,      VOCAB_FILES_NAMES["""merges_file"""]						)
       with open(self.vocab_file	,      """w"""	,      encoding="""utf-8"""						) as fp:
            fp.write(json.dumps(SCREAMING_SNAKE_CASE_						) + """\n"""						)
       with open(self.merges_file	,      """w"""	,      encoding="""utf-8"""						) as fp:
            fp.write("""\n""".join(SCREAMING_SNAKE_CASE_						)						)







  def 	UpperCAmelCase_ (self	,      **SCREAMING_SNAKE_CASE_						):
       kwargs.update(self.special_tokens_map						)
       return self.tokenizer_class.from_pretrained(self.tmpdirname	,      **SCREAMING_SNAKE_CASE_						)







  def 	UpperCAmelCase_ (self	,      **SCREAMING_SNAKE_CASE_						):
       kwargs.update(self.special_tokens_map						)
       return self.rust_tokenizer_class.from_pretrained(self.tmpdirname	,      **SCREAMING_SNAKE_CASE_						)







  def 	UpperCAmelCase_ (self	,      SCREAMING_SNAKE_CASE_						):
       UpperCamelCase__				=    """lower newer"""
       UpperCamelCase__				=    """lower newer"""
       return input_text, output_text







  def 	UpperCAmelCase_ (self						):
       UpperCamelCase__				=    self.tokenizer_class(self.vocab_file	,      self.merges_file	,      **self.special_tokens_map						)
       UpperCamelCase__				=    """lower newer"""
       UpperCamelCase__				=    ["""l""", """o""", """w""", """er""", """\u0120""", """n""", """e""", """w""", """er"""]
       UpperCamelCase__				=    tokenizer.tokenize(SCREAMING_SNAKE_CASE_						)  # , add_prefix_space=True)
       self.assertListEqual(SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						)

       UpperCamelCase__				=    tokens + [tokenizer.unk_token]
       UpperCamelCase__				=    [0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
       self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE_						)	,      SCREAMING_SNAKE_CASE_						)







  def 	UpperCAmelCase_ (self						):
       UpperCamelCase__				=    self.get_tokenizer()

       self.assertListEqual(tokenizer.encode("""Hello world!"""	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)	,      [0, 3_14_14, 2_32, 3_28, 2]						)
       self.assertListEqual(
           tokenizer.encode("""Hello world! cécé herlolip 418"""	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)	,      [0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]	,      )







  @slow
  def 	UpperCAmelCase_ (self						):
       UpperCamelCase__				=    self.tokenizer_class.from_pretrained("""allenai/longformer-base-4096"""						)

       UpperCamelCase__				=    tokenizer.encode("""sequence builders"""	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    tokenizer.encode("""multi-sequence build"""	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)

       UpperCamelCase__				=    tokenizer.encode(
           """sequence builders"""	,      add_special_tokens=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    tokenizer.encode(
           """sequence builders"""	,      """multi-sequence build"""	,      add_special_tokens=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_						)

       UpperCamelCase__				=    tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						)

       assert encoded_sentence == encoded_text_from_decode
       assert encoded_pair == encoded_pair_from_decode







  def 	UpperCAmelCase_ (self						):
       UpperCamelCase__				=    self.get_tokenizer()

       UpperCamelCase__				=    """Encode this sequence."""
       UpperCamelCase__				=    tokenizer.byte_encoder[""" """.encode("""utf-8"""						)[0]]

       # Testing encoder arguments
       UpperCamelCase__				=    tokenizer.encode(SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    tokenizer.convert_ids_to_tokens(encoded[0]						)[0]
       self.assertNotEqual(SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						)

       UpperCamelCase__				=    tokenizer.encode(SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    tokenizer.convert_ids_to_tokens(encoded[0]						)[0]
       self.assertEqual(SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						)

       tokenizer.add_special_tokens({"""bos_token""": """<s>"""}						)
       UpperCamelCase__				=    tokenizer.encode(SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    tokenizer.convert_ids_to_tokens(encoded[1]						)[0]
       self.assertNotEqual(SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						)

       # Testing spaces after special tokens
       UpperCamelCase__				=    """<mask>"""
       tokenizer.add_special_tokens(
           {"""mask_token""": AddedToken(SCREAMING_SNAKE_CASE_	,      lstrip=SCREAMING_SNAKE_CASE_	,      rstrip=SCREAMING_SNAKE_CASE_						)}						)  # mask token has a left space
       UpperCamelCase__				=    tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE_						)

       UpperCamelCase__				=    """Encode <mask> sequence"""
       UpperCamelCase__				=    """Encode <mask>sequence"""

       UpperCamelCase__				=    tokenizer.encode(SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    encoded.index(SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]						)[0]
       self.assertEqual(SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						)

       UpperCamelCase__				=    tokenizer.encode(SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    encoded.index(SCREAMING_SNAKE_CASE_						)
       UpperCamelCase__				=    tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]						)[0]
       self.assertNotEqual(SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						)







  def 	UpperCAmelCase_ (self						):
       pass







  def 	UpperCAmelCase_ (self						):
       for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
            with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})"						):
                 UpperCamelCase__				=    self.rust_tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE_	,      **SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    self.tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE_	,      **SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    """A, <mask> AllenNLP sentence."""
                 UpperCamelCase__				=    tokenizer_r.encode_plus(SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_	,      return_token_type_ids=SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    tokenizer_p.encode_plus(SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_	,      return_token_type_ids=SCREAMING_SNAKE_CASE_						)

                 # token_type_ids should put 0 everywhere
                 self.assertEqual(sum(tokens_r["""token_type_ids"""]						)	,      sum(tokens_p["""token_type_ids"""]						)						)

                 # attention_mask should put 1 everywhere, so sum over length should be 1
                 self.assertEqual(
                     sum(tokens_r["""attention_mask"""]						) / len(tokens_r["""attention_mask"""]						)	,      sum(tokens_p["""attention_mask"""]						) / len(tokens_p["""attention_mask"""]						)	,      )

                 UpperCamelCase__				=    tokenizer_r.convert_ids_to_tokens(tokens_r["""input_ids"""]						)
                 UpperCamelCase__				=    tokenizer_p.convert_ids_to_tokens(tokens_p["""input_ids"""]						)

                 # Rust correctly handles the space before the mask while python doesnt
                 self.assertSequenceEqual(tokens_p["""input_ids"""]	,      [0, 2_50, 6, 5_02_64, 38_23, 4_87, 2_19_92, 36_45, 4, 2]						)
                 self.assertSequenceEqual(tokens_r["""input_ids"""]	,      [0, 2_50, 6, 5_02_64, 38_23, 4_87, 2_19_92, 36_45, 4, 2]						)

                 self.assertSequenceEqual(
                     SCREAMING_SNAKE_CASE_	,      ["""<s>""", """A""", """,""", """<mask>""", """ĠAllen""", """N""", """LP""", """Ġsentence""", """.""", """</s>"""]						)
                 self.assertSequenceEqual(
                     SCREAMING_SNAKE_CASE_	,      ["""<s>""", """A""", """,""", """<mask>""", """ĠAllen""", """N""", """LP""", """Ġsentence""", """.""", """</s>"""]						)







  def 	UpperCAmelCase_ (self						):
       for trim_offsets, add_prefix_space in itertools.product([True, False]	,      repeat=2						):
            UpperCamelCase__				=    self.rust_tokenizer_class.from_pretrained(
                self.tmpdirname	,      use_fast=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_	,      trim_offsets=SCREAMING_SNAKE_CASE_						)

            UpperCamelCase__				=    json.loads(tokenizer_r.backend_tokenizer.pre_tokenizer.__getstate__()						)
            UpperCamelCase__				=    json.loads(tokenizer_r.backend_tokenizer.post_processor.__getstate__()						)

            self.assertEqual(pre_tokenizer_state["""add_prefix_space"""]	,      SCREAMING_SNAKE_CASE_						)

            self.assertEqual(post_processor_state["""add_prefix_space"""]	,      SCREAMING_SNAKE_CASE_						)
            self.assertEqual(post_processor_state["""trim_offsets"""]	,      SCREAMING_SNAKE_CASE_						)







  def 	UpperCAmelCase_ (self						):
       # Test which aims to verify that the offsets are well adapted to the argument `add_prefix_space` and
       # `trim_offsets`
       for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
            with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})"						):
                 UpperCamelCase__				=    """hello"""  # `hello` is a token in the vocabulary of `pretrained_name`
                 UpperCamelCase__				=    F"{text_of_1_token} {text_of_1_token}"

                 UpperCamelCase__				=    self.rust_tokenizer_class.from_pretrained(
                     SCREAMING_SNAKE_CASE_	,      use_fast=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_	,      trim_offsets=SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    tokenizer_r(SCREAMING_SNAKE_CASE_	,      return_offsets_mapping=SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)
                 self.assertEqual(encoding.offset_mapping[0]	,      (0, len(SCREAMING_SNAKE_CASE_						))						)
                 self.assertEqual(
                     encoding.offset_mapping[1]	,      (len(SCREAMING_SNAKE_CASE_						) + 1, len(SCREAMING_SNAKE_CASE_						) + 1 + len(SCREAMING_SNAKE_CASE_						))	,      )

                 UpperCamelCase__				=    self.rust_tokenizer_class.from_pretrained(
                     SCREAMING_SNAKE_CASE_	,      use_fast=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_	,      trim_offsets=SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    tokenizer_r(SCREAMING_SNAKE_CASE_	,      return_offsets_mapping=SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)
                 self.assertEqual(encoding.offset_mapping[0]	,      (0, len(SCREAMING_SNAKE_CASE_						))						)
                 self.assertEqual(
                     encoding.offset_mapping[1]	,      (len(SCREAMING_SNAKE_CASE_						) + 1, len(SCREAMING_SNAKE_CASE_						) + 1 + len(SCREAMING_SNAKE_CASE_						))	,      )

                 UpperCamelCase__				=    self.rust_tokenizer_class.from_pretrained(
                     SCREAMING_SNAKE_CASE_	,      use_fast=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_	,      trim_offsets=SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    tokenizer_r(SCREAMING_SNAKE_CASE_	,      return_offsets_mapping=SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)
                 self.assertEqual(encoding.offset_mapping[0]	,      (0, len(SCREAMING_SNAKE_CASE_						))						)
                 self.assertEqual(
                     encoding.offset_mapping[1]	,      (len(SCREAMING_SNAKE_CASE_						), len(SCREAMING_SNAKE_CASE_						) + 1 + len(SCREAMING_SNAKE_CASE_						))	,      )

                 UpperCamelCase__				=    self.rust_tokenizer_class.from_pretrained(
                     SCREAMING_SNAKE_CASE_	,      use_fast=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_	,      trim_offsets=SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    tokenizer_r(SCREAMING_SNAKE_CASE_	,      return_offsets_mapping=SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)
                 self.assertEqual(encoding.offset_mapping[0]	,      (0, len(SCREAMING_SNAKE_CASE_						))						)
                 self.assertEqual(
                     encoding.offset_mapping[1]	,      (len(SCREAMING_SNAKE_CASE_						), len(SCREAMING_SNAKE_CASE_						) + 1 + len(SCREAMING_SNAKE_CASE_						))	,      )

                 UpperCamelCase__				=    F" {text}"

                 # tokenizer_r = self.rust_tokenizer_class.from_pretrained(
                 #     pretrained_name, use_fast=True, add_prefix_space=True, trim_offsets=True
                 # )
                 # encoding = tokenizer_r(text, return_offsets_mapping=True, add_special_tokens=False)
                 # self.assertEqual(encoding.offset_mapping[0], (1, 1 + len(text_of_1_token)))
                 # self.assertEqual(
                 #     encoding.offset_mapping[1],
                 #     (1 + len(text_of_1_token) + 1, 1 + len(text_of_1_token) + 1 + len(text_of_1_token)),
                 # )

                 UpperCamelCase__				=    self.rust_tokenizer_class.from_pretrained(
                     SCREAMING_SNAKE_CASE_	,      use_fast=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_	,      trim_offsets=SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    tokenizer_r(SCREAMING_SNAKE_CASE_	,      return_offsets_mapping=SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)
                 self.assertEqual(encoding.offset_mapping[0]	,      (1, 1 + len(SCREAMING_SNAKE_CASE_						))						)
                 self.assertEqual(
                     encoding.offset_mapping[1]	,      (1 + len(SCREAMING_SNAKE_CASE_						) + 1, 1 + len(SCREAMING_SNAKE_CASE_						) + 1 + len(SCREAMING_SNAKE_CASE_						))	,      )

                 UpperCamelCase__				=    self.rust_tokenizer_class.from_pretrained(
                     SCREAMING_SNAKE_CASE_	,      use_fast=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_	,      trim_offsets=SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    tokenizer_r(SCREAMING_SNAKE_CASE_	,      return_offsets_mapping=SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)
                 self.assertEqual(encoding.offset_mapping[0]	,      (0, 1 + len(SCREAMING_SNAKE_CASE_						))						)
                 self.assertEqual(
                     encoding.offset_mapping[1]	,      (1 + len(SCREAMING_SNAKE_CASE_						), 1 + len(SCREAMING_SNAKE_CASE_						) + 1 + len(SCREAMING_SNAKE_CASE_						))	,      )

                 UpperCamelCase__				=    self.rust_tokenizer_class.from_pretrained(
                     SCREAMING_SNAKE_CASE_	,      use_fast=SCREAMING_SNAKE_CASE_	,      add_prefix_space=SCREAMING_SNAKE_CASE_	,      trim_offsets=SCREAMING_SNAKE_CASE_						)
                 UpperCamelCase__				=    tokenizer_r(SCREAMING_SNAKE_CASE_	,      return_offsets_mapping=SCREAMING_SNAKE_CASE_	,      add_special_tokens=SCREAMING_SNAKE_CASE_						)
                 self.assertEqual(encoding.offset_mapping[0]	,      (0, 1 + len(SCREAMING_SNAKE_CASE_						))						)
                 self.assertEqual(
                     encoding.offset_mapping[1]	,      (1 + len(SCREAMING_SNAKE_CASE_						), 1 + len(SCREAMING_SNAKE_CASE_						) + 1 + len(SCREAMING_SNAKE_CASE_						))	,      )







import hashlib
import unittest
from typing import Dict

import numpy as np

from transformers import (
    MODEL_FOR_MASK_GENERATION_MAPPING,
    TF_MODEL_FOR_MASK_GENERATION_MAPPING,
    is_vision_available,
    pipeline,
)
from transformers.pipelines import MaskGenerationPipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)


if is_vision_available():
    from PIL import Image
else:




    class      __A:

      """simple docstring"""







      @staticmethod
      def 	UpperCAmelCase_ (*SCREAMING_SNAKE_CASE_	,      **SCREAMING_SNAKE_CASE_						):
           pass






def 						__magic_name__			(   __a      :	Image						):



     '''simple docstring'''




     UpperCamelCase__				=    hashlib.mda(image.tobytes()						)
     return m.hexdigest()[:10]






def 						__magic_name__			(   __a      :	Image						):



     '''simple docstring'''




     UpperCamelCase__				=    np.array(__a						)
     UpperCamelCase__				=    npimg.shape
     return {"hash": hashimage(__a						), "shape": shape}




@is_pipeline_test
@require_vision
@require_torch
class      __A(    unittest.TestCase			):

  """simple docstring"""
  SCREAMING_SNAKE_CASE__         =      dict(
      (list(MODEL_FOR_MASK_GENERATION_MAPPING.items()			) if MODEL_FOR_MASK_GENERATION_MAPPING else [])			)
  SCREAMING_SNAKE_CASE__         =      dict(
      (list(TF_MODEL_FOR_MASK_GENERATION_MAPPING.items()			) if TF_MODEL_FOR_MASK_GENERATION_MAPPING else [])			)







  def 	UpperCAmelCase_ (self	,      SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						):
       UpperCamelCase__				=    MaskGenerationPipeline(model=SCREAMING_SNAKE_CASE_	,      image_processor=SCREAMING_SNAKE_CASE_						)
       return image_segmenter, [
           "./tests/fixtures/tests_samples/COCO/000000039769.png",
           "./tests/fixtures/tests_samples/COCO/000000039769.png",
       ]







  def 	UpperCAmelCase_ (self	,      SCREAMING_SNAKE_CASE_	,      SCREAMING_SNAKE_CASE_						):
       pass







  @require_tf
  @unittest.skip("""Image segmentation not implemented in TF"""						)
  def 	UpperCAmelCase_ (self						):
       pass







  @slow
  @require_torch
  def 	UpperCAmelCase_ (self						):
       UpperCamelCase__				=    pipeline("""mask-generation"""	,      model="""facebook/sam-vit-huge"""						)

       UpperCamelCase__				=    image_segmenter("""http://images.cocodataset.org/val2017/000000039769.jpg"""	,      points_per_batch=2_56						)

       # Shortening by hashing
       UpperCamelCase__				=    []
       for i, o in enumerate(outputs["""masks"""]						):
            new_outupt += [{"mask": mask_to_test_readable(SCREAMING_SNAKE_CASE_						), "scores": outputs["scores"][i]}]

       # fmt: off
       self.assertEqual(
           nested_simplify(SCREAMING_SNAKE_CASE_	,      decimals=4						)	,      [
               {"""mask""": {"""hash""": """115ad19f5f""", """shape""": (4_80, 6_40)}, """scores""": 1.0444},
               {"""mask""": {"""hash""": """6affa964c6""", """shape""": (4_80, 6_40)}, """scores""": 1.021},
               {"""mask""": {"""hash""": """dfe28a0388""", """shape""": (4_80, 6_40)}, """scores""": 1.0167},
               {"""mask""": {"""hash""": """c0a5f4a318""", """shape""": (4_80, 6_40)}, """scores""": 1.0132},
               {"""mask""": {"""hash""": """fe8065c197""", """shape""": (4_80, 6_40)}, """scores""": 1.0053},
               {"""mask""": {"""hash""": """e2d0b7a0b7""", """shape""": (4_80, 6_40)}, """scores""": 0.9967},
               {"""mask""": {"""hash""": """453c7844bd""", """shape""": (4_80, 6_40)}, """scores""": 0.993},
               {"""mask""": {"""hash""": """3d44f2926d""", """shape""": (4_80, 6_40)}, """scores""": 0.9909},
               {"""mask""": {"""hash""": """64033ddc3f""", """shape""": (4_80, 6_40)}, """scores""": 0.9879},
               {"""mask""": {"""hash""": """801064ff79""", """shape""": (4_80, 6_40)}, """scores""": 0.9834},
               {"""mask""": {"""hash""": """6172f276ef""", """shape""": (4_80, 6_40)}, """scores""": 0.9716},
               {"""mask""": {"""hash""": """b49e60e084""", """shape""": (4_80, 6_40)}, """scores""": 0.9612},
               {"""mask""": {"""hash""": """a811e775fd""", """shape""": (4_80, 6_40)}, """scores""": 0.9599},
               {"""mask""": {"""hash""": """a6a8ebcf4b""", """shape""": (4_80, 6_40)}, """scores""": 0.9552},
               {"""mask""": {"""hash""": """9d8257e080""", """shape""": (4_80, 6_40)}, """scores""": 0.9532},
               {"""mask""": {"""hash""": """32de6454a8""", """shape""": (4_80, 6_40)}, """scores""": 0.9516},
               {"""mask""": {"""hash""": """af3d4af2c8""", """shape""": (4_80, 6_40)}, """scores""": 0.9499},
               {"""mask""": {"""hash""": """3c6db475fb""", """shape""": (4_80, 6_40)}, """scores""": 0.9483},
               {"""mask""": {"""hash""": """c290813fb9""", """shape""": (4_80, 6_40)}, """scores""": 0.9464},
               {"""mask""": {"""hash""": """b6f0b8f606""", """shape""": (4_80, 6_40)}, """scores""": 0.943},
               {"""mask""": {"""hash""": """92ce16bfdf""", """shape""": (4_80, 6_40)}, """scores""": 0.943},
               {"""mask""": {"""hash""": """c749b25868""", """shape""": (4_80, 6_40)}, """scores""": 0.9408},
               {"""mask""": {"""hash""": """efb6cab859""", """shape""": (4_80, 6_40)}, """scores""": 0.9335},
               {"""mask""": {"""hash""": """1ff2eafb30""", """shape""": (4_80, 6_40)}, """scores""": 0.9326},
               {"""mask""": {"""hash""": """788b798e24""", """shape""": (4_80, 6_40)}, """scores""": 0.9262},
               {"""mask""": {"""hash""": """abea804f0e""", """shape""": (4_80, 6_40)}, """scores""": 0.8999},
               {"""mask""": {"""hash""": """7b9e8ddb73""", """shape""": (4_80, 6_40)}, """scores""": 0.8986},
               {"""mask""": {"""hash""": """cd24047c8a""", """shape""": (4_80, 6_40)}, """scores""": 0.8984},
               {"""mask""": {"""hash""": """6943e6bcbd""", """shape""": (4_80, 6_40)}, """scores""": 0.8873},
               {"""mask""": {"""hash""": """b5f47c9191""", """shape""": (4_80, 6_40)}, """scores""": 0.8871}
           ]	,      )
       # fmt: on







  @require_torch
  @slow
  def 	UpperCAmelCase_ (self						):
       UpperCamelCase__				=    """facebook/sam-vit-huge"""
       UpperCamelCase__				=    pipeline("""mask-generation"""	,      model=SCREAMING_SNAKE_CASE_						)

       UpperCamelCase__				=    image_segmenter(
           """http://images.cocodataset.org/val2017/000000039769.jpg"""	,      pred_iou_thresh=1	,      points_per_batch=2_56						)

       # Shortening by hashing
       UpperCamelCase__				=    []
       for i, o in enumerate(outputs["""masks"""]						):
            new_outupt += [{"mask": mask_to_test_readable(SCREAMING_SNAKE_CASE_						), "scores": outputs["scores"][i]}]

       self.assertEqual(
           nested_simplify(SCREAMING_SNAKE_CASE_	,      decimals=4						)	,      [
               {"""mask""": {"""hash""": """115ad19f5f""", """shape""": (4_80, 6_40)}, """scores""": 1.0444},
               {"""mask""": {"""hash""": """6affa964c6""", """shape""": (4_80, 6_40)}, """scores""": 1.0210},
               {"""mask""": {"""hash""": """dfe28a0388""", """shape""": (4_80, 6_40)}, """scores""": 1.0167},
               {"""mask""": {"""hash""": """c0a5f4a318""", """shape""": (4_80, 6_40)}, """scores""": 1.0132},
               {"""mask""": {"""hash""": """fe8065c197""", """shape""": (4_80, 6_40)}, """scores""": 1.0053},
           ]	,      )





