

from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
							import tensorflow as tf

							from transformers import (
							    TFConvBertForMaskedLM,
							    TFConvBertForMultipleChoice,
							    TFConvBertForQuestionAnswering,
							    TFConvBertForSequenceClassification,
							    TFConvBertForTokenClassification,
							    TFConvBertModel,
							)







class 				lowercase       :




				def __init__(      self   ,     snake_case   ,     snake_case=13   ,     snake_case=7   ,     snake_case=True   ,     snake_case=True   ,     snake_case=True   ,     snake_case=True   ,     snake_case=99   ,     snake_case=32   ,     snake_case=2   ,     snake_case=4   ,     snake_case=37   ,     snake_case="gelu"   ,     snake_case=0.1   ,     snake_case=0.1   ,     snake_case=512   ,     snake_case=16   ,     snake_case=2   ,     snake_case=0.02   ,     snake_case=3   ,     snake_case=4   ,     snake_case=None   ,     ):
											snake_case_           =					parent
											snake_case_           =					13
											snake_case_           =					7
											snake_case_           =					True
											snake_case_           =					True
											snake_case_           =					True
											snake_case_           =					True
											snake_case_           =					99
											snake_case_           =					384
											snake_case_           =					2
											snake_case_           =					4
											snake_case_           =					37
											snake_case_           =					'''gelu'''
											snake_case_           =					0.1
											snake_case_           =					0.1
											snake_case_           =					512
											snake_case_           =					16
											snake_case_           =					2
											snake_case_           =					0.02
											snake_case_           =					3
											snake_case_           =					4
											snake_case_           =					128
											snake_case_           =					2
											snake_case_           =					9
											snake_case_           =					1
											snake_case_           =					None




				def 					a							(      self ):
											snake_case_           =					ids_tensor([self.batch_size, self.seq_length]   ,     self.vocab_size )

											snake_case_           =					None
											if self.use_input_mask:
																		snake_case_           =					random_attention_mask([self.batch_size, self.seq_length] )

											snake_case_           =					None
											if self.use_token_type_ids:
																		snake_case_           =					ids_tensor([self.batch_size, self.seq_length]   ,     self.type_vocab_size )

											snake_case_           =					None
											snake_case_           =					None
											snake_case_           =					None
											if self.use_labels:
																		snake_case_           =					ids_tensor([self.batch_size]   ,     self.type_sequence_label_size )
																		snake_case_           =					ids_tensor([self.batch_size, self.seq_length]   ,     self.num_labels )
																		snake_case_           =					ids_tensor([self.batch_size]   ,     self.num_choices )

											snake_case_           =					ConvBertConfig(
											    vocab_size=self.vocab_size   ,     hidden_size=self.hidden_size   ,     num_hidden_layers=self.num_hidden_layers   ,     num_attention_heads=self.num_attention_heads   ,     intermediate_size=self.intermediate_size   ,     hidden_act=self.hidden_act   ,     hidden_dropout_prob=self.hidden_dropout_prob   ,     attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,     max_position_embeddings=self.max_position_embeddings   ,     type_vocab_size=self.type_vocab_size   ,     initializer_range=self.initializer_range   ,     return_dict=__lowerCamelCase   ,     )

											return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels




				def 					a							(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case ):
											snake_case_           =					TFConvBertModel(config=__lowerCamelCase )
											snake_case_           =					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

											snake_case_           =					[input_ids, input_mask]
											snake_case_           =					model(__lowerCamelCase )

											snake_case_           =					model(__lowerCamelCase )

											self.parent.assertEqual(result.last_hidden_state.shape   ,     (self.batch_size, self.seq_length, self.hidden_size) )




				def 					a							(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case ):
											snake_case_           =					TFConvBertForMaskedLM(config=__lowerCamelCase )
											snake_case_           =					{
											    '''input_ids''': input_ids,
											    '''attention_mask''': input_mask,
											    '''token_type_ids''': token_type_ids,
											}
											snake_case_           =					model(__lowerCamelCase )
											self.parent.assertEqual(result.logits.shape   ,     (self.batch_size, self.seq_length, self.vocab_size) )




				def 					a							(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case ):
											snake_case_           =					self.num_labels
											snake_case_           =					TFConvBertForSequenceClassification(config=__lowerCamelCase )
											snake_case_           =					{
											    '''input_ids''': input_ids,
											    '''attention_mask''': input_mask,
											    '''token_type_ids''': token_type_ids,
											}

											snake_case_           =					model(__lowerCamelCase )
											self.parent.assertEqual(result.logits.shape   ,     (self.batch_size, self.num_labels) )




				def 					a							(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case ):
											snake_case_           =					self.num_choices
											snake_case_           =					TFConvBertForMultipleChoice(config=__lowerCamelCase )
											snake_case_           =					tf.tile(tf.expand_dims(__lowerCamelCase   ,     1 )   ,     (1, self.num_choices, 1) )
											snake_case_           =					tf.tile(tf.expand_dims(__lowerCamelCase   ,     1 )   ,     (1, self.num_choices, 1) )
											snake_case_           =					tf.tile(tf.expand_dims(__lowerCamelCase   ,     1 )   ,     (1, self.num_choices, 1) )
											snake_case_           =					{
											    '''input_ids''': multiple_choice_inputs_ids,
											    '''attention_mask''': multiple_choice_input_mask,
											    '''token_type_ids''': multiple_choice_token_type_ids,
											}
											snake_case_           =					model(__lowerCamelCase )
											self.parent.assertEqual(result.logits.shape   ,     (self.batch_size, self.num_choices) )




				def 					a							(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case ):
											snake_case_           =					self.num_labels
											snake_case_           =					TFConvBertForTokenClassification(config=__lowerCamelCase )
											snake_case_           =					{
											    '''input_ids''': input_ids,
											    '''attention_mask''': input_mask,
											    '''token_type_ids''': token_type_ids,
											}
											snake_case_           =					model(__lowerCamelCase )
											self.parent.assertEqual(result.logits.shape   ,     (self.batch_size, self.seq_length, self.num_labels) )




				def 					a							(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case ):
											snake_case_           =					TFConvBertForQuestionAnswering(config=__lowerCamelCase )
											snake_case_           =					{
											    '''input_ids''': input_ids,
											    '''attention_mask''': input_mask,
											    '''token_type_ids''': token_type_ids,
											}

											snake_case_           =					model(__lowerCamelCase )
											self.parent.assertEqual(result.start_logits.shape   ,     (self.batch_size, self.seq_length) )
											self.parent.assertEqual(result.end_logits.shape   ,     (self.batch_size, self.seq_length) )




				def 					a							(      self ):
											snake_case_           =					self.prepare_config_and_inputs()
											(
											    snake_case_	
											)           =					config_and_inputs
											snake_case_           =					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
											return config, inputs_dict







@require_tf
class 				lowercase       ( lowerCamelCase__			,						lowerCamelCase__			,						unittest.TestCase    ):
				__SCREAMING_SNAKE_CASE      :				List[str]     =    (
				    (
				        TFConvBertModel,
				        TFConvBertForMaskedLM,
				        TFConvBertForQuestionAnswering,
				        TFConvBertForSequenceClassification,
				        TFConvBertForTokenClassification,
				        TFConvBertForMultipleChoice,
				    )
				    if is_tf_available()
				    else ()
				)
				__SCREAMING_SNAKE_CASE      :				Any     =    (
				    {
				        '''feature-extraction''': TFConvBertModel,
				        '''fill-mask''': TFConvBertForMaskedLM,
				        '''question-answering''': TFConvBertForQuestionAnswering,
				        '''text-classification''': TFConvBertForSequenceClassification,
				        '''token-classification''': TFConvBertForTokenClassification,
				        '''zero-shot''': TFConvBertForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				__SCREAMING_SNAKE_CASE      :				int     =    False
				__SCREAMING_SNAKE_CASE      :				List[Any]     =    False
				__SCREAMING_SNAKE_CASE      :				Dict     =    False




				def 					a							(      self ):
											snake_case_           =					TFConvBertModelTester(self )
											snake_case_           =					ConfigTester(self   ,     config_class=__lowerCamelCase   ,     hidden_size=37 )




				def 					a							(      self ):
											self.config_tester.run_common_tests()




				def 					a							(      self ):
											snake_case_           =					self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__lowerCamelCase )




				def 					a							(      self ):
											snake_case_           =					self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*__lowerCamelCase )




				def 					a							(      self ):
											snake_case_           =					self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_multiple_choice(*__lowerCamelCase )




				def 					a							(      self ):
											snake_case_           =					self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*__lowerCamelCase )




				def 					a							(      self ):
											snake_case_           =					self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*__lowerCamelCase )




				def 					a							(      self ):
											snake_case_           =					self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*__lowerCamelCase )




				@slow
				def 					a							(      self ):
											snake_case_           =					self.model_tester.prepare_config_and_inputs_for_common()
											snake_case_           =					True
											snake_case_           =					True

											if hasattr(__lowerCamelCase   ,     'use_cache' ):
																		snake_case_           =					True

											snake_case_           =					getattr(self.model_tester   ,     'encoder_seq_length'   ,     self.model_tester.seq_length )
											snake_case_           =					getattr(self.model_tester   ,     'key_length'   ,     __lowerCamelCase )

											for model_class in self.all_model_classes:
																		snake_case_           =					self._prepare_for_class(__lowerCamelCase   ,     __lowerCamelCase )
																		snake_case_           =					model_class(__lowerCamelCase )
																		snake_case_           =					len(model(__lowerCamelCase ) )

																		with tempfile.TemporaryDirectory() as tmpdirname:
																									model.save_pretrained(__lowerCamelCase   ,     saved_model=__lowerCamelCase )
																									snake_case_           =					os.path.join(__lowerCamelCase   ,     'saved_model'   ,     '1' )
																									snake_case_           =					tf.keras.models.load_model(__lowerCamelCase )
																									snake_case_           =					model(__lowerCamelCase )

																									if self.is_encoder_decoder:
																																snake_case_           =					outputs['''encoder_hidden_states''']
																																snake_case_           =					outputs['''encoder_attentions''']
																									else:
																																snake_case_           =					outputs['''hidden_states''']
																																snake_case_           =					outputs['''attentions''']

																									self.assertEqual(len(__lowerCamelCase )   ,     __lowerCamelCase )

																									snake_case_           =					getattr(
																									    self.model_tester   ,     'expected_num_hidden_layers'   ,     self.model_tester.num_hidden_layers + 1 )

																									self.assertEqual(len(__lowerCamelCase )   ,     __lowerCamelCase )
																									self.assertListEqual(
																									    list(output_hidden_states[0].shape[-2:] )   ,     [self.model_tester.seq_length, self.model_tester.hidden_size]   ,     )

																									self.assertEqual(len(__lowerCamelCase )   ,     self.model_tester.num_hidden_layers )
																									self.assertListEqual(
																									    list(output_attentions[0].shape[-3:] )   ,     [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]   ,     )




				@slow
				def 					a							(      self ):
											snake_case_           =					TFConvBertModel.from_pretrained('YituTech/conv-bert-base' )
											self.assertIsNotNone(__lowerCamelCase )




				def 					a							(      self ):
											snake_case_           =					self.model_tester.prepare_config_and_inputs_for_common()
											snake_case_           =					True
											snake_case_           =					getattr(self.model_tester   ,     'decoder_seq_length'   ,     self.model_tester.seq_length )
											snake_case_           =					getattr(self.model_tester   ,     'encoder_seq_length'   ,     self.model_tester.seq_length )
											snake_case_           =					getattr(self.model_tester   ,     'key_length'   ,     __lowerCamelCase )
											snake_case_           =					getattr(self.model_tester   ,     'key_length'   ,     __lowerCamelCase )

											def check_decoder_attentions_output(snake_case ):
																		snake_case_           =					len(__lowerCamelCase )
																		self.assertEqual(out_len % 2   ,     0 )
																		snake_case_           =					outputs.decoder_attentions
																		self.assertEqual(len(__lowerCamelCase )   ,     self.model_tester.num_hidden_layers )
																		self.assertListEqual(
																		    list(decoder_attentions[0].shape[-3:] )   ,     [self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]   ,     )

											def check_encoder_attentions_output(snake_case ):
																		snake_case_           =					[
																		    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
																		]
																		self.assertEqual(len(__lowerCamelCase )   ,     self.model_tester.num_hidden_layers )
																		self.assertListEqual(
																		    list(attentions[0].shape[-3:] )   ,     [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]   ,     )

											for model_class in self.all_model_classes:
																		snake_case_           =					True
																		snake_case_           =					False
																		snake_case_           =					model_class(__lowerCamelCase )
																		snake_case_           =					model(self._prepare_for_class(__lowerCamelCase   ,     __lowerCamelCase ) )
																		snake_case_           =					len(__lowerCamelCase )
																		self.assertEqual(config.output_hidden_states   ,     __lowerCamelCase )
																		check_encoder_attentions_output(__lowerCamelCase )

																		if self.is_encoder_decoder:
																									snake_case_           =					model_class(__lowerCamelCase )
																									snake_case_           =					model(self._prepare_for_class(__lowerCamelCase   ,     __lowerCamelCase ) )
																									self.assertEqual(config.output_hidden_states   ,     __lowerCamelCase )
																									check_decoder_attentions_output(__lowerCamelCase )

																		# Check that output attentions can also be changed via the config
																		del inputs_dict["output_attentions"]
																		snake_case_           =					True
																		snake_case_           =					model_class(__lowerCamelCase )
																		snake_case_           =					model(self._prepare_for_class(__lowerCamelCase   ,     __lowerCamelCase ) )
																		self.assertEqual(config.output_hidden_states   ,     __lowerCamelCase )
																		check_encoder_attentions_output(__lowerCamelCase )

																		# Check attention is always last and order is fine
																		snake_case_           =					True
																		snake_case_           =					True
																		snake_case_           =					model_class(__lowerCamelCase )
																		snake_case_           =					model(self._prepare_for_class(__lowerCamelCase   ,     __lowerCamelCase ) )

																		self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)   ,     len(__lowerCamelCase ) )
																		self.assertEqual(model.config.output_hidden_states   ,     __lowerCamelCase )
																		check_encoder_attentions_output(__lowerCamelCase )







@require_tf
class 				lowercase       ( unittest.TestCase    ):




				@slow
				def 					a							(      self ):
											snake_case_           =					TFConvBertModel.from_pretrained('YituTech/conv-bert-base' )
											snake_case_           =					tf.constant([[0, 1, 2, 3, 4, 5]] )
											snake_case_           =					model(__lowerCamelCase )[0]

											snake_case_           =					[1, 6, 768]
											self.assertEqual(output.shape   ,     __lowerCamelCase )

											snake_case_           =					tf.constant(
											    [
											        [
											            [-0.03_47_54_93, -0.4_68_60_34, -0.30_63_88_32],
											            [0.22_63_72_48, -0.26_98_86_46, -0.7_42_34_24],
											            [0.10_32_48_68, -0.45_01_35_08, -0.58_28_07_84],
											        ]
											    ] )
											tf.debugging.assert_near(output[:, :3, :3]   ,     __lowerCamelCase   ,     atol=1e-4 )







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 DetrImageProcessor







class 				lowercase       ( unittest.TestCase    ):




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




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




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

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

											return expected_height, expected_width







@require_torch
@require_vision
class 				lowercase       ( lowercase_			,						unittest.TestCase    ):
				__SCREAMING_SNAKE_CASE      :				str     =    DetrImageProcessor if is_vision_available() else None




				def 					a							(      self ):
											snake_case_           =					DetrImageProcessingTester(self )




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




				def 					a							(      self ):
											snake_case_           =					self.image_processing_class(**self.image_processor_dict )
											self.assertTrue(hasattr(snake_case   ,     'image_mean' ) )
											self.assertTrue(hasattr(snake_case   ,     'image_std' ) )
											self.assertTrue(hasattr(snake_case   ,     'do_normalize' ) )
											self.assertTrue(hasattr(snake_case   ,     'do_rescale' ) )
											self.assertTrue(hasattr(snake_case   ,     'rescale_factor' ) )
											self.assertTrue(hasattr(snake_case   ,     'do_resize' ) )
											self.assertTrue(hasattr(snake_case   ,     'size' ) )
											self.assertTrue(hasattr(snake_case   ,     'do_pad' ) )




				def 					a							(      self ):
											snake_case_           =					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   ,     snake_case )

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




				def 					a							(      self ):
											pass




				def 					a							(      self ):
											# Initialize image_processing
											snake_case_           =					self.image_processing_class(**self.image_processor_dict )
											# create random PIL images
											snake_case_           =					prepare_image_inputs(self.image_processor_tester   ,     equal_resolution=snake_case )
											for image in image_inputs:
																		self.assertIsInstance(snake_case   ,     Image.Image )

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

											snake_case_       ,					snake_case_           =					self.image_processor_tester.get_expected_values(snake_case )

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

											# Test batched
											snake_case_       ,					snake_case_           =					self.image_processor_tester.get_expected_values(snake_case   ,     batched=snake_case )

											snake_case_           =					image_processing(snake_case   ,     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 					a							(      self ):
											# Initialize image_processing
											snake_case_           =					self.image_processing_class(**self.image_processor_dict )
											# create random numpy tensors
											snake_case_           =					prepare_image_inputs(self.image_processor_tester   ,     equal_resolution=snake_case   ,     numpify=snake_case )
											for image in image_inputs:
																		self.assertIsInstance(snake_case   ,     np.ndarray )

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

											snake_case_       ,					snake_case_           =					self.image_processor_tester.get_expected_values(snake_case )

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

											# Test batched
											snake_case_           =					image_processing(snake_case   ,     return_tensors='pt' ).pixel_values

											snake_case_       ,					snake_case_           =					self.image_processor_tester.get_expected_values(snake_case   ,     batched=snake_case )

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




				def 					a							(      self ):
											# Initialize image_processing
											snake_case_           =					self.image_processing_class(**self.image_processor_dict )
											# create random PyTorch tensors
											snake_case_           =					prepare_image_inputs(self.image_processor_tester   ,     equal_resolution=snake_case   ,     torchify=snake_case )
											for image in image_inputs:
																		self.assertIsInstance(snake_case   ,     torch.Tensor )

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

											snake_case_       ,					snake_case_           =					self.image_processor_tester.get_expected_values(snake_case )

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

											# Test batched
											snake_case_           =					image_processing(snake_case   ,     return_tensors='pt' ).pixel_values

											snake_case_       ,					snake_case_           =					self.image_processor_tester.get_expected_values(snake_case   ,     batched=snake_case )

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




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

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

											# encode them
											snake_case_           =					DetrImageProcessor.from_pretrained('facebook/detr-resnet-50' )
											snake_case_           =					image_processing(images=snake_case   ,     annotations=snake_case   ,     return_tensors='pt' )

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

											snake_case_           =					torch.tensor([0.27_96, 0.31_38, 0.34_81] )
											self.assertTrue(torch.allclose(encoding['pixel_values'][0, 0, 0, :3]   ,     snake_case   ,     atol=1e-4 ) )

											# verify area
											snake_case_           =					torch.tensor([58_87.96_00, 1_12_50.20_61, 48_93_53.84_38, 83_71_22.75_00, 14_79_67.51_56, 16_57_32.34_38] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['area']   ,     snake_case ) )
											# verify boxes
											snake_case_           =					torch.Size([6, 4] )
											self.assertEqual(encoding['labels'][0]['boxes'].shape   ,     snake_case )
											snake_case_           =					torch.tensor([0.55_03, 0.27_65, 0.06_04, 0.22_15] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]   ,     snake_case   ,     atol=1e-3 ) )
											# verify image_id
											snake_case_           =					torch.tensor([3_9769] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']   ,     snake_case ) )
											# verify is_crowd
											snake_case_           =					torch.tensor([0, 0, 0, 0, 0, 0] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']   ,     snake_case ) )
											# verify class_labels
											snake_case_           =					torch.tensor([75, 75, 63, 65, 17, 17] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']   ,     snake_case ) )
											# verify orig_size
											snake_case_           =					torch.tensor([480, 640] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']   ,     snake_case ) )
											# verify size
											snake_case_           =					torch.tensor([800, 1066] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['size']   ,     snake_case ) )




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

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

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

											# encode them
											snake_case_           =					DetrImageProcessor.from_pretrained('facebook/detr-resnet-50-panoptic' )
											snake_case_           =					image_processing(images=snake_case   ,     annotations=snake_case   ,     masks_path=snake_case   ,     return_tensors='pt' )

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

											snake_case_           =					torch.tensor([0.27_96, 0.31_38, 0.34_81] )
											self.assertTrue(torch.allclose(encoding['pixel_values'][0, 0, 0, :3]   ,     snake_case   ,     atol=1e-4 ) )

											# verify area
											snake_case_           =					torch.tensor([14_79_79.68_75, 16_55_27.04_69, 48_46_38.59_38, 1_12_92.93_75, 58_79.65_62, 76_34.11_47] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['area']   ,     snake_case ) )
											# verify boxes
											snake_case_           =					torch.Size([6, 4] )
											self.assertEqual(encoding['labels'][0]['boxes'].shape   ,     snake_case )
											snake_case_           =					torch.tensor([0.26_25, 0.54_37, 0.46_88, 0.86_25] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]   ,     snake_case   ,     atol=1e-3 ) )
											# verify image_id
											snake_case_           =					torch.tensor([3_9769] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']   ,     snake_case ) )
											# verify is_crowd
											snake_case_           =					torch.tensor([0, 0, 0, 0, 0, 0] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']   ,     snake_case ) )
											# verify class_labels
											snake_case_           =					torch.tensor([17, 17, 63, 75, 75, 93] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']   ,     snake_case ) )
											# verify masks
											snake_case_           =					82_2873
											self.assertEqual(encoding['labels'][0]['masks'].sum().item()   ,     snake_case )
											# verify orig_size
											snake_case_           =					torch.tensor([480, 640] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']   ,     snake_case ) )
											# verify size
											snake_case_           =					torch.tensor([800, 1066] )
											self.assertTrue(torch.allclose(encoding['labels'][0]['size']   ,     snake_case ) )




