






'''simple docstring'''




# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING, Dict, Optional

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.logging import get_logger
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
    import jax
    import jaxlib

lowerCamelCase_												=					get_logger()

lowerCamelCase_												=					None

class    _UpperCAmelCase			(     TensorFormatter[Mapping, '''jax.Array''', Mapping]						):




   """simple docstring"""

   def __init__(		self :	int      ,      __UpperCAmelCase :	int=None      ,      __UpperCAmelCase :	List[str]=None      ,      **__UpperCAmelCase :	Optional[int]		):





         '''simple docstring'''





         super().__init__(features=__UpperCAmelCase		)
         import jax
         from jaxlib.xla_client import Device

         if isinstance(__UpperCAmelCase      ,      __UpperCAmelCase		):
               raise ValueError(
                   f'''Expected {device} to be a `str` not {type(__UpperCAmelCase		)}, as `jaxlib.xla_extension.Device` '''
                   "is not serializable neither with `pickle` nor with `dill`. Instead you can surround "
                   "the device with `str()` to get its string identifier that will be internally mapped "
                   "to the actual `jaxlib.xla_extension.Device`."		)
         _A			     =	device if isinstance(__UpperCAmelCase      ,      __UpperCAmelCase		) else str(jax.devices()[0]		)
         # using global variable since `jaxlib.xla_extension.Device` is not serializable neither
         # with `pickle` nor with `dill`, so we need to use a global variable instead
         global DEVICE_MAPPING
         if DEVICE_MAPPING is None:
               _A			     =	self._map_devices_to_str()
         if self.device not in list(DEVICE_MAPPING.keys()		):
               logger.warning(
                   f'''Device with string identifier {self.device} not listed among the available '''
                   f'''devices: {list(DEVICE_MAPPING.keys()		)}, so falling back to the default '''
                   f'''device: {str(jax.devices()[0]		)}.'''		)
               _A			     =	str(jax.devices()[0]		)
         _A			     =	jnp_array_kwargs

   @staticmethod
   def 						lowerCAmelCase (		):





         '''simple docstring'''





         import jax

         return {str(__UpperCAmelCase		): device for device in jax.devices()}

   def 						lowerCAmelCase (		self :	Any      ,      __UpperCAmelCase :	Union[str, Any]		):





         '''simple docstring'''





         import jax
         import jax.numpy as jnp

         if isinstance(__UpperCAmelCase      ,      __UpperCAmelCase		) and column:
               if all(
                   isinstance(__UpperCAmelCase      ,      jax.Array		) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column		):
                     return jnp.stack(__UpperCAmelCase      ,      axis=0		)
         return column

   def 						lowerCAmelCase (		self :	int      ,      __UpperCAmelCase :	List[str]		):





         '''simple docstring'''





         import jax
         import jax.numpy as jnp

         if isinstance(__UpperCAmelCase      ,      (str, bytes, type(__UpperCAmelCase		))		):
               return value
         elif isinstance(__UpperCAmelCase      ,      (np.character, np.ndarray)		) and np.issubdtype(value.dtype      ,      np.character		):
               return value.tolist()

         _A			     =	{}

         if isinstance(__UpperCAmelCase      ,      (np.number, np.ndarray)		) and np.issubdtype(value.dtype      ,      np.integer		):
               # the default int precision depends on the jax config
               # see https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#double-64bit-precision
               if jax.config.jax_enable_xaa:
                     _A			     =	{"dtype": jnp.intaa}
               else:
                     _A			     =	{"dtype": jnp.intaa}
         elif isinstance(__UpperCAmelCase      ,      (np.number, np.ndarray)		) and np.issubdtype(value.dtype      ,      np.floating		):
               _A			     =	{"dtype": jnp.floataa}
         elif config.PIL_AVAILABLE and "PIL" in sys.modules:
               import PIL.Image

               if isinstance(__UpperCAmelCase      ,      PIL.Image.Image		):
                     _A			     =	np.asarray(__UpperCAmelCase		)

        # using global variable since `jaxlib.xla_extension.Device` is not serializable neither
        # with `pickle` nor with `dill`, so we need to use a global variable instead
         global DEVICE_MAPPING
         if DEVICE_MAPPING is None:
               _A			     =	self._map_devices_to_str()

         with jax.default_device(DEVICE_MAPPING[self.device]		):
               # calling jnp.array on a np.ndarray does copy the data
               # see https://github.com/google/jax/issues/4486
               return jnp.array(__UpperCAmelCase      ,      **{**default_dtype, **self.jnp_array_kwargs}		)

   def 						lowerCAmelCase (		self :	Optional[Any]      ,      __UpperCAmelCase :	int		):





         '''simple docstring'''





         import jax

         # support for torch, tf, jax etc.
         if config.TORCH_AVAILABLE and "torch" in sys.modules:
               import torch

               if isinstance(__UpperCAmelCase      ,      torch.Tensor		):
                     return self._tensorize(data_struct.detach().cpu().numpy()[()]		)
         if hasattr(__UpperCAmelCase      ,      "__array__"		) and not isinstance(__UpperCAmelCase      ,      jax.Array		):
               _A			     =	data_struct.__array__()
         # support for nested types like struct of list of struct
         if isinstance(__UpperCAmelCase      ,      np.ndarray		):
               if data_struct.dtype == object:  # jax arrays cannot be instantied from an array of objects
                     return self._consolidate([self.recursive_tensorize(__UpperCAmelCase		) for substruct in data_struct]		)
         elif isinstance(__UpperCAmelCase      ,      (list, tuple)		):
               return self._consolidate([self.recursive_tensorize(__UpperCAmelCase		) for substruct in data_struct]		)
         return self._tensorize(__UpperCAmelCase		)

   def 						lowerCAmelCase (		self :	List[Any]      ,      __UpperCAmelCase :	dict		):





         '''simple docstring'''





         return map_nested(self._recursive_tensorize      ,      __UpperCAmelCase      ,      map_list=__UpperCAmelCase		)

   def 						lowerCAmelCase (		self :	str      ,      __UpperCAmelCase :	pa.Table		):





         '''simple docstring'''





         _A			     =	self.numpy_arrow_extractor().extract_row(__UpperCAmelCase		)
         _A			     =	self.python_features_decoder.decode_row(__UpperCAmelCase		)
         return self.recursive_tensorize(__UpperCAmelCase		)

   def 						lowerCAmelCase (		self :	List[str]      ,      __UpperCAmelCase :	pa.Table		):





         '''simple docstring'''





         _A			     =	self.numpy_arrow_extractor().extract_column(__UpperCAmelCase		)
         _A			     =	self.python_features_decoder.decode_column(__UpperCAmelCase      ,      pa_table.column_names[0]		)
         _A			     =	self.recursive_tensorize(__UpperCAmelCase		)
         _A			     =	self._consolidate(__UpperCAmelCase		)
         return column

   def 						lowerCAmelCase (		self :	Union[str, Any]      ,      __UpperCAmelCase :	pa.Table		):





         '''simple docstring'''





         _A			     =	self.numpy_arrow_extractor().extract_batch(__UpperCAmelCase		)
         _A			     =	self.python_features_decoder.decode_batch(__UpperCAmelCase		)
         _A			     =	self.recursive_tensorize(__UpperCAmelCase		)
         for column_name in batch:
               _A			     =	self._consolidate(batch[column_name]		)
         return batch






"""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 YolosImageProcessor


class     UpperCAmelCase						(unittest.TestCase  ):



    """simple docstring"""

    def __init__(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase=7    ,			_UpperCAmelCase=3    ,			_UpperCAmelCase=30    ,			_UpperCAmelCase=400    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=None    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=[0.5, 0.5, 0.5]    ,			_UpperCAmelCase=[0.5, 0.5, 0.5]    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=1 / 255    ,			_UpperCAmelCase=True    ,			):
       # by setting size["longest_edge"] > max_resolution we're effectively not testing this :p
       lowercase__:   str					=      size if size is not None else {'''shortest_edge''': 18, '''longest_edge''': 1333}
       lowercase__:   Optional[Any]					=      parent
       lowercase__:   List[Any]					=      batch_size
       lowercase__:   Tuple					=      num_channels
       lowercase__:   Optional[Any]					=      min_resolution
       lowercase__:   Dict					=      max_resolution
       lowercase__:   Optional[int]					=      do_resize
       lowercase__:   Any					=      size
       lowercase__:   Optional[Any]					=      do_normalize
       lowercase__:   Union[str, Any]					=      image_mean
       lowercase__:   Tuple					=      image_std
       lowercase__:   str					=      do_rescale
       lowercase__:   Any					=      rescale_factor
       lowercase__:   List[Any]					=      do_pad






    def _snake_case			(   self							):
       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 _snake_case			(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase=False							):
       if not batched:
          lowercase__:   Optional[Any]					=      image_inputs[0]
          if isinstance(_UpperCAmelCase    ,			Image.Image							):
             lowercase__, lowercase__:   Dict					=      image.size
          else:
             lowercase__, lowercase__:   Optional[Any]					=      image.shape[1], image.shape[2]
          if w < h:
             lowercase__:   List[str]					=      int(self.size['''shortest_edge'''] * h / w							)
             lowercase__:   Union[str, Any]					=      self.size['''shortest_edge''']
          elif w > h:
             lowercase__:   int					=      self.size['''shortest_edge''']
             lowercase__:   int					=      int(self.size['''shortest_edge'''] * w / h							)
          else:
             lowercase__:   Union[str, Any]					=      self.size['''shortest_edge''']
             lowercase__:   Union[str, Any]					=      self.size['''shortest_edge''']

       else:
          lowercase__:   Optional[int]					=      []
          for image in image_inputs:
             lowercase__, lowercase__:   int					=      self.get_expected_values([image]							)
             expected_values.append((expected_height, expected_width)							)
          lowercase__:   Union[str, Any]					=      max(_UpperCAmelCase    ,			key=lambda _UpperCAmelCase							: item[0]							)[0]
          lowercase__:   Dict					=      max(_UpperCAmelCase    ,			key=lambda _UpperCAmelCase							: item[1]							)[1]

       return expected_height, expected_width



@require_torch
@require_vision
class     UpperCAmelCase						(_UpperCAmelCase    ,unittest.TestCase  ):



    """simple docstring"""

    _UpperCAmelCase	:Optional[int]						    = YolosImageProcessor if is_vision_available() else None






    def _snake_case			(   self							):
       lowercase__:   int					=      YolosImageProcessingTester(self							)






    @property
    def _snake_case			(   self							):
       return self.image_processor_tester.prepare_image_processor_dict()






    def _snake_case			(   self							):
       lowercase__:   List[str]					=      self.image_processing_class(**self.image_processor_dict							)
       self.assertTrue(hasattr(_UpperCAmelCase    ,			'''image_mean'''							)							)
       self.assertTrue(hasattr(_UpperCAmelCase    ,			'''image_std'''							)							)
       self.assertTrue(hasattr(_UpperCAmelCase    ,			'''do_normalize'''							)							)
       self.assertTrue(hasattr(_UpperCAmelCase    ,			'''do_resize'''							)							)
       self.assertTrue(hasattr(_UpperCAmelCase    ,			'''size'''							)							)






    def _snake_case			(   self							):
       lowercase__:   Any					=      self.image_processing_class.from_dict(self.image_processor_dict							)
       self.assertEqual(image_processor.size    ,			{'''shortest_edge''': 18, '''longest_edge''': 1333}							)
       self.assertEqual(image_processor.do_pad    ,			_UpperCAmelCase							)

       lowercase__:   Any					=      self.image_processing_class.from_dict(
           self.image_processor_dict    ,			size=42    ,			max_size=84    ,			pad_and_return_pixel_mask=_UpperCAmelCase							)
       self.assertEqual(image_processor.size    ,			{'''shortest_edge''': 42, '''longest_edge''': 84}							)
       self.assertEqual(image_processor.do_pad    ,			_UpperCAmelCase							)






    def _snake_case			(   self							):
       pass






    def _snake_case			(   self							):
       # Initialize image_processing
       lowercase__:   Union[str, Any]					=      self.image_processing_class(**self.image_processor_dict							)
       # create random PIL images
       lowercase__:   Dict					=      prepare_image_inputs(self.image_processor_tester    ,			equal_resolution=_UpperCAmelCase							)
       for image in image_inputs:
          self.assertIsInstance(_UpperCAmelCase    ,			Image.Image							)

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

       lowercase__, lowercase__:   Optional[int]					=      self.image_processor_tester.get_expected_values(_UpperCAmelCase							)

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

       # Test batched
       lowercase__, lowercase__:   Any					=      self.image_processor_tester.get_expected_values(_UpperCAmelCase    ,			batched=_UpperCAmelCase							)

       lowercase__:   int					=      image_processing(_UpperCAmelCase    ,			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 _snake_case			(   self							):
       # Initialize image_processing
       lowercase__:   List[str]					=      self.image_processing_class(**self.image_processor_dict							)
       # create random numpy tensors
       lowercase__:   Optional[Any]					=      prepare_image_inputs(self.image_processor_tester    ,			equal_resolution=_UpperCAmelCase    ,			numpify=_UpperCAmelCase							)
       for image in image_inputs:
          self.assertIsInstance(_UpperCAmelCase    ,			np.ndarray							)

       # Test not batched input
       lowercase__:   List[Any]					=      image_processing(image_inputs[0]    ,			return_tensors='''pt'''							).pixel_values

       lowercase__, lowercase__:   str					=      self.image_processor_tester.get_expected_values(_UpperCAmelCase							)

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

       # Test batched
       lowercase__:   Dict					=      image_processing(_UpperCAmelCase    ,			return_tensors='''pt'''							).pixel_values

       lowercase__, lowercase__:   str					=      self.image_processor_tester.get_expected_values(_UpperCAmelCase    ,			batched=_UpperCAmelCase							)

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






    def _snake_case			(   self							):
       # Initialize image_processing
       lowercase__:   Any					=      self.image_processing_class(**self.image_processor_dict							)
       # create random PyTorch tensors
       lowercase__:   Optional[Any]					=      prepare_image_inputs(self.image_processor_tester    ,			equal_resolution=_UpperCAmelCase    ,			torchify=_UpperCAmelCase							)
       for image in image_inputs:
          self.assertIsInstance(_UpperCAmelCase    ,			torch.Tensor							)

       # Test not batched input
       lowercase__:   Optional[int]					=      image_processing(image_inputs[0]    ,			return_tensors='''pt'''							).pixel_values

       lowercase__, lowercase__:   int					=      self.image_processor_tester.get_expected_values(_UpperCAmelCase							)

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

       # Test batched
       lowercase__:   List[str]					=      image_processing(_UpperCAmelCase    ,			return_tensors='''pt'''							).pixel_values

       lowercase__, lowercase__:   List[Any]					=      self.image_processor_tester.get_expected_values(_UpperCAmelCase    ,			batched=_UpperCAmelCase							)

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






    def _snake_case			(   self							):
       # Initialize image_processings
       lowercase__:   Union[str, Any]					=      self.image_processing_class(**self.image_processor_dict							)
       lowercase__:   Optional[Any]					=      self.image_processing_class(do_resize=_UpperCAmelCase    ,			do_normalize=_UpperCAmelCase    ,			do_rescale=_UpperCAmelCase							)
       # create random PyTorch tensors
       lowercase__:   Optional[Any]					=      prepare_image_inputs(self.image_processor_tester    ,			equal_resolution=_UpperCAmelCase    ,			torchify=_UpperCAmelCase							)
       for image in image_inputs:
          self.assertIsInstance(_UpperCAmelCase    ,			torch.Tensor							)

       # Test whether the method "pad" and calling the image processor return the same tensors
       lowercase__:   List[str]					=      image_processing_a.pad(_UpperCAmelCase    ,			return_tensors='''pt'''							)
       lowercase__:   Tuple					=      image_processing_a(_UpperCAmelCase    ,			return_tensors='''pt'''							)

       self.assertTrue(
           torch.allclose(encoded_images_with_method['''pixel_values''']    ,			encoded_images['''pixel_values''']    ,			atol=1e-4							)							)






    @slow
    def _snake_case			(   self							):
       # prepare image and target
       lowercase__:   Tuple					=      Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
       with open('''./tests/fixtures/tests_samples/COCO/coco_annotations.txt'''    ,			'''r'''							) as f:
          lowercase__:   Any					=      json.loads(f.read()							)

       lowercase__:   Dict					=      {'''image_id''': 39769, '''annotations''': target}

       # encode them
       lowercase__:   Dict					=      YolosImageProcessor.from_pretrained('''hustvl/yolos-small'''							)
       lowercase__:   Any					=      image_processing(images=_UpperCAmelCase    ,			annotations=_UpperCAmelCase    ,			return_tensors='''pt'''							)

       # verify pixel values
       lowercase__:   Optional[Any]					=      torch.Size([1, 3, 800, 1066]							)
       self.assertEqual(encoding['''pixel_values'''].shape    ,			_UpperCAmelCase							)

       lowercase__:   Optional[Any]					=      torch.tensor([0.2_796, 0.3_138, 0.3_481]							)
       self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3]    ,			_UpperCAmelCase    ,			atol=1e-4							)							)

       # verify area
       lowercase__:   Tuple					=      torch.tensor([5_887.9_600, 11_250.2_061, 489_353.8_438, 837_122.7_500, 147_967.5_156, 165_732.3_438]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area''']    ,			_UpperCAmelCase							)							)
       # verify boxes
       lowercase__:   str					=      torch.Size([6, 4]							)
       self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape    ,			_UpperCAmelCase							)
       lowercase__:   List[Any]					=      torch.tensor([0.5_503, 0.2_765, 0.0_604, 0.2_215]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]    ,			_UpperCAmelCase    ,			atol=1e-3							)							)
       # verify image_id
       lowercase__:   Optional[int]					=      torch.tensor([39769]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']    ,			_UpperCAmelCase							)							)
       # verify is_crowd
       lowercase__:   Optional[int]					=      torch.tensor([0, 0, 0, 0, 0, 0]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']    ,			_UpperCAmelCase							)							)
       # verify class_labels
       lowercase__:   Dict					=      torch.tensor([75, 75, 63, 65, 17, 17]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']    ,			_UpperCAmelCase							)							)
       # verify orig_size
       lowercase__:   List[Any]					=      torch.tensor([480, 640]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']    ,			_UpperCAmelCase							)							)
       # verify size
       lowercase__:   List[Any]					=      torch.tensor([800, 1066]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']    ,			_UpperCAmelCase							)							)






    @slow
    def _snake_case			(   self							):
       # prepare image, target and masks_path
       lowercase__:   str					=      Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
       with open('''./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt'''    ,			'''r'''							) as f:
          lowercase__:   str					=      json.loads(f.read()							)

       lowercase__:   List[Any]					=      {'''file_name''': '''000000039769.png''', '''image_id''': 39769, '''segments_info''': target}

       lowercase__:   Dict					=      pathlib.Path('''./tests/fixtures/tests_samples/COCO/coco_panoptic'''							)

       # encode them
       lowercase__:   Union[str, Any]					=      YolosImageProcessor(format='''coco_panoptic'''							)
       lowercase__:   Optional[Any]					=      image_processing(images=_UpperCAmelCase    ,			annotations=_UpperCAmelCase    ,			masks_path=_UpperCAmelCase    ,			return_tensors='''pt'''							)

       # verify pixel values
       lowercase__:   Optional[int]					=      torch.Size([1, 3, 800, 1066]							)
       self.assertEqual(encoding['''pixel_values'''].shape    ,			_UpperCAmelCase							)

       lowercase__:   Dict					=      torch.tensor([0.2_796, 0.3_138, 0.3_481]							)
       self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3]    ,			_UpperCAmelCase    ,			atol=1e-4							)							)

       # verify area
       lowercase__:   str					=      torch.tensor([147_979.6_875, 165_527.0_469, 484_638.5_938, 11_292.9_375, 5_879.6_562, 7_634.1_147]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area''']    ,			_UpperCAmelCase							)							)
       # verify boxes
       lowercase__:   List[str]					=      torch.Size([6, 4]							)
       self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape    ,			_UpperCAmelCase							)
       lowercase__:   List[Any]					=      torch.tensor([0.2_625, 0.5_437, 0.4_688, 0.8_625]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]    ,			_UpperCAmelCase    ,			atol=1e-3							)							)
       # verify image_id
       lowercase__:   int					=      torch.tensor([39769]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']    ,			_UpperCAmelCase							)							)
       # verify is_crowd
       lowercase__:   int					=      torch.tensor([0, 0, 0, 0, 0, 0]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']    ,			_UpperCAmelCase							)							)
       # verify class_labels
       lowercase__:   Dict					=      torch.tensor([17, 17, 63, 75, 75, 93]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']    ,			_UpperCAmelCase							)							)
       # verify masks
       lowercase__:   Union[str, Any]					=      822873
       self.assertEqual(encoding['''labels'''][0]['''masks'''].sum().item()    ,			_UpperCAmelCase							)
       # verify orig_size
       lowercase__:   List[Any]					=      torch.tensor([480, 640]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']    ,			_UpperCAmelCase							)							)
       # verify size
       lowercase__:   Union[str, Any]					=      torch.tensor([800, 1066]							)
       self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']    ,			_UpperCAmelCase							)							)
