
import random
import timeit
from functools import wraps
from typing import Callable, Optional

from ..configuration_utils import PretrainedConfig
from ..models.auto.modeling_tf_auto import TF_MODEL_MAPPING, TF_MODEL_WITH_LM_HEAD_MAPPING
from ..utils import is_pyanvml_available, is_tf_available, logging
from .benchmark_utils import (
    Benchmark,
    Memory,
    MemorySummary,
    measure_peak_memory_cpu,
    start_memory_tracing,
    stop_memory_tracing,
)


if is_tf_available():
					import tensorflow as tf
					from tensorflow.python.framework.errors_impl import ResourceExhaustedError

					from .benchmark_args_tf import TensorFlowBenchmarkArguments

if is_pyanvml_available():
					import pyanvml.pyanvml as nvml

SCREAMING_SNAKE_CASE				:str									=							logging.get_logger(__name__)


def 		UpperCAmelCase     (      a_						,  a_		)						->      List[str]:







				"""simple docstring"""



				def run_func(a_		):
								@wraps(a_		)
								def run_in_eager_mode(*a_						,  **a_		):
												return func(*a_						,  **a_		)

								@wraps(a_		)
								@tf.function(experimental_compile=a_		)
								def run_in_graph_mode(*a_						,  **a_		):
												return func(*a_						,  **a_		)

								if do_eager_mode is True:
												if use_xla is not False:
																raise ValueError(
																    "Cannot run model in XLA, if `args.eager_mode` is set to `True`. Please set `args.eager_mode=False`."		)
												return run_in_eager_mode
								else:
												return run_in_graph_mode

				return run_func


def 		UpperCAmelCase     (      a_						,  a_						,  a_		)						->      ["tf.Tensor"]:







				"""simple docstring"""



				__A       =					random.Random()
				__A       =					[rng.randint(0						,  vocab_size - 1		) for i in range(batch_size * sequence_length		)]
				return tf.constant(a_						,  shape=(batch_size, sequence_length)						,  dtype=tf.intaa		)





class 				UpperCAmelCase (    __SCREAMING_SNAKE_CASE    ):




	'''simple docstring'''





	snake_case_          =	42
	snake_case_          =	42
	snake_case_          =	"TensorFlow"






	@property
	def 							UpperCamelCase_    (			self   :					Tuple					):
					return tf.__version__






	def 							UpperCamelCase_    (			self   :					Union[str, Any]				,A   :					str				,A   :					int				,A   :					int					):
					# initialize GPU on separate process
					__A       =					self.args.strategy
					if strategy is None:
									raise ValueError("A device strategy has to be initialized before using TensorFlow."					)
					__A       =					self._prepare_inference_func(A				,A				,A					)
					return self._measure_speed(_inference					)






	def 							UpperCamelCase_    (			self   :					str				,A   :					str				,A   :					int				,A   :					int					):
					__A       =					self.args.strategy
					if strategy is None:
									raise ValueError("A device strategy has to be initialized before using TensorFlow."					)
					__A       =					self._prepare_train_func(A				,A				,A					)
					return self._measure_speed(_train					)






	def 							UpperCamelCase_    (			self   :					Dict				,A   :					str				,A   :					int				,A   :					int					):
					# initialize GPU on separate process
					if self.args.is_gpu:
									tf.config.experimental.set_memory_growth(self.args.gpu_list[self.args.device_idx]				,A					)
					__A       =					self.args.strategy
					if strategy is None:
									raise ValueError("A device strategy has to be initialized before using TensorFlow."					)
					__A       =					self._prepare_inference_func(A				,A				,A					)
					return self._measure_memory(_inference					)






	def 							UpperCamelCase_    (			self   :					int				,A   :					str				,A   :					int				,A   :					int					):
					if self.args.is_gpu:
									tf.config.experimental.set_memory_growth(self.args.gpu_list[self.args.device_idx]				,A					)
					__A       =					self.args.strategy
					if strategy is None:
									raise ValueError("A device strategy has to be initialized before using TensorFlow."					)

					__A       =					self._prepare_train_func(A				,A				,A					)
					return self._measure_memory(_train					)






	def 							UpperCamelCase_    (			self   :					Tuple				,A   :					str				,A   :					int				,A   :					int					):
					__A       =					self.config_dict[model_name]

					if self.args.fpaa:
									raise NotImplementedError("Mixed precision is currently not supported."					)

					__A       =					(
					    hasattr(A				,"architectures"					)
					    and isinstance(config.architectures				,A					)
					    and len(config.architectures					) > 0
					)
					if not self.args.only_pretrain_model and has_model_class_in_config:
									try:
													__A       =					"TF" + config.architectures[0]  # prepend 'TF' for tensorflow model
													__A       =					__import__("transformers"				,fromlist=[model_class]					)
													__A       =					getattr(A				,A					)
													__A       =					model_cls(A					)
									except ImportError:
													raise ImportError(
													    f'''{model_class} does not exist. If you just want to test the pretrained model, you might want to'''
													    " set `--only_pretrain_model` or `args.only_pretrain_model=True`."					)
					else:
									__A       =					TF_MODEL_MAPPING[config.__class__](A					)

					# encoder-decoder has vocab size saved differently
					__A       =					config.vocab_size if hasattr(A				,"vocab_size"					) else config.encoder.vocab_size
					__A       =					random_input_ids(A				,A				,A					)

					@run_with_tf_optimizations(self.args.eager_mode				,self.args.use_xla					)
					def encoder_decoder_forward():
									return model(A				,decoder_input_ids=A				,training=A					)

					@run_with_tf_optimizations(self.args.eager_mode				,self.args.use_xla					)
					def encoder_forward():
									return model(A				,training=A					)

					__A       =					encoder_decoder_forward if config.is_encoder_decoder else encoder_forward

					return _inference






	def 							UpperCamelCase_    (			self   :					Optional[int]				,A   :					str				,A   :					int				,A   :					int					):
					__A       =					self.config_dict[model_name]

					if self.args.eager_mode is not False:
									raise ValueError("Training cannot be done in eager mode. Please make sure that `args.eager_mode = False`."					)

					if self.args.fpaa:
									raise NotImplementedError("Mixed precision is currently not supported."					)

					__A       =					(
					    hasattr(A				,"architectures"					)
					    and isinstance(config.architectures				,A					)
					    and len(config.architectures					) > 0
					)
					if not self.args.only_pretrain_model and has_model_class_in_config:
									try:
													__A       =					"TF" + config.architectures[0]  # prepend 'TF' for tensorflow model
													__A       =					__import__("transformers"				,fromlist=[model_class]					)
													__A       =					getattr(A				,A					)
													__A       =					model_cls(A					)
									except ImportError:
													raise ImportError(
													    f'''{model_class} does not exist. If you just want to test the pretrained model, you might want to'''
													    " set `--only_pretrain_model` or `args.only_pretrain_model=True`."					)
					else:
									__A       =					TF_MODEL_WITH_LM_HEAD_MAPPING[config.__class__](A					)

					# encoder-decoder has vocab size saved differently
					__A       =					config.vocab_size if hasattr(A				,"vocab_size"					) else config.encoder.vocab_size
					__A       =					random_input_ids(A				,A				,A					)

					@run_with_tf_optimizations(self.args.eager_mode				,self.args.use_xla					)
					def encoder_decoder_train():
									__A       =					model(A				,decoder_input_ids=A				,labels=A				,training=A					)[0]
									__A       =					tf.gradients(A				,model.trainable_variables					)
									return gradients

					@run_with_tf_optimizations(self.args.eager_mode				,self.args.use_xla					)
					def encoder_train():
									__A       =					model(A				,labels=A				,training=A					)[0]
									__A       =					tf.gradients(A				,model.trainable_variables					)
									return gradients

					__A       =					encoder_decoder_train if config.is_encoder_decoder else encoder_train

					return _train






	def 							UpperCamelCase_    (			self   :					str				,A   :					List[Any]					):
					with self.args.strategy.scope():
									try:
													if self.args.is_tpu or self.args.use_xla:
																	# run additional 10 times to stabilize compilation for tpu
																	logger.info("Do inference on TPU. Running model 5 times to stabilize compilation"					)
																	timeit.repeat(A				,repeat=1				,number=5					)

													# as written in https://docs.python.org/2/library/timeit.html#timeit.Timer.repeat, min should be taken rather than the average
													__A       =					timeit.repeat(
													    A				,repeat=self.args.repeat				,number=10				,)

													return min(A					) / 10.0
									except ResourceExhaustedError as e:
													self.print_fn(f'''Doesn\'t fit on GPU. {e}'''					)







	def 							UpperCamelCase_    (			self   :					Optional[Any]				,A   :					Callable[[], None]					):
					logger.info(
					    "Note that TensorFlow allocates more memory than "
					    "it might need to speed up computation. "
					    "The memory reported here corresponds to the memory "
					    "reported by `nvidia-smi`, which can vary depending "
					    "on total available memory on the GPU that is used."					)
					with self.args.strategy.scope():
									try:
													if self.args.trace_memory_line_by_line:
																	if not self.args.eager_mode:
																					raise ValueError(
																					    "`args.eager_mode` is set to `False`. Make sure to run model in eager mode to measure memory"
																					    " consumption line by line."					)
																	__A       =					start_memory_tracing("transformers"					)

													if self.args.is_tpu:
																	# tpu
																	raise NotImplementedError(
																	    "Memory Benchmarking is currently not implemented for TPU. Please disable memory benchmarking"
																	    " with `args.memory=False`"					)
													elif self.args.is_gpu:
																	# gpu
																	if not is_pyanvml_available():
																					logger.warning(
																					    "py3nvml not installed, we won't log GPU memory usage. "
																					    "Install py3nvml (pip install py3nvml) to log information about GPU."					)
																					__A       =					"N/A"
																	else:
																					logger.info(
																					    "Measuring total GPU usage on GPU device. Make sure to not have additional processes"
																					    " running on the same GPU."					)
																					# init nvml
																					nvml.nvmlInit()
																					func()
																					__A       =					nvml.nvmlDeviceGetHandleByIndex(self.args.device_idx					)
																					__A       =					nvml.nvmlDeviceGetMemoryInfo(A					)
																					__A       =					meminfo.used
																					__A       =					Memory(A					)
																					# shutdown nvml
																					nvml.nvmlShutdown()
													else:
																	# cpu
																	if self.args.trace_memory_line_by_line:
																					logger.info(
																					    "When enabling line by line tracing, the max peak memory for CPU is inaccurate in"
																					    " TensorFlow."					)
																					__A       =					None
																	else:
																					__A       =					measure_peak_memory_cpu(A					)
																					__A       =					Memory(A					) if isinstance(A				,A					) else memory_bytes
													if self.args.trace_memory_line_by_line:
																	__A       =					stop_memory_tracing(A					)
																	if memory is None:
																					__A       =					summary.total
													else:
																	__A       =					None

													return memory, summary
									except ResourceExhaustedError as e:
													self.print_fn(f'''Doesn\'t fit on GPU. {e}'''					)
													return "N/A", None




'''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        lowerCAmelCase_  (     unittest.TestCase	):






       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			,     )->      Tuple:
            # by setting size["longest_edge"] > max_resolution we're effectively not testing this :p
            _A				=							size if size is not None else {'shortest_edge': 18, 'longest_edge': 1333}
            _A				=							parent
            _A				=							batch_size
            _A				=							num_channels
            _A				=							min_resolution
            _A				=							max_resolution
            _A				=							do_resize
            _A				=							size
            _A				=							do_normalize
            _A				=							image_mean
            _A				=							image_std
            _A				=							do_rescale
            _A				=							rescale_factor
            _A				=							do_pad






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

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

            return expected_height, expected_width






@require_torch
@require_vision
class        lowerCAmelCase_  (     UpperCAmelCase      ,							unittest.TestCase	):
       __UpperCAmelCase					=DeformableDetrImageProcessor if is_vision_available() else None






       def   UpperCamelCase						( self   )->      Optional[int]:
            _A				=							DeformableDetrImageProcessingTester(self   )






       @property
       def   UpperCamelCase						( self   )->      Optional[Any]:
            return self.image_processor_tester.prepare_image_processor_dict()






       def   UpperCamelCase						( self   )->      List[str]:
            _A				=							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			,     'do_rescale'   )   )
            self.assertTrue(hasattr(_UpperCamelCase			,     'do_pad'   )   )
            self.assertTrue(hasattr(_UpperCamelCase			,     'size'   )   )






       def   UpperCamelCase						( self   )->      Any:
            _A				=							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   )

            _A				=							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   UpperCamelCase						( self   )->      Optional[Any]:
            pass






       def   UpperCamelCase						( self   )->      Optional[Any]:
            # Initialize image_processing
            _A				=							self.image_processing_class(**self.image_processor_dict   )
            # create random PIL images
            _A				=							prepare_image_inputs(self.image_processor_tester			,     equal_resolution=_UpperCamelCase   )
            for image in image_inputs:
                 self.assertIsInstance(_UpperCamelCase			,     Image.Image   )

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

            _A		,				_A				=							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
            _A		,				_A				=							self.image_processor_tester.get_expected_values(_UpperCamelCase			,     batched=_UpperCamelCase   )

            _A				=							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   UpperCamelCase						( self   )->      List[str]:
            # Initialize image_processing
            _A				=							self.image_processing_class(**self.image_processor_dict   )
            # create random numpy tensors
            _A				=							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
            _A				=							image_processing(image_inputs[0]			,     return_tensors='pt'   ).pixel_values

            _A		,				_A				=							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
            _A				=							image_processing(_UpperCamelCase			,     return_tensors='pt'   ).pixel_values

            _A		,				_A				=							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   UpperCamelCase						( self   )->      Dict:
            # Initialize image_processing
            _A				=							self.image_processing_class(**self.image_processor_dict   )
            # create random PyTorch tensors
            _A				=							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
            _A				=							image_processing(image_inputs[0]			,     return_tensors='pt'   ).pixel_values

            _A		,				_A				=							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
            _A				=							image_processing(_UpperCamelCase			,     return_tensors='pt'   ).pixel_values

            _A		,				_A				=							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,
                )			,     )






       @slow
       def   UpperCamelCase						( self   )->      List[Any]:
            # prepare image and target
            _A				=							Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'   )
            with open('./tests/fixtures/tests_samples/COCO/coco_annotations.txt'			,     'r'   ) as f:
                 _A				=							json.loads(f.read()   )

            _A				=							{'image_id': 3_9769, 'annotations': target}

            # encode them
            _A				=							DeformableDetrImageProcessor()
            _A				=							image_processing(images=_UpperCamelCase			,     annotations=_UpperCamelCase			,     return_tensors='pt'   )

            # verify pixel values
            _A				=							torch.Size([1, 3, 800, 1066]   )
            self.assertEqual(encoding['pixel_values'].shape			,     _UpperCamelCase   )

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

            # verify area
            _A				=							torch.tensor([5887.9600, 1_1250.2061, 48_9353.8438, 83_7122.7500, 14_7967.5156, 16_5732.3438]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['area']			,     _UpperCamelCase   )   )
            # verify boxes
            _A				=							torch.Size([6, 4]   )
            self.assertEqual(encoding['labels'][0]['boxes'].shape			,     _UpperCamelCase   )
            _A				=							torch.tensor([0.5503, 0.2765, 0.0604, 0.2215]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]			,     _UpperCamelCase			,     atol=1e-3   )   )
            # verify image_id
            _A				=							torch.tensor([3_9769]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']			,     _UpperCamelCase   )   )
            # verify is_crowd
            _A				=							torch.tensor([0, 0, 0, 0, 0, 0]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']			,     _UpperCamelCase   )   )
            # verify class_labels
            _A				=							torch.tensor([75, 75, 63, 65, 17, 17]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']			,     _UpperCamelCase   )   )
            # verify orig_size
            _A				=							torch.tensor([480, 640]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']			,     _UpperCamelCase   )   )
            # verify size
            _A				=							torch.tensor([800, 1066]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['size']			,     _UpperCamelCase   )   )






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

            _A				=							{'file_name': '000000039769.png', 'image_id': 3_9769, 'segments_info': target}

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

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

            # verify pixel values
            _A				=							torch.Size([1, 3, 800, 1066]   )
            self.assertEqual(encoding['pixel_values'].shape			,     _UpperCamelCase   )

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

            # verify area
            _A				=							torch.tensor([14_7979.6875, 16_5527.0469, 48_4638.5938, 1_1292.9375, 5879.6562, 7634.1147]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['area']			,     _UpperCamelCase   )   )
            # verify boxes
            _A				=							torch.Size([6, 4]   )
            self.assertEqual(encoding['labels'][0]['boxes'].shape			,     _UpperCamelCase   )
            _A				=							torch.tensor([0.2625, 0.5437, 0.4688, 0.8625]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]			,     _UpperCamelCase			,     atol=1e-3   )   )
            # verify image_id
            _A				=							torch.tensor([3_9769]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']			,     _UpperCamelCase   )   )
            # verify is_crowd
            _A				=							torch.tensor([0, 0, 0, 0, 0, 0]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']			,     _UpperCamelCase   )   )
            # verify class_labels
            _A				=							torch.tensor([17, 17, 63, 75, 75, 93]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']			,     _UpperCamelCase   )   )
            # verify masks
            _A				=							82_2873
            self.assertEqual(encoding['labels'][0]['masks'].sum().item()			,     _UpperCamelCase   )
            # verify orig_size
            _A				=							torch.tensor([480, 640]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']			,     _UpperCamelCase   )   )
            # verify size
            _A				=							torch.tensor([800, 1066]   )
            self.assertTrue(torch.allclose(encoding['labels'][0]['size']			,     _UpperCamelCase   )   )





