
'''simple docstring'''


import argparse
import json
import logging
import os
import sys
from unittest.mock import patch

from transformers.testing_utils import TestCasePlus, get_gpu_count, slow


snake_case_ :  Union[str, Any]     =					[
    os.path.join(os.path.dirname(__file__), dirname)
    for dirname in [
        'text-classification',
        'language-modeling',
        'summarization',
        'token-classification',
        'question-answering',
    ]
]
sys.path.extend(SRC_DIRS)


if SRC_DIRS is not None:
   import run_clm_flax
   import run_flax_glue
   import run_flax_ner
   import run_mlm_flax
   import run_qa
   import run_summarization_flax
   import run_ta_mlm_flax


logging.basicConfig(level=logging.DEBUG)

snake_case_ :  Optional[Any]     =					logging.getLogger()



def  __snake_case     (    ):
   UpperCamelCase       =  argparse.ArgumentParser()
   parser.add_argument('''-f''')
   UpperCamelCase       =  parser.parse_args()
   return args.f



def  __snake_case     (    _UpperCAmelCase					:       Union[str, Any],      _UpperCAmelCase					:       Dict="eval"):
   UpperCamelCase       =  os.path.join(_UpperCAmelCase,      f'{split}_results.json')
   if os.path.exists(_UpperCAmelCase):
      with open(_UpperCAmelCase,      '''r''') as f:
         return json.load(_UpperCAmelCase)
   raise ValueError(f'can\'t find {path}')


snake_case_ :  List[str]     =					logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)


class 						lowercase__	(  snake_case_   ):






   '''simple docstring'''







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.get_auto_remove_tmp_dir()
      UpperCamelCase       =  f'\n            run_glue.py\n            --model_name_or_path distilbert-base-uncased\n            --output_dir {tmp_dir}\n            --train_file ./tests/fixtures/tests_samples/MRPC/train.csv\n            --validation_file ./tests/fixtures/tests_samples/MRPC/dev.csv\n            --per_device_train_batch_size=2\n            --per_device_eval_batch_size=1\n            --learning_rate=1e-4\n            --eval_steps=2\n            --warmup_steps=2\n            --seed=42\n            --max_seq_length=128\n            '.split()

      with patch.object(lowerCamelCase__ ,   '''argv''' ,   lowerCamelCase__   ):
         run_flax_glue.main()
         UpperCamelCase       =  get_results(lowerCamelCase__   )
         self.assertGreaterEqual(result['''eval_accuracy'''] ,   0.75   )







   @slow
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.get_auto_remove_tmp_dir()
      UpperCamelCase       =  f'\n            run_clm_flax.py\n            --model_name_or_path distilgpt2\n            --train_file ./tests/fixtures/sample_text.txt\n            --validation_file ./tests/fixtures/sample_text.txt\n            --do_train\n            --do_eval\n            --block_size 128\n            --per_device_train_batch_size 4\n            --per_device_eval_batch_size 4\n            --num_train_epochs 2\n            --logging_steps 2 --eval_steps 2\n            --output_dir {tmp_dir}\n            --overwrite_output_dir\n            '.split()

      with patch.object(lowerCamelCase__ ,   '''argv''' ,   lowerCamelCase__   ):
         run_clm_flax.main()
         UpperCamelCase       =  get_results(lowerCamelCase__   )
         self.assertLess(result['''eval_perplexity'''] ,   1_0_0   )







   @slow
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.get_auto_remove_tmp_dir()
      UpperCamelCase       =  f'\n            run_summarization.py\n            --model_name_or_path t5-small\n            --train_file tests/fixtures/tests_samples/xsum/sample.json\n            --validation_file tests/fixtures/tests_samples/xsum/sample.json\n            --test_file tests/fixtures/tests_samples/xsum/sample.json\n            --output_dir {tmp_dir}\n            --overwrite_output_dir\n            --num_train_epochs=3\n            --warmup_steps=8\n            --do_train\n            --do_eval\n            --do_predict\n            --learning_rate=2e-4\n            --per_device_train_batch_size=2\n            --per_device_eval_batch_size=1\n            --predict_with_generate\n        '.split()

      with patch.object(lowerCamelCase__ ,   '''argv''' ,   lowerCamelCase__   ):
         run_summarization_flax.main()
         UpperCamelCase       =  get_results(lowerCamelCase__ ,   split='''test'''   )
         self.assertGreaterEqual(result['''test_rouge1'''] ,   1_0   )
         self.assertGreaterEqual(result['''test_rouge2'''] ,   2   )
         self.assertGreaterEqual(result['''test_rougeL'''] ,   7   )
         self.assertGreaterEqual(result['''test_rougeLsum'''] ,   7   )







   @slow
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.get_auto_remove_tmp_dir()
      UpperCamelCase       =  f'\n            run_mlm.py\n            --model_name_or_path distilroberta-base\n            --train_file ./tests/fixtures/sample_text.txt\n            --validation_file ./tests/fixtures/sample_text.txt\n            --output_dir {tmp_dir}\n            --overwrite_output_dir\n            --max_seq_length 128\n            --per_device_train_batch_size 4\n            --per_device_eval_batch_size 4\n            --logging_steps 2 --eval_steps 2\n            --do_train\n            --do_eval\n            --num_train_epochs=1\n        '.split()

      with patch.object(lowerCamelCase__ ,   '''argv''' ,   lowerCamelCase__   ):
         run_mlm_flax.main()
         UpperCamelCase       =  get_results(lowerCamelCase__   )
         self.assertLess(result['''eval_perplexity'''] ,   4_2   )







   @slow
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.get_auto_remove_tmp_dir()
      UpperCamelCase       =  f'\n            run_t5_mlm_flax.py\n            --model_name_or_path t5-small\n            --train_file ./tests/fixtures/sample_text.txt\n            --validation_file ./tests/fixtures/sample_text.txt\n            --do_train\n            --do_eval\n            --max_seq_length 128\n            --per_device_train_batch_size 4\n            --per_device_eval_batch_size 4\n            --num_train_epochs 2\n            --logging_steps 2 --eval_steps 2\n            --output_dir {tmp_dir}\n            --overwrite_output_dir\n            '.split()

      with patch.object(lowerCamelCase__ ,   '''argv''' ,   lowerCamelCase__   ):
         run_ta_mlm_flax.main()
         UpperCamelCase       =  get_results(lowerCamelCase__   )
         self.assertGreaterEqual(result['''eval_accuracy'''] ,   0.42   )







   @slow
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  7 if get_gpu_count() > 1 else 2

      UpperCamelCase       =  self.get_auto_remove_tmp_dir()
      UpperCamelCase       =  f'\n            run_flax_ner.py\n            --model_name_or_path bert-base-uncased\n            --train_file tests/fixtures/tests_samples/conll/sample.json\n            --validation_file tests/fixtures/tests_samples/conll/sample.json\n            --output_dir {tmp_dir}\n            --overwrite_output_dir\n            --do_train\n            --do_eval\n            --warmup_steps=2\n            --learning_rate=2e-4\n            --logging_steps 2 --eval_steps 2\n            --per_device_train_batch_size=2\n            --per_device_eval_batch_size=2\n            --num_train_epochs={epochs}\n            --seed 7\n        '.split()

      with patch.object(lowerCamelCase__ ,   '''argv''' ,   lowerCamelCase__   ):
         run_flax_ner.main()
         UpperCamelCase       =  get_results(lowerCamelCase__   )
         self.assertGreaterEqual(result['''eval_accuracy'''] ,   0.75   )
         self.assertGreaterEqual(result['''eval_f1'''] ,   0.3   )







   @slow
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.get_auto_remove_tmp_dir()
      UpperCamelCase       =  f'\n            run_qa.py\n            --model_name_or_path bert-base-uncased\n            --version_2_with_negative\n            --train_file tests/fixtures/tests_samples/SQUAD/sample.json\n            --validation_file tests/fixtures/tests_samples/SQUAD/sample.json\n            --output_dir {tmp_dir}\n            --overwrite_output_dir\n            --num_train_epochs=3\n            --warmup_steps=2\n            --do_train\n            --do_eval\n            --logging_steps 2 --eval_steps 2\n            --learning_rate=2e-4\n            --per_device_train_batch_size=2\n            --per_device_eval_batch_size=1\n        '.split()

      with patch.object(lowerCamelCase__ ,   '''argv''' ,   lowerCamelCase__   ):
         run_qa.main()
         UpperCamelCase       =  get_results(lowerCamelCase__   )
         self.assertGreaterEqual(result['''eval_f1'''] ,   3_0   )
         self.assertGreaterEqual(result['''eval_exact'''] ,   3_0   )







'''simple docstring'''


import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import DeformableDetrImageProcessor


class 						lowercase__	(  unittest.TestCase   ):






   '''simple docstring'''







   def __init__(			self ,   lowerCamelCase__ ,   lowerCamelCase__=7 ,   lowerCamelCase__=3 ,   lowerCamelCase__=3_0 ,   lowerCamelCase__=4_0_0 ,   lowerCamelCase__=True ,   lowerCamelCase__=None ,   lowerCamelCase__=True ,   lowerCamelCase__=[0.5, 0.5, 0.5] ,   lowerCamelCase__=[0.5, 0.5, 0.5] ,   lowerCamelCase__=True ,   lowerCamelCase__=1 / 2_5_5 ,   lowerCamelCase__=True ,   ):

      '''simple docstring'''







      UpperCamelCase       =  size if size is not None else {'''shortest_edge''': 1_8, '''longest_edge''': 1_3_3_3}
      UpperCamelCase       =  parent
      UpperCamelCase       =  batch_size
      UpperCamelCase       =  num_channels
      UpperCamelCase       =  min_resolution
      UpperCamelCase       =  max_resolution
      UpperCamelCase       =  do_resize
      UpperCamelCase       =  size
      UpperCamelCase       =  do_normalize
      UpperCamelCase       =  image_mean
      UpperCamelCase       =  image_std
      UpperCamelCase       =  do_rescale
      UpperCamelCase       =  rescale_factor
      UpperCamelCase       =  do_pad







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_normalize": self.do_normalize,
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_rescale": self.do_rescale,
          "rescale_factor": self.rescale_factor,
          "do_pad": self.do_pad,
      }







   def       UpperCAmelCase				(			self ,   lowerCamelCase__ ,   lowerCamelCase__=False   ):

      '''simple docstring'''







      if not batched:
         UpperCamelCase       =  image_inputs[0]
         if isinstance(lowerCamelCase__ ,   Image.Image   ):
            UpperCamelCase     , UpperCamelCase       =  image.size
         else:
            UpperCamelCase     , UpperCamelCase       =  image.shape[1], image.shape[2]
         if w < h:
            UpperCamelCase       =  int(self.size['''shortest_edge'''] * h / w   )
            UpperCamelCase       =  self.size['''shortest_edge''']
         elif w > h:
            UpperCamelCase       =  self.size['''shortest_edge''']
            UpperCamelCase       =  int(self.size['''shortest_edge'''] * w / h   )
         else:
            UpperCamelCase       =  self.size['''shortest_edge''']
            UpperCamelCase       =  self.size['''shortest_edge''']

      else:
         UpperCamelCase       =  []
         for image in image_inputs:
            UpperCamelCase     , UpperCamelCase       =  self.get_expected_values([image]   )
            expected_values.append((expected_height, expected_width)   )
         UpperCamelCase       =  max(lowerCamelCase__ ,   key=lambda lowerCamelCase__   : item[0]   )[0]
         UpperCamelCase       =  max(lowerCamelCase__ ,   key=lambda lowerCamelCase__   : item[1]   )[1]

      return expected_height, expected_width




@require_torch
@require_vision
class 						lowercase__	(  snake_case_,					unittest.TestCase   ):






   '''simple docstring'''







   _snake_case		   =							DeformableDetrImageProcessor if is_vision_available() else None







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  DeformableDetrImageProcessingTester(self   )







   @property
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      return self.image_processor_tester.prepare_image_processor_dict()







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.image_processing_class(**self.image_processor_dict   )
      self.assertTrue(hasattr(lowerCamelCase__ ,   '''image_mean'''   )   )
      self.assertTrue(hasattr(lowerCamelCase__ ,   '''image_std'''   )   )
      self.assertTrue(hasattr(lowerCamelCase__ ,   '''do_normalize'''   )   )
      self.assertTrue(hasattr(lowerCamelCase__ ,   '''do_resize'''   )   )
      self.assertTrue(hasattr(lowerCamelCase__ ,   '''do_rescale'''   )   )
      self.assertTrue(hasattr(lowerCamelCase__ ,   '''do_pad'''   )   )
      self.assertTrue(hasattr(lowerCamelCase__ ,   '''size'''   )   )







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.image_processing_class.from_dict(self.image_processor_dict   )
      self.assertEqual(image_processor.size ,   {'''shortest_edge''': 1_8, '''longest_edge''': 1_3_3_3}   )
      self.assertEqual(image_processor.do_pad ,   lowerCamelCase__   )

      UpperCamelCase       =  self.image_processing_class.from_dict(
          self.image_processor_dict ,   size=4_2 ,   max_size=8_4 ,   pad_and_return_pixel_mask=lowerCamelCase__   )
      self.assertEqual(image_processor.size ,   {'''shortest_edge''': 4_2, '''longest_edge''': 8_4}   )
      self.assertEqual(image_processor.do_pad ,   lowerCamelCase__   )







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      pass







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.image_processing_class(**self.image_processor_dict   )
      # create random PIL images
      UpperCamelCase       =  prepare_image_inputs(self.image_processor_tester ,   equal_resolution=lowerCamelCase__   )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase__ ,   Image.Image   )

      # Test not batched input
      UpperCamelCase       =  image_processing(image_inputs[0] ,   return_tensors='''pt'''   ).pixel_values

      UpperCamelCase     , UpperCamelCase       =  self.image_processor_tester.get_expected_values(lowerCamelCase__   )

      self.assertEqual(
          encoded_images.shape ,   (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,   )

      # Test batched
      UpperCamelCase     , UpperCamelCase       =  self.image_processor_tester.get_expected_values(lowerCamelCase__ ,   batched=lowerCamelCase__   )

      UpperCamelCase       =  image_processing(lowerCamelCase__ ,   return_tensors='''pt'''   ).pixel_values
      self.assertEqual(
          encoded_images.shape ,   (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          ) ,   )







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.image_processing_class(**self.image_processor_dict   )
      # create random numpy tensors
      UpperCamelCase       =  prepare_image_inputs(self.image_processor_tester ,   equal_resolution=lowerCamelCase__ ,   numpify=lowerCamelCase__   )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase__ ,   np.ndarray   )

      # Test not batched input
      UpperCamelCase       =  image_processing(image_inputs[0] ,   return_tensors='''pt'''   ).pixel_values

      UpperCamelCase     , UpperCamelCase       =  self.image_processor_tester.get_expected_values(lowerCamelCase__   )

      self.assertEqual(
          encoded_images.shape ,   (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,   )

      # Test batched
      UpperCamelCase       =  image_processing(lowerCamelCase__ ,   return_tensors='''pt'''   ).pixel_values

      UpperCamelCase     , UpperCamelCase       =  self.image_processor_tester.get_expected_values(lowerCamelCase__ ,   batched=lowerCamelCase__   )

      self.assertEqual(
          encoded_images.shape ,   (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          ) ,   )







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  self.image_processing_class(**self.image_processor_dict   )
      # create random PyTorch tensors
      UpperCamelCase       =  prepare_image_inputs(self.image_processor_tester ,   equal_resolution=lowerCamelCase__ ,   torchify=lowerCamelCase__   )
      for image in image_inputs:
         self.assertIsInstance(lowerCamelCase__ ,   torch.Tensor   )

      # Test not batched input
      UpperCamelCase       =  image_processing(image_inputs[0] ,   return_tensors='''pt'''   ).pixel_values

      UpperCamelCase     , UpperCamelCase       =  self.image_processor_tester.get_expected_values(lowerCamelCase__   )

      self.assertEqual(
          encoded_images.shape ,   (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,   )

      # Test batched
      UpperCamelCase       =  image_processing(lowerCamelCase__ ,   return_tensors='''pt'''   ).pixel_values

      UpperCamelCase     , UpperCamelCase       =  self.image_processor_tester.get_expected_values(lowerCamelCase__ ,   batched=lowerCamelCase__   )

      self.assertEqual(
          encoded_images.shape ,   (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              expected_height,
              expected_width,
          ) ,   )







   @slow
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''   )
      with open('''./tests/fixtures/tests_samples/COCO/coco_annotations.txt''' ,   '''r'''   ) as f:
         UpperCamelCase       =  json.loads(f.read()   )

      UpperCamelCase       =  {'''image_id''': 3_9_7_6_9, '''annotations''': target}

      # encode them
      UpperCamelCase       =  DeformableDetrImageProcessor()
      UpperCamelCase       =  image_processing(images=lowerCamelCase__ ,   annotations=lowerCamelCase__ ,   return_tensors='''pt'''   )

      # verify pixel values
      UpperCamelCase       =  torch.Size([1, 3, 8_0_0, 1_0_6_6]   )
      self.assertEqual(encoding['''pixel_values'''].shape ,   lowerCamelCase__   )

      UpperCamelCase       =  torch.tensor([0.2796, 0.3138, 0.3481]   )
      self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3] ,   lowerCamelCase__ ,   atol=1e-4   )   )

      # verify area
      UpperCamelCase       =  torch.tensor([5887.9600, 11250.2061, 489353.8438, 837122.7500, 147967.5156, 165732.3438]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area'''] ,   lowerCamelCase__   )   )
      # verify boxes
      UpperCamelCase       =  torch.Size([6, 4]   )
      self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape ,   lowerCamelCase__   )
      UpperCamelCase       =  torch.tensor([0.5503, 0.2765, 0.0604, 0.2215]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0] ,   lowerCamelCase__ ,   atol=1e-3   )   )
      # verify image_id
      UpperCamelCase       =  torch.tensor([3_9_7_6_9]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id'''] ,   lowerCamelCase__   )   )
      # verify is_crowd
      UpperCamelCase       =  torch.tensor([0, 0, 0, 0, 0, 0]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd'''] ,   lowerCamelCase__   )   )
      # verify class_labels
      UpperCamelCase       =  torch.tensor([7_5, 7_5, 6_3, 6_5, 1_7, 1_7]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels'''] ,   lowerCamelCase__   )   )
      # verify orig_size
      UpperCamelCase       =  torch.tensor([4_8_0, 6_4_0]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size'''] ,   lowerCamelCase__   )   )
      # verify size
      UpperCamelCase       =  torch.tensor([8_0_0, 1_0_6_6]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size'''] ,   lowerCamelCase__   )   )







   @slow
   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''   )
      with open('''./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt''' ,   '''r'''   ) as f:
         UpperCamelCase       =  json.loads(f.read()   )

      UpperCamelCase       =  {'''file_name''': '''000000039769.png''', '''image_id''': 3_9_7_6_9, '''segments_info''': target}

      UpperCamelCase       =  pathlib.Path('''./tests/fixtures/tests_samples/COCO/coco_panoptic'''   )

      # encode them
      UpperCamelCase       =  DeformableDetrImageProcessor(format='''coco_panoptic'''   )
      UpperCamelCase       =  image_processing(images=lowerCamelCase__ ,   annotations=lowerCamelCase__ ,   masks_path=lowerCamelCase__ ,   return_tensors='''pt'''   )

      # verify pixel values
      UpperCamelCase       =  torch.Size([1, 3, 8_0_0, 1_0_6_6]   )
      self.assertEqual(encoding['''pixel_values'''].shape ,   lowerCamelCase__   )

      UpperCamelCase       =  torch.tensor([0.2796, 0.3138, 0.3481]   )
      self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3] ,   lowerCamelCase__ ,   atol=1e-4   )   )

      # verify area
      UpperCamelCase       =  torch.tensor([147979.6875, 165527.0469, 484638.5938, 11292.9375, 5879.6562, 7634.1147]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area'''] ,   lowerCamelCase__   )   )
      # verify boxes
      UpperCamelCase       =  torch.Size([6, 4]   )
      self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape ,   lowerCamelCase__   )
      UpperCamelCase       =  torch.tensor([0.2625, 0.5437, 0.4688, 0.8625]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0] ,   lowerCamelCase__ ,   atol=1e-3   )   )
      # verify image_id
      UpperCamelCase       =  torch.tensor([3_9_7_6_9]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id'''] ,   lowerCamelCase__   )   )
      # verify is_crowd
      UpperCamelCase       =  torch.tensor([0, 0, 0, 0, 0, 0]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd'''] ,   lowerCamelCase__   )   )
      # verify class_labels
      UpperCamelCase       =  torch.tensor([1_7, 1_7, 6_3, 7_5, 7_5, 9_3]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels'''] ,   lowerCamelCase__   )   )
      # verify masks
      UpperCamelCase       =  8_2_2_8_7_3
      self.assertEqual(encoding['''labels'''][0]['''masks'''].sum().item() ,   lowerCamelCase__   )
      # verify orig_size
      UpperCamelCase       =  torch.tensor([4_8_0, 6_4_0]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size'''] ,   lowerCamelCase__   )   )
      # verify size
      UpperCamelCase       =  torch.tensor([8_0_0, 1_0_6_6]   )
      self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size'''] ,   lowerCamelCase__   )   )





