






'''simple docstring'''



from __future__ import annotations

import unittest

from transformers import DistilBertConfig, 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.models.distilbert.modeling_tf_distilbert import (
						    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFDistilBertForMaskedLM,
						    TFDistilBertForMultipleChoice,
						    TFDistilBertForQuestionAnswering,
						    TFDistilBertForSequenceClassification,
						    TFDistilBertForTokenClassification,
						    TFDistilBertModel,
						)
class UpperCAmelCase_					:




						"""simple docstring"""




						def __init__( self			:		Tuple     ,      UpperCAmelCase			:		List[str]     ,      )  ->  Union[str, Any]:


							'''simple docstring'''

							lowercase					:   int				  =parent
							lowercase					:   Any				  =13
							lowercase					:   Any				  =7
							lowercase					:   Optional[int]				  =True
							lowercase					:   Optional[int]				  =True
							lowercase					:   Tuple				  =False
							lowercase					:   Optional[Any]				  =True
							lowercase					:   Dict				  =99
							lowercase					:   Union[str, Any]				  =32
							lowercase					:   Union[str, Any]				  =2
							lowercase					:   Union[str, Any]				  =4
							lowercase					:   List[str]				  =37
							lowercase					:   str				  ='''gelu'''
							lowercase					:   Dict				  =0.1
							lowercase					:   List[Any]				  =0.1
							lowercase					:   List[str]				  =512
							lowercase					:   Optional[int]				  =16
							lowercase					:   Optional[Any]				  =2
							lowercase					:   List[str]				  =0.0_2
							lowercase					:   Any				  =3
							lowercase					:   Optional[Any]				  =4
							lowercase					:   int				  =None






						def 				A__      ( self			:		List[str]		)  ->  Dict:


							'''simple docstring'''

							lowercase					:   Tuple				  =ids_tensor([self.batch_size, self.seq_length]     ,      self.vocab_size		)

							lowercase					:   Any				  =None
							if self.use_input_mask:
								lowercase					:   List[str]				  =random_attention_mask([self.batch_size, self.seq_length]		)

							lowercase					:   Union[str, Any]				  =None
							lowercase					:   Any				  =None
							lowercase					:   str				  =None
							if self.use_labels:
								lowercase					:   Union[str, Any]				  =ids_tensor([self.batch_size]     ,      self.type_sequence_label_size		)
								lowercase					:   Tuple				  =ids_tensor([self.batch_size, self.seq_length]     ,      self.num_labels		)
								lowercase					:   List[Any]				  =ids_tensor([self.batch_size]     ,      self.num_choices		)

							lowercase					:   Dict				  =DistilBertConfig(
							    vocab_size=self.vocab_size     ,      dim=self.hidden_size     ,      n_layers=self.num_hidden_layers     ,      n_heads=self.num_attention_heads     ,      hidden_dim=self.intermediate_size     ,      hidden_act=self.hidden_act     ,      dropout=self.hidden_dropout_prob     ,      attention_dropout=self.attention_probs_dropout_prob     ,      max_position_embeddings=self.max_position_embeddings     ,      initializer_range=self.initializer_range     ,      )

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






						def 				A__      ( self			:		Any     ,      UpperCAmelCase			:		Dict     ,      UpperCAmelCase			:		List[str]     ,      UpperCAmelCase			:		Any     ,      UpperCAmelCase			:		List[str]     ,      UpperCAmelCase			:		Dict     ,      UpperCAmelCase			:		Optional[Any]		)  ->  Union[str, Any]:


							'''simple docstring'''

							lowercase					:   int				  =TFDistilBertModel(config=UpperCAmelCase		)
							lowercase					:   int				  ={'''input_ids''': input_ids, '''attention_mask''': input_mask}

							lowercase					:   List[str]				  =model(UpperCAmelCase		)

							lowercase					:   str				  =[input_ids, input_mask]

							lowercase					:   Tuple				  =model(UpperCAmelCase		)

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






						def 				A__      ( self			:		List[Any]     ,      UpperCAmelCase			:		Any     ,      UpperCAmelCase			:		int     ,      UpperCAmelCase			:		Dict     ,      UpperCAmelCase			:		List[str]     ,      UpperCAmelCase			:		List[str]     ,      UpperCAmelCase			:		Optional[Any]		)  ->  Tuple:


							'''simple docstring'''

							lowercase					:   List[str]				  =TFDistilBertForMaskedLM(config=UpperCAmelCase		)
							lowercase					:   int				  ={'''input_ids''': input_ids, '''attention_mask''': input_mask}
							lowercase					:   Union[str, Any]				  =model(UpperCAmelCase		)
							self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.seq_length, self.vocab_size)		)






						def 				A__      ( self			:		List[Any]     ,      UpperCAmelCase			:		int     ,      UpperCAmelCase			:		Union[str, Any]     ,      UpperCAmelCase			:		Union[str, Any]     ,      UpperCAmelCase			:		Union[str, Any]     ,      UpperCAmelCase			:		List[Any]     ,      UpperCAmelCase			:		Optional[int]		)  ->  Any:


							'''simple docstring'''

							lowercase					:   str				  =TFDistilBertForQuestionAnswering(config=UpperCAmelCase		)
							lowercase					:   int				  ={
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							}
							lowercase					:   List[str]				  =model(UpperCAmelCase		)
							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			:		str     ,      UpperCAmelCase			:		int     ,      UpperCAmelCase			:		List[str]     ,      UpperCAmelCase			:		List[Any]     ,      UpperCAmelCase			:		Tuple     ,      UpperCAmelCase			:		Optional[Any]     ,      UpperCAmelCase			:		Dict		)  ->  Optional[int]:


							'''simple docstring'''

							lowercase					:   Dict				  =self.num_labels
							lowercase					:   Optional[Any]				  =TFDistilBertForSequenceClassification(UpperCAmelCase		)
							lowercase					:   str				  ={'''input_ids''': input_ids, '''attention_mask''': input_mask}
							lowercase					:   Union[str, Any]				  =model(UpperCAmelCase		)
							self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.num_labels)		)






						def 				A__      ( self			:		int     ,      UpperCAmelCase			:		str     ,      UpperCAmelCase			:		str     ,      UpperCAmelCase			:		Any     ,      UpperCAmelCase			:		str     ,      UpperCAmelCase			:		int     ,      UpperCAmelCase			:		Dict		)  ->  List[str]:


							'''simple docstring'''

							lowercase					:   List[Any]				  =self.num_choices
							lowercase					:   Optional[int]				  =TFDistilBertForMultipleChoice(UpperCAmelCase		)
							lowercase					:   Optional[Any]				  =tf.tile(tf.expand_dims(UpperCAmelCase     ,      1		)     ,      (1, self.num_choices, 1)		)
							lowercase					:   List[Any]				  =tf.tile(tf.expand_dims(UpperCAmelCase     ,      1		)     ,      (1, self.num_choices, 1)		)
							lowercase					:   Tuple				  ={
							    '''input_ids''': multiple_choice_inputs_ids,
							    '''attention_mask''': multiple_choice_input_mask,
							}
							lowercase					:   Tuple				  =model(UpperCAmelCase		)
							self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.num_choices)		)






						def 				A__      ( self			:		List[Any]     ,      UpperCAmelCase			:		Optional[Any]     ,      UpperCAmelCase			:		Tuple     ,      UpperCAmelCase			:		Optional[Any]     ,      UpperCAmelCase			:		Dict     ,      UpperCAmelCase			:		List[Any]     ,      UpperCAmelCase			:		Union[str, Any]		)  ->  Dict:


							'''simple docstring'''

							lowercase					:   Dict				  =self.num_labels
							lowercase					:   Tuple				  =TFDistilBertForTokenClassification(UpperCAmelCase		)
							lowercase					:   Optional[Any]				  ={'''input_ids''': input_ids, '''attention_mask''': input_mask}
							lowercase					:   str				  =model(UpperCAmelCase		)
							self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.seq_length, self.num_labels)		)






						def 				A__      ( self			:		List[str]		)  ->  Dict:


							'''simple docstring'''

							lowercase					:   int				  =self.prepare_config_and_inputs()
							(lowercase)					:   Union[str, Any]				  =config_and_inputs
							lowercase					:   Tuple				  ={'''input_ids''': input_ids, '''attention_mask''': input_mask}
							return config, inputs_dict





@require_tf
class UpperCAmelCase_					(    __A				,       __A				,       unittest.TestCase				):




						"""simple docstring"""




						UpperCamelCase_								=			(
						    (
						        TFDistilBertModel,
						        TFDistilBertForMaskedLM,
						        TFDistilBertForQuestionAnswering,
						        TFDistilBertForSequenceClassification,
						        TFDistilBertForTokenClassification,
						        TFDistilBertForMultipleChoice,
						    )
						    if is_tf_available()
						    else None
						)
						UpperCamelCase_								=			(
						    {
						        '''feature-extraction''': TFDistilBertModel,
						        '''fill-mask''': TFDistilBertForMaskedLM,
						        '''question-answering''': TFDistilBertForQuestionAnswering,
						        '''text-classification''': TFDistilBertForSequenceClassification,
						        '''token-classification''': TFDistilBertForTokenClassification,
						        '''zero-shot''': TFDistilBertForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						UpperCamelCase_								=			False
						UpperCamelCase_								=			False






						def 				A__      ( self			:		Dict		)  ->  str:


							'''simple docstring'''

							lowercase					:   str				  =TFDistilBertModelTester(self		)
							lowercase					:   int				  =ConfigTester(self     ,      config_class=UpperCAmelCase     ,      dim=37		)






						def 				A__      ( self			:		Union[str, Any]		)  ->  Dict:


							'''simple docstring'''

							self.config_tester.run_common_tests()






						def 				A__      ( self			:		Optional[Any]		)  ->  Tuple:


							'''simple docstring'''

							lowercase					:   List[Any]				  =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_model(*UpperCAmelCase		)






						def 				A__      ( self			:		Tuple		)  ->  Any:


							'''simple docstring'''

							lowercase					:   str				  =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_masked_lm(*UpperCAmelCase		)






						def 				A__      ( self			:		Optional[int]		)  ->  List[Any]:


							'''simple docstring'''

							lowercase					:   Any				  =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_question_answering(*UpperCAmelCase		)






						def 				A__      ( self			:		Any		)  ->  str:


							'''simple docstring'''

							lowercase					:   List[Any]				  =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_sequence_classification(*UpperCAmelCase		)






						def 				A__      ( self			:		Optional[Any]		)  ->  List[str]:


							'''simple docstring'''

							lowercase					:   str				  =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_multiple_choice(*UpperCAmelCase		)






						def 				A__      ( self			:		str		)  ->  Union[str, Any]:


							'''simple docstring'''

							lowercase					:   str				  =self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_token_classification(*UpperCAmelCase		)






						@slow
						def 				A__      ( self			:		List[Any]		)  ->  Dict:


							'''simple docstring'''

							for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]		):
								lowercase					:   Union[str, Any]				  =TFDistilBertModel.from_pretrained(UpperCAmelCase		)
								self.assertIsNotNone(UpperCAmelCase		)





@require_tf
class UpperCAmelCase_					(    unittest.TestCase				):




						"""simple docstring"""




						@slow
						def 				A__      ( self			:		List[str]		)  ->  List[Any]:


							'''simple docstring'''

							lowercase					:   Optional[Any]				  =TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''		)
							lowercase					:   Tuple				  =tf.constant([[0, 1, 2, 3, 4, 5]]		)
							lowercase					:   List[Any]				  =model(UpperCAmelCase		)[0]

							lowercase					:   str				  =[1, 6, 768]
							self.assertEqual(output.shape     ,      UpperCAmelCase		)

							lowercase					:   Optional[int]				  =tf.constant(
							    [
							        [
							            [0.1_9_2_6_1_8_8_5, -0.1_3_7_3_2_9_5_5, 0.4_1_1_9_7_9_9],
							            [0.2_2_1_5_0_1_5_6, -0.0_7_4_2_2_6_6_1, 0.3_9_0_3_7_2_0_4],
							            [0.2_2_7_5_6_0_1_8, -0.0_8_9_6_4_1_4, 0.3_7_0_1_4_6_7],
							        ]
							    ]		)
							tf.debugging.assert_near(output[:, :3, :3]     ,      UpperCAmelCase     ,      atol=1e-4		)











'''simple docstring'''



from typing import Dict, Iterable, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import normalize, rescale, resize, to_channel_dimension_format, to_pil_image
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_pytesseract_available, is_vision_available, logging, requires_backends


if is_vision_available():
      import PIL

# soft dependency
if is_pytesseract_available():
      import pytesseract

SCREAMING_SNAKE_CASE						=	logging.get_logger(__name__)


def 							lowercase_				(    __A :       List[Any]					,      __A :       int					,      __A :       int			)       ->      Optional[int]:



 """simple docstring"""




 return [
     int(1_0_0_0 * (box[0] / width)			),
     int(1_0_0_0 * (box[1] / height)			),
     int(1_0_0_0 * (box[2] / width)			),
     int(1_0_0_0 * (box[3] / height)			),
 ]


def 							lowercase_				(    __A :       np.ndarray					,      __A :       Optional[str]					,      __A :       Optional[str]			)       ->      Optional[Any]:



 """simple docstring"""




 lowercase					:   int				  =to_pil_image(__A			)
 lowercase  ,		lowercase					:   Tuple				  =pil_image.size
 lowercase					:   Optional[Any]				  =pytesseract.image_to_data(__A					,      lang=__A					,      output_type='''dict'''					,      config=__A			)
 lowercase  ,		lowercase  ,		lowercase  ,		lowercase  ,		lowercase					:   Optional[Any]				  =data['''text'''], data['''left'''], data['''top'''], data['''width'''], data['''height''']

 # filter empty words and corresponding coordinates
 lowercase					:   Dict				  =[idx for idx, word in enumerate(__A			) if not word.strip()]
 lowercase					:   str				  =[word for idx, word in enumerate(__A			) if idx not in irrelevant_indices]
 lowercase					:   Optional[int]				  =[coord for idx, coord in enumerate(__A			) if idx not in irrelevant_indices]
 lowercase					:   List[Any]				  =[coord for idx, coord in enumerate(__A			) if idx not in irrelevant_indices]
 lowercase					:   str				  =[coord for idx, coord in enumerate(__A			) if idx not in irrelevant_indices]
 lowercase					:   int				  =[coord for idx, coord in enumerate(__A			) if idx not in irrelevant_indices]

 # turn coordinates into (left, top, left+width, top+height) format
 lowercase					:   Tuple				  =[]
 for x, y, w, h in zip(__A					,      __A					,      __A					,      __A			):
  lowercase					:   str				  =[x, y, x + w, y + h]
  actual_boxes.append(__A			)

 # finally, normalize the bounding boxes
 lowercase					:   List[str]				  =[]
 for box in actual_boxes:
  normalized_boxes.append(normalize_box(__A					,      __A					,      __A			)			)

 assert len(__A			) == len(__A			), "Not as many words as there are bounding boxes"

 return words, normalized_boxes





class UpperCAmelCase_					(    __A				):




      """simple docstring"""




      UpperCamelCase_								=			['''pixel_values''']






      def __init__( self			:		List[Any]     ,      UpperCAmelCase			:		bool = True     ,      UpperCAmelCase			:		Dict[str, int] = None     ,      UpperCAmelCase			:		PILImageResampling = PILImageResampling.BILINEAR     ,      UpperCAmelCase			:		bool = True     ,      UpperCAmelCase			:		float = 1 / 255     ,      UpperCAmelCase			:		bool = True     ,      UpperCAmelCase			:		Union[float, Iterable[float]] = None     ,      UpperCAmelCase			:		Union[float, Iterable[float]] = None     ,      UpperCAmelCase			:		bool = True     ,      UpperCAmelCase			:		Optional[str] = None     ,      UpperCAmelCase			:		Optional[str] = ""     ,      **UpperCAmelCase			:		Tuple     ,      )  ->  None:


       '''simple docstring'''

       super().__init__(**UpperCAmelCase		)
       lowercase					:   Tuple				  =size if size is not None else {'''height''': 224, '''width''': 224}
       lowercase					:   Optional[Any]				  =get_size_dict(UpperCAmelCase		)

       lowercase					:   Optional[Any]				  =do_resize
       lowercase					:   List[Any]				  =size
       lowercase					:   List[str]				  =resample
       lowercase					:   Dict				  =do_rescale
       lowercase					:   str				  =rescale_value
       lowercase					:   Optional[int]				  =do_normalize
       lowercase					:   Any				  =image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
       lowercase					:   Union[str, Any]				  =image_std if image_std is not None else IMAGENET_STANDARD_STD
       lowercase					:   List[Any]				  =apply_ocr
       lowercase					:   Union[str, Any]				  =ocr_lang
       lowercase					:   str				  =tesseract_config






      def 				A__      ( self			:		Dict     ,      UpperCAmelCase			:		np.ndarray     ,      UpperCAmelCase			:		Dict[str, int]     ,      UpperCAmelCase			:		PILImageResampling = PILImageResampling.BILINEAR     ,      UpperCAmelCase			:		Optional[Union[str, ChannelDimension]] = None     ,      **UpperCAmelCase			:		Optional[Any]     ,      )  ->  np.ndarray:


       '''simple docstring'''

       lowercase					:   Tuple				  =get_size_dict(UpperCAmelCase		)
       if "height" not in size or "width" not in size:
        raise ValueError(f'The size dictionary must contain the keys \'height\' and \'width\'. Got {size.keys()}'		)
       lowercase					:   Optional[Any]				  =(size['''height'''], size['''width'''])
       return resize(UpperCAmelCase     ,      size=UpperCAmelCase     ,      resample=UpperCAmelCase     ,      data_format=UpperCAmelCase     ,      **UpperCAmelCase		)






      def 				A__      ( self			:		Union[str, Any]     ,      UpperCAmelCase			:		np.ndarray     ,      UpperCAmelCase			:		Union[int, float]     ,      UpperCAmelCase			:		Optional[Union[str, ChannelDimension]] = None     ,      **UpperCAmelCase			:		Optional[Any]     ,      )  ->  np.ndarray:


       '''simple docstring'''

       return rescale(UpperCAmelCase     ,      scale=UpperCAmelCase     ,      data_format=UpperCAmelCase     ,      **UpperCAmelCase		)






      def 				A__      ( self			:		Union[str, Any]     ,      UpperCAmelCase			:		np.ndarray     ,      UpperCAmelCase			:		Union[float, Iterable[float]]     ,      UpperCAmelCase			:		Union[float, Iterable[float]]     ,      UpperCAmelCase			:		Optional[Union[str, ChannelDimension]] = None     ,      **UpperCAmelCase			:		Optional[int]     ,      )  ->  np.ndarray:


       '''simple docstring'''

       return normalize(UpperCAmelCase     ,      mean=UpperCAmelCase     ,      std=UpperCAmelCase     ,      data_format=UpperCAmelCase     ,      **UpperCAmelCase		)






      def 				A__      ( self			:		Any     ,      UpperCAmelCase			:		ImageInput     ,      UpperCAmelCase			:		bool = None     ,      UpperCAmelCase			:		Dict[str, int] = None     ,      UpperCAmelCase			:		Union[str, Any]=None     ,      UpperCAmelCase			:		bool = None     ,      UpperCAmelCase			:		float = None     ,      UpperCAmelCase			:		bool = None     ,      UpperCAmelCase			:		Union[float, Iterable[float]] = None     ,      UpperCAmelCase			:		Union[float, Iterable[float]] = None     ,      UpperCAmelCase			:		bool = None     ,      UpperCAmelCase			:		Optional[str] = None     ,      UpperCAmelCase			:		Optional[str] = None     ,      UpperCAmelCase			:		Optional[Union[str, TensorType]] = None     ,      UpperCAmelCase			:		ChannelDimension = ChannelDimension.FIRST     ,      **UpperCAmelCase			:		List[str]     ,      )  ->  PIL.Image.Image:


       '''simple docstring'''

       lowercase					:   Optional[int]				  =do_resize if do_resize is not None else self.do_resize
       lowercase					:   Tuple				  =size if size is not None else self.size
       lowercase					:   Optional[int]				  =get_size_dict(UpperCAmelCase		)
       lowercase					:   List[str]				  =resample if resample is not None else self.resample
       lowercase					:   List[Any]				  =do_rescale if do_rescale is not None else self.do_rescale
       lowercase					:   List[Any]				  =rescale_factor if rescale_factor is not None else self.rescale_factor
       lowercase					:   Optional[int]				  =do_normalize if do_normalize is not None else self.do_normalize
       lowercase					:   List[Any]				  =image_mean if image_mean is not None else self.image_mean
       lowercase					:   Optional[int]				  =image_std if image_std is not None else self.image_std
       lowercase					:   Any				  =apply_ocr if apply_ocr is not None else self.apply_ocr
       lowercase					:   Any				  =ocr_lang if ocr_lang is not None else self.ocr_lang
       lowercase					:   Dict				  =tesseract_config if tesseract_config is not None else self.tesseract_config

       lowercase					:   str				  =make_list_of_images(UpperCAmelCase		)

       if not valid_images(UpperCAmelCase		):
        raise ValueError(
            '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
            '''torch.Tensor, tf.Tensor or jax.ndarray.'''		)

       if do_resize and size is None:
        raise ValueError('''Size must be specified if do_resize is True.'''		)

       if do_rescale and rescale_factor is None:
        raise ValueError('''Rescale factor must be specified if do_rescale is True.'''		)

       if do_normalize and (image_mean is None or image_std is None):
        raise ValueError('''If do_normalize is True, image_mean and image_std must be specified.'''		)

       # All transformations expect numpy arrays.
       lowercase					:   Tuple				  =[to_numpy_array(UpperCAmelCase		) for image in images]

       # Tesseract OCR to get words + normalized bounding boxes
       if apply_ocr:
        requires_backends(self     ,      '''pytesseract'''		)
        lowercase					:   int				  =[]
        lowercase					:   Tuple				  =[]
        for image in images:
         lowercase  ,		lowercase					:   Dict				  =apply_tesseract(UpperCAmelCase     ,      UpperCAmelCase     ,      UpperCAmelCase		)
         words_batch.append(UpperCAmelCase		)
         boxes_batch.append(UpperCAmelCase		)

       if do_resize:
        lowercase					:   int				  =[self.resize(image=UpperCAmelCase     ,      size=UpperCAmelCase     ,      resample=UpperCAmelCase		) for image in images]

       if do_rescale:
        lowercase					:   Tuple				  =[self.rescale(image=UpperCAmelCase     ,      scale=UpperCAmelCase		) for image in images]

       if do_normalize:
        lowercase					:   str				  =[self.normalize(image=UpperCAmelCase     ,      mean=UpperCAmelCase     ,      std=UpperCAmelCase		) for image in images]

       lowercase					:   Optional[Any]				  =[to_channel_dimension_format(UpperCAmelCase     ,      UpperCAmelCase		) for image in images]

       lowercase					:   Dict				  =BatchFeature(data={'''pixel_values''': images}     ,      tensor_type=UpperCAmelCase		)

       if apply_ocr:
        lowercase					:   int				  =words_batch
        lowercase					:   List[str]				  =boxes_batch
       return data



