



"""simple docstring"""






import collections
import types

import numpy as np

from ..utils import (
    add_end_docstrings,
    is_tensorflow_probability_available,
    is_tf_available,
    is_torch_available,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, ArgumentHandler, Dataset, Pipeline, PipelineException


if is_torch_available():
		import torch

		from ..models.auto.modeling_auto import (
		    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
		    MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
		)

if is_tf_available() and is_tensorflow_probability_available():
		import tensorflow as tf
		import tensorflow_probability as tfp

		from ..models.auto.modeling_tf_auto import (
		    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
		    TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
		)

class 			__SCREAMING_SNAKE_CASE      ( lowerCAmelCase_  ):


					'''simple docstring'''





					def __call__(			self				:    Tuple,    lowerCamelCase				:    Tuple=None,    lowerCamelCase				:    Union[str, Any]=None,    **lowerCamelCase				:    Optional[Any]	)->   Union[str, Any]:
								# Returns tqa_pipeline_inputs of shape:
								# [
								#   {"table": pd.DataFrame, "query": List[str]},
								#   ...,
								#   {"table": pd.DataFrame, "query" : List[str]}
								# ]
								requires_backends(self,    '''pandas'''	)
								import pandas as pd

								if table is None:
											raise ValueError('''Keyword argument `table` cannot be None.'''	)
								elif query is None:
											if isinstance(lowerCamelCase,    lowerCamelCase	) and table.get('''query'''	) is not None and table.get('''table'''	) is not None:
														lowerCamelCase__						:						Any						      =[table]
											elif isinstance(lowerCamelCase,    lowerCamelCase	) and len(lowerCamelCase	) > 0:
														if not all(isinstance(lowerCamelCase,    lowerCamelCase	) for d in table	):
																	raise ValueError(
																	    F'''Keyword argument `table` should be a list of dict, but is {(type(lowerCamelCase	) for d in table)}'''	)

														if table[0].get('''query'''	) is not None and table[0].get('''table'''	) is not None:
																	lowerCamelCase__						:						List[str]						      =table
														else:
																	raise ValueError(
																	    '''If keyword argument `table` is a list of dictionaries, each dictionary should have a `table`'''
																	    F''' and `query` key, but only dictionary has keys {table[0].keys()} `table` and `query` keys.'''	)
											elif Dataset is not None and isinstance(lowerCamelCase,    lowerCamelCase	) or isinstance(lowerCamelCase,    types.GeneratorType	):
														return table
											else:
														raise ValueError(
														    '''Invalid input. Keyword argument `table` should be either of type `dict` or `list`, but '''
														    F'''is {type(lowerCamelCase	)})'''	)
								else:
											lowerCamelCase__						:						Any						      =[{'''table''': table, '''query''': query}]

								for tqa_pipeline_input in tqa_pipeline_inputs:
											if not isinstance(tqa_pipeline_input['''table'''],    pd.DataFrame	):
														if tqa_pipeline_input["table"] is None:
																	raise ValueError('''Table cannot be None.'''	)

														lowerCamelCase__						:						int						      =pd.DataFrame(tqa_pipeline_input['''table''']	)

								return tqa_pipeline_inputs





@add_end_docstrings(lowerCAmelCase_  )
class 			__SCREAMING_SNAKE_CASE      ( lowerCAmelCase_  ):


					'''simple docstring'''





					_a       =				'table,query'



					def __init__(			self				:    Optional[int],    lowerCamelCase				:    Dict=TableQuestionAnsweringArgumentHandler(),    *lowerCamelCase				:    int,    **lowerCamelCase				:    Tuple	)->   Dict:
								super().__init__(*lowerCamelCase,    **lowerCamelCase	)
								lowerCamelCase__						:						Optional[Any]						      =args_parser

								self.check_model_type(
								    dict(
								        TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items()
								        + TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()	)
								    if self.framework == '''tf'''
								    else dict(
								        MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items() + MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()	)	)

								lowerCamelCase__						:						Tuple						      =bool(getattr(self.model.config,    '''aggregation_labels''',    lowerCamelCase	)	) and bool(
								    getattr(self.model.config,    '''num_aggregation_labels''',    lowerCamelCase	)	)
								lowerCamelCase__						:						int						      ='''tapas''' if hasattr(self.model.config,    '''aggregation_labels'''	) else None



					def 						snake_case			(			self				:    List[str],    **lowerCamelCase				:    Optional[Any]	)->   Optional[Any]:
								return self.model(**lowerCamelCase	)



					def 						snake_case			(			self				:    Tuple,    **lowerCamelCase				:    List[Any]	)->   Dict:
								if self.framework == "pt":
											lowerCamelCase__						:						Optional[Any]						      =[]
											lowerCamelCase__						:						List[str]						      =[]
											lowerCamelCase__						:						Union[str, Any]						      =None
											lowerCamelCase__						:						Any						      =inputs['''input_ids'''].shape[0]

											lowerCamelCase__						:						int						      =inputs['''input_ids'''].to(self.device	)
											lowerCamelCase__						:						str						      =inputs['''attention_mask'''].to(self.device	)
											lowerCamelCase__						:						Union[str, Any]						      =inputs['''token_type_ids'''].to(self.device	)
											lowerCamelCase__						:						int						      =None

											for index in range(lowerCamelCase	):
														# If sequences have already been processed, the token type IDs will be created according to the previous
														# answer.
														if prev_answers is not None:
																	lowerCamelCase__						:						Union[str, Any]						      =token_type_ids_example[:, 3]  # shape (seq_len,)
																	lowerCamelCase__						:						List[Any]						      =np.zeros_like(prev_labels_example.cpu().numpy()	)  # shape (seq_len,)

																	lowerCamelCase__						:						List[str]						      =token_type_ids[index]  # shape (seq_len, 7)
																	for i in range(model_labels.shape[0]	):
																				lowerCamelCase__						:						List[Any]						      =token_type_ids_example[:, 0].tolist()[i]
																				lowerCamelCase__						:						int						      =token_type_ids_example[:, 1].tolist()[i] - 1
																				lowerCamelCase__						:						str						      =token_type_ids_example[:, 2].tolist()[i] - 1

																				if row_id >= 0 and col_id >= 0 and segment_id == 1:
																							lowerCamelCase__						:						Optional[int]						      =int(prev_answers[(col_id, row_id)]	)

																	lowerCamelCase__						:						Optional[Any]						      =torch.from_numpy(lowerCamelCase	).type(torch.long	).to(self.device	)

														lowerCamelCase__						:						Union[str, Any]						      =input_ids[index]
														lowerCamelCase__						:						str						      =attention_mask[index]  # shape (seq_len,)
														lowerCamelCase__						:						str						      =token_type_ids[index]  # shape (seq_len, 7)
														lowerCamelCase__						:						List[Any]						      =self.model(
														    input_ids=input_ids_example.unsqueeze(0	),    attention_mask=attention_mask_example.unsqueeze(0	),    token_type_ids=token_type_ids_example.unsqueeze(0	),    )
														lowerCamelCase__						:						List[str]						      =outputs.logits

														if self.aggregate:
																	all_aggregations.append(outputs.logits_aggregation	)

														all_logits.append(lowerCamelCase	)

														lowerCamelCase__						:						Any						      =torch.distributions.Bernoulli(logits=lowerCamelCase	)
														lowerCamelCase__						:						str						      =dist_per_token.probs * attention_mask_example.type(torch.floataa	).to(
														    dist_per_token.probs.device	)

														lowerCamelCase__						:						List[Any]						      =collections.defaultdict(lowerCamelCase	)
														for i, p in enumerate(probabilities.squeeze().tolist()	):
																	lowerCamelCase__						:						int						      =token_type_ids_example[:, 0].tolist()[i]
																	lowerCamelCase__						:						Any						      =token_type_ids_example[:, 1].tolist()[i] - 1
																	lowerCamelCase__						:						Tuple						      =token_type_ids_example[:, 2].tolist()[i] - 1
																	if col >= 0 and row >= 0 and segment_id == 1:
																				coords_to_probs[(col, row)].append(lowerCamelCase	)

														lowerCamelCase__						:						int						      ={key: np.array(coords_to_probs[key]	).mean() > 0.5 for key in coords_to_probs}

											lowerCamelCase__						:						List[str]						      =torch.cat(tuple(lowerCamelCase	),    0	)

											return (logits_batch,) if not self.aggregate else (logits_batch, torch.cat(tuple(lowerCamelCase	),    0	))
								else:
											lowerCamelCase__						:						Union[str, Any]						      =[]
											lowerCamelCase__						:						int						      =[]
											lowerCamelCase__						:						Tuple						      =None
											lowerCamelCase__						:						int						      =inputs['''input_ids'''].shape[0]

											lowerCamelCase__						:						List[str]						      =inputs['''input_ids''']
											lowerCamelCase__						:						Optional[int]						      =inputs['''attention_mask''']
											lowerCamelCase__						:						Any						      =inputs['''token_type_ids'''].numpy()
											lowerCamelCase__						:						Dict						      =None

											for index in range(lowerCamelCase	):
														# If sequences have already been processed, the token type IDs will be created according to the previous
														# answer.
														if prev_answers is not None:
																	lowerCamelCase__						:						Optional[int]						      =token_type_ids_example[:, 3]  # shape (seq_len,)
																	lowerCamelCase__						:						Optional[Any]						      =np.zeros_like(lowerCamelCase,    dtype=np.intaa	)  # shape (seq_len,)

																	lowerCamelCase__						:						List[Any]						      =token_type_ids[index]  # shape (seq_len, 7)
																	for i in range(model_labels.shape[0]	):
																				lowerCamelCase__						:						Any						      =token_type_ids_example[:, 0].tolist()[i]
																				lowerCamelCase__						:						Any						      =token_type_ids_example[:, 1].tolist()[i] - 1
																				lowerCamelCase__						:						Tuple						      =token_type_ids_example[:, 2].tolist()[i] - 1

																				if row_id >= 0 and col_id >= 0 and segment_id == 1:
																							lowerCamelCase__						:						Dict						      =int(prev_answers[(col_id, row_id)]	)

																	lowerCamelCase__						:						List[Any]						      =model_labels

														lowerCamelCase__						:						Any						      =input_ids[index]
														lowerCamelCase__						:						str						      =attention_mask[index]  # shape (seq_len,)
														lowerCamelCase__						:						Optional[Any]						      =token_type_ids[index]  # shape (seq_len, 7)
														lowerCamelCase__						:						List[Any]						      =self.model(
														    input_ids=np.expand_dims(lowerCamelCase,    axis=0	),    attention_mask=np.expand_dims(lowerCamelCase,    axis=0	),    token_type_ids=np.expand_dims(lowerCamelCase,    axis=0	),    )
														lowerCamelCase__						:						Optional[Any]						      =outputs.logits

														if self.aggregate:
																	all_aggregations.append(outputs.logits_aggregation	)

														all_logits.append(lowerCamelCase	)

														lowerCamelCase__						:						int						      =tfp.distributions.Bernoulli(logits=lowerCamelCase	)
														lowerCamelCase__						:						Tuple						      =dist_per_token.probs_parameter() * tf.cast(lowerCamelCase,    tf.floataa	)

														lowerCamelCase__						:						Optional[int]						      =collections.defaultdict(lowerCamelCase	)
														lowerCamelCase__						:						List[Any]						      =token_type_ids_example
														for i, p in enumerate(tf.squeeze(lowerCamelCase	).numpy().tolist()	):
																	lowerCamelCase__						:						Union[str, Any]						      =token_type_ids_example[:, 0].tolist()[i]
																	lowerCamelCase__						:						List[Any]						      =token_type_ids_example[:, 1].tolist()[i] - 1
																	lowerCamelCase__						:						Any						      =token_type_ids_example[:, 2].tolist()[i] - 1
																	if col >= 0 and row >= 0 and segment_id == 1:
																				coords_to_probs[(col, row)].append(lowerCamelCase	)

														lowerCamelCase__						:						List[Any]						      ={key: np.array(coords_to_probs[key]	).mean() > 0.5 for key in coords_to_probs}

											lowerCamelCase__						:						List[Any]						      =tf.concat(tuple(lowerCamelCase	),    0	)

											return (logits_batch,) if not self.aggregate else (logits_batch, tf.concat(tuple(lowerCamelCase	),    0	))



					def __call__(			self				:    Dict,    *lowerCamelCase				:    int,    **lowerCamelCase				:    str	)->   int:
								lowerCamelCase__						:						List[Any]						      =self._args_parser(*lowerCamelCase,    **lowerCamelCase	)

								lowerCamelCase__						:						Dict						      =super().__call__(lowerCamelCase,    **lowerCamelCase	)
								if len(lowerCamelCase	) == 1:
											return results[0]
								return results



					def 						snake_case			(			self				:    Dict,    lowerCamelCase				:    Dict=None,    lowerCamelCase				:    List[Any]=None,    lowerCamelCase				:    int=None,    **lowerCamelCase				:    int	)->   Optional[int]:
								lowerCamelCase__						:						Union[str, Any]						      ={}
								if padding is not None:
											lowerCamelCase__						:						Union[str, Any]						      =padding
								if truncation is not None:
											lowerCamelCase__						:						Any						      =truncation

								lowerCamelCase__						:						List[str]						      ={}
								if sequential is not None:
											lowerCamelCase__						:						int						      =sequential
								return preprocess_params, forward_params, {}



					def 						snake_case			(			self				:    Tuple,    lowerCamelCase				:    str,    lowerCamelCase				:    int=None,    lowerCamelCase				:    Tuple=True,    lowerCamelCase				:    Union[str, Any]=None	)->   List[str]:
								if truncation is None:
											if self.type == "tapas":
														lowerCamelCase__						:						Tuple						      ='''drop_rows_to_fit'''
											else:
														lowerCamelCase__						:						Union[str, Any]						      ='''do_not_truncate'''

								lowerCamelCase__      ,  lowerCamelCase__						:						List[str]						      =pipeline_input['''table'''], pipeline_input['''query''']
								if table.empty:
											raise ValueError('''table is empty'''	)
								if query is None or query == "":
											raise ValueError('''query is empty'''	)
								lowerCamelCase__						:						List[Any]						      =self.tokenizer(lowerCamelCase,    lowerCamelCase,    return_tensors=self.framework,    truncation=lowerCamelCase,    padding=lowerCamelCase	)
								lowerCamelCase__						:						Dict						      =table
								return inputs



					def 						snake_case			(			self				:    Tuple,    lowerCamelCase				:    Optional[int],    lowerCamelCase				:    Dict=False	)->   List[Any]:
								lowerCamelCase__						:						Union[str, Any]						      =model_inputs.pop('''table'''	)

								if self.type == "tapas":
											if sequential:
														lowerCamelCase__						:						List[Any]						      =self.sequential_inference(**lowerCamelCase	)
											else:
														lowerCamelCase__						:						List[Any]						      =self.batch_inference(**lowerCamelCase	)
								else:
											lowerCamelCase__						:						Union[str, Any]						      =self.model.generate(**lowerCamelCase	)
								lowerCamelCase__						:						Optional[int]						      ={'''model_inputs''': model_inputs, '''table''': table, '''outputs''': outputs}
								return model_outputs




					def 						snake_case			(			self				:    Optional[Any],    lowerCamelCase				:    Tuple	)->   int:
								lowerCamelCase__						:						List[str]						      =model_outputs['''model_inputs''']
								lowerCamelCase__						:						Any						      =model_outputs['''table''']
								lowerCamelCase__						:						List[Any]						      =model_outputs['''outputs''']
								if self.type == "tapas":
											if self.aggregate:
														lowerCamelCase__      ,  lowerCamelCase__						:						List[str]						      =outputs[:2]
														lowerCamelCase__						:						Dict						      =self.tokenizer.convert_logits_to_predictions(lowerCamelCase,    lowerCamelCase,    lowerCamelCase	)
														lowerCamelCase__      ,  lowerCamelCase__						:						Optional[int]						      =predictions
														lowerCamelCase__						:						Optional[Any]						      ={i: self.model.config.aggregation_labels[pred] for i, pred in enumerate(lowerCamelCase	)}

														lowerCamelCase__						:						str						      =self.model.config.no_aggregation_label_index
														lowerCamelCase__						:						str						      ={
														    i: aggregators[i] + ''' > ''' for i, pred in enumerate(lowerCamelCase	) if pred != no_agg_label_index
														}
											else:
														lowerCamelCase__						:						Optional[int]						      =outputs[0]
														lowerCamelCase__						:						List[Any]						      =self.tokenizer.convert_logits_to_predictions(lowerCamelCase,    lowerCamelCase	)
														lowerCamelCase__						:						List[str]						      =predictions[0]
														lowerCamelCase__						:						Optional[Any]						      ={}
														lowerCamelCase__						:						str						      ={}
											lowerCamelCase__						:						Union[str, Any]						      =[]
											for index, coordinates in enumerate(lowerCamelCase	):
														lowerCamelCase__						:						str						      =[table.iat[coordinate] for coordinate in coordinates]
														lowerCamelCase__						:						List[str]						      =aggregators.get(lowerCamelCase,    ''''''	)
														lowerCamelCase__						:						Union[str, Any]						      =aggregators_prefix.get(lowerCamelCase,    ''''''	)
														lowerCamelCase__						:						Any						      ={
														    '''answer''': aggregator_prefix + ''', '''.join(lowerCamelCase	),
														    '''coordinates''': coordinates,
														    '''cells''': [table.iat[coordinate] for coordinate in coordinates],
														}
														if aggregator:
																	lowerCamelCase__						:						Optional[Any]						      =aggregator

														answers.append(lowerCamelCase	)
											if len(lowerCamelCase	) == 0:
														raise PipelineException('''Empty answer'''	)
								else:
											lowerCamelCase__						:						Any						      =[{'''answer''': answer} for answer in self.tokenizer.batch_decode(lowerCamelCase,    skip_special_tokens=lowerCamelCase	)]

								return answers if len(lowerCamelCase	) > 1 else answers[0]





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
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 EfficientNetImageProcessor







class       __snake_case (  unittest.TestCase ):
 def __init__(	self		, snake_case__		, snake_case__=13		, snake_case__=3		, snake_case__=18		, snake_case__=30		, snake_case__=400		, snake_case__=True		, snake_case__=None		, snake_case__=True		, snake_case__=[0.5, 0.5, 0.5]		, snake_case__=[0.5, 0.5, 0.5]		, )						->				Any:
       '''simple docstring'''





       UpperCAmelCase     :			int     	=size if size is not None else {'''height''': 18, '''width''': 18}
       UpperCAmelCase     :			Tuple     	=parent
       UpperCAmelCase     :			List[str]     	=batch_size
       UpperCAmelCase     :			int     	=num_channels
       UpperCAmelCase     :			List[str]     	=image_size
       UpperCAmelCase     :			str     	=min_resolution
       UpperCAmelCase     :			Optional[int]     	=max_resolution
       UpperCAmelCase     :			Optional[int]     	=do_resize
       UpperCAmelCase     :			int     	=size
       UpperCAmelCase     :			Union[str, Any]     	=do_normalize
       UpperCAmelCase     :			Dict     	=image_mean
       UpperCAmelCase     :			List[Any]     	=image_std






 def 						UpperCAmelCase__							(	self    )						->				int:
       '''simple docstring'''





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







@require_torch
@require_vision
class       __snake_case (  lowerCamelCase__       , unittest.TestCase ):
 __lowerCamelCase     : Any 	=   EfficientNetImageProcessor if is_vision_available() else None
 def 						UpperCAmelCase__							(	self    )						->				Tuple:
       '''simple docstring'''





       UpperCAmelCase     :			Dict     	=EfficientNetImageProcessorTester(self    )
 @property
 def 						UpperCAmelCase__							(	self    )						->				int:
       '''simple docstring'''





       return self.image_processor_tester.prepare_image_processor_dict()
 def 						UpperCAmelCase__							(	self    )						->				List[str]:
       '''simple docstring'''





       UpperCAmelCase     :			Tuple     	=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_resize'''    )    )
       self.assertTrue(hasattr(snake_case__		, '''size'''    )    )
 def 						UpperCAmelCase__							(	self    )						->				Tuple:
       '''simple docstring'''





       UpperCAmelCase     :			str     	=self.image_processing_class.from_dict(self.image_processor_dict    )
       self.assertEqual(image_processor.size		, {'''height''': 18, '''width''': 18}    )

       UpperCAmelCase     :			List[str]     	=self.image_processing_class.from_dict(self.image_processor_dict		, size=42    )
       self.assertEqual(image_processor.size		, {'''height''': 42, '''width''': 42}    )
 def 						UpperCAmelCase__							(	self    )						->				Dict:
       '''simple docstring'''





       UpperCAmelCase     :			List[Any]     	=self.image_processing_class(**self.image_processor_dict    )
       # create random PIL images
       UpperCAmelCase     :			Optional[Any]     	=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
       UpperCAmelCase     :			int     	=image_processing(image_inputs[0]		, return_tensors='''pt'''    ).pixel_values
       self.assertEqual(
           encoded_images.shape		, (
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )		, )

       # Test batched
       UpperCAmelCase     :			int     	=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,
               self.image_processor_tester.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )		, )
 def 						UpperCAmelCase__							(	self    )						->				Dict:
       '''simple docstring'''





       UpperCAmelCase     :			Tuple     	=self.image_processing_class(**self.image_processor_dict    )
       # create random numpy tensors
       UpperCAmelCase     :			List[str]     	=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
       UpperCAmelCase     :			str     	=image_processing(image_inputs[0]		, return_tensors='''pt'''    ).pixel_values
       self.assertEqual(
           encoded_images.shape		, (
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )		, )

       # Test batched
       UpperCAmelCase     :			Union[str, Any]     	=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,
               self.image_processor_tester.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )		, )






 def 						UpperCAmelCase__							(	self    )						->				str:
       '''simple docstring'''





       UpperCAmelCase     :			int     	=self.image_processing_class(**self.image_processor_dict    )
       # create random PyTorch tensors
       UpperCAmelCase     :			int     	=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
       UpperCAmelCase     :			List[Any]     	=image_processing(image_inputs[0]		, return_tensors='''pt'''    ).pixel_values
       self.assertEqual(
           encoded_images.shape		, (
               1,
               self.image_processor_tester.num_channels,
               self.image_processor_tester.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )		, )

       # Test batched
       UpperCAmelCase     :			List[str]     	=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,
               self.image_processor_tester.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )		, )
