


"""simple docstring"""






import os
import tempfile
import unittest

from transformers import FlaubertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import (
       FlaubertForMultipleChoice,
       FlaubertForQuestionAnswering,
       FlaubertForQuestionAnsweringSimple,
       FlaubertForSequenceClassification,
       FlaubertForTokenClassification,
       FlaubertModel,
       FlaubertWithLMHeadModel,
   )
   from transformers.models.flaubert.modeling_flaubert import FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST


class     __lowerCamelCase  (					a__				):

     '''simple docstring'''


     def __init__(      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase=13    ,				__UpperCAmelCase=7    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=False    ,				__UpperCAmelCase=False    ,				__UpperCAmelCase=False    ,				__UpperCAmelCase=2    ,				__UpperCAmelCase=99    ,				__UpperCAmelCase=0    ,				__UpperCAmelCase=32    ,				__UpperCAmelCase=5    ,				__UpperCAmelCase=4    ,				__UpperCAmelCase=0.1    ,				__UpperCAmelCase=0.1    ,				__UpperCAmelCase=512    ,				__UpperCAmelCase=12    ,				__UpperCAmelCase=2    ,				__UpperCAmelCase=0.02    ,				__UpperCAmelCase=3    ,				__UpperCAmelCase=4    ,				__UpperCAmelCase="last"    ,				__UpperCAmelCase=None    ,				__UpperCAmelCase=None    ,				)       ->							List[Any]:
          _a    	=				parent
          _a    	=				batch_size
          _a    	=				seq_length
          _a    	=				is_training
          _a    	=				use_input_lengths
          _a    	=				use_token_type_ids
          _a    	=				use_labels
          _a    	=				gelu_activation
          _a    	=				sinusoidal_embeddings
          _a    	=				causal
          _a    	=				asm
          _a    	=				n_langs
          _a    	=				vocab_size
          _a    	=				n_special
          _a    	=				hidden_size
          _a    	=				num_hidden_layers
          _a    	=				num_attention_heads
          _a    	=				hidden_dropout_prob
          _a    	=				attention_probs_dropout_prob
          _a    	=				max_position_embeddings
          _a    	=				type_vocab_size
          _a    	=				type_sequence_label_size
          _a    	=				initializer_range
          _a    	=				num_labels
          _a    	=				num_choices
          _a    	=				summary_type
          _a    	=				use_proj
          _a    	=				scope


     def 							_UpperCAmelCase      (      self							)       ->							int:
          _a    	=				ids_tensor([self.batch_size, self.seq_length]    ,				self.vocab_size							)
          _a    	=				random_attention_mask([self.batch_size, self.seq_length]							)

          _a    	=				None
          if self.use_input_lengths:
               _a    	=				(
                   ids_tensor([self.batch_size]    ,				vocab_size=2							) + self.seq_length - 2
               )  # small variation of seq_length

          _a    	=				None
          if self.use_token_type_ids:
               _a    	=				ids_tensor([self.batch_size, self.seq_length]    ,				self.n_langs							)

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

          _a    	=				self.get_config()

          return (
              config,
              input_ids,
              token_type_ids,
              input_lengths,
              sequence_labels,
              token_labels,
              is_impossible_labels,
              choice_labels,
              input_mask,
          )


     def 							_UpperCAmelCase      (      self							)       ->							Optional[int]:
          return FlaubertConfig(
              vocab_size=self.vocab_size    ,				n_special=self.n_special    ,				emb_dim=self.hidden_size    ,				n_layers=self.num_hidden_layers    ,				n_heads=self.num_attention_heads    ,				dropout=self.hidden_dropout_prob    ,				attention_dropout=self.attention_probs_dropout_prob    ,				gelu_activation=self.gelu_activation    ,				sinusoidal_embeddings=self.sinusoidal_embeddings    ,				asm=self.asm    ,				causal=self.causal    ,				n_langs=self.n_langs    ,				max_position_embeddings=self.max_position_embeddings    ,				initializer_range=self.initializer_range    ,				summary_type=self.summary_type    ,				use_proj=self.use_proj    ,				)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				)       ->							int:
          _a    	=				FlaubertModel(config=__UpperCAmelCase							)
          model.to(__UpperCAmelCase							)
          model.eval()
          _a    	=				model(__UpperCAmelCase    ,				lengths=__UpperCAmelCase    ,				langs=__UpperCAmelCase							)
          _a    	=				model(__UpperCAmelCase    ,				langs=__UpperCAmelCase							)
          _a    	=				model(__UpperCAmelCase							)
          self.parent.assertEqual(result.last_hidden_state.shape    ,				(self.batch_size, self.seq_length, self.hidden_size)							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				)       ->							Union[str, Any]:
          _a    	=				FlaubertWithLMHeadModel(__UpperCAmelCase							)
          model.to(__UpperCAmelCase							)
          model.eval()

          _a    	=				model(__UpperCAmelCase    ,				token_type_ids=__UpperCAmelCase    ,				labels=__UpperCAmelCase							)
          self.parent.assertEqual(result.loss.shape    ,				()							)
          self.parent.assertEqual(result.logits.shape    ,				(self.batch_size, self.seq_length, self.vocab_size)							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				)       ->							List[str]:
          _a    	=				FlaubertForQuestionAnsweringSimple(__UpperCAmelCase							)
          model.to(__UpperCAmelCase							)
          model.eval()

          _a    	=				model(__UpperCAmelCase							)

          _a    	=				model(__UpperCAmelCase    ,				start_positions=__UpperCAmelCase    ,				end_positions=__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 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				)       ->							str:
          _a    	=				FlaubertForQuestionAnswering(__UpperCAmelCase							)
          model.to(__UpperCAmelCase							)
          model.eval()

          _a    	=				model(__UpperCAmelCase							)

          _a    	=				model(
              __UpperCAmelCase    ,				start_positions=__UpperCAmelCase    ,				end_positions=__UpperCAmelCase    ,				cls_index=__UpperCAmelCase    ,				is_impossible=__UpperCAmelCase    ,				p_mask=__UpperCAmelCase    ,				)

          _a    	=				model(
              __UpperCAmelCase    ,				start_positions=__UpperCAmelCase    ,				end_positions=__UpperCAmelCase    ,				cls_index=__UpperCAmelCase    ,				is_impossible=__UpperCAmelCase    ,				)

          ((_a)	,      )    	=				result_with_labels.to_tuple()

          _a    	=				model(__UpperCAmelCase    ,				start_positions=__UpperCAmelCase    ,				end_positions=__UpperCAmelCase							)

          ((_a)	,      )    	=				result_with_labels.to_tuple()

          self.parent.assertEqual(result_with_labels.loss.shape    ,				()							)
          self.parent.assertEqual(result.start_top_log_probs.shape    ,				(self.batch_size, model.config.start_n_top)							)
          self.parent.assertEqual(result.start_top_index.shape    ,				(self.batch_size, model.config.start_n_top)							)
          self.parent.assertEqual(
              result.end_top_log_probs.shape    ,				(self.batch_size, model.config.start_n_top * model.config.end_n_top)							)
          self.parent.assertEqual(
              result.end_top_index.shape    ,				(self.batch_size, model.config.start_n_top * model.config.end_n_top)							)
          self.parent.assertEqual(result.cls_logits.shape    ,				(self.batch_size,)							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				)       ->							List[str]:
          _a    	=				FlaubertForSequenceClassification(__UpperCAmelCase							)
          model.to(__UpperCAmelCase							)
          model.eval()

          _a    	=				model(__UpperCAmelCase							)
          _a    	=				model(__UpperCAmelCase    ,				labels=__UpperCAmelCase							)

          self.parent.assertEqual(result.loss.shape    ,				()							)
          self.parent.assertEqual(result.logits.shape    ,				(self.batch_size, self.type_sequence_label_size)							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				)       ->							Tuple:
          _a    	=				self.num_labels
          _a    	=				FlaubertForTokenClassification(__UpperCAmelCase							)
          model.to(__UpperCAmelCase							)
          model.eval()

          _a    	=				model(__UpperCAmelCase    ,				attention_mask=__UpperCAmelCase    ,				labels=__UpperCAmelCase							)
          self.parent.assertEqual(result.logits.shape    ,				(self.batch_size, self.seq_length, self.num_labels)							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				)       ->							int:
          _a    	=				self.num_choices
          _a    	=				FlaubertForMultipleChoice(config=__UpperCAmelCase							)
          model.to(__UpperCAmelCase							)
          model.eval()
          _a    	=				input_ids.unsqueeze(1							).expand(-1    ,				self.num_choices    ,				-1							).contiguous()
          _a    	=				token_type_ids.unsqueeze(1							).expand(-1    ,				self.num_choices    ,				-1							).contiguous()
          _a    	=				input_mask.unsqueeze(1							).expand(-1    ,				self.num_choices    ,				-1							).contiguous()
          _a    	=				model(
              __UpperCAmelCase    ,				attention_mask=__UpperCAmelCase    ,				token_type_ids=__UpperCAmelCase    ,				labels=__UpperCAmelCase    ,				)
          self.parent.assertEqual(result.logits.shape    ,				(self.batch_size, self.num_choices)							)





     def 							_UpperCAmelCase      (      self							)       ->							List[Any]:
          _a    	=				self.prepare_config_and_inputs()
          (
              (
              _a
          )	,      (
              _a
          )	,      (
              _a
          )	,      (
              _a
          )	,      (
              _a
          )	,      (
              _a
          )	,      (
              _a
          )	,      (
              _a
          )	,      (
              _a
          )	,      
          )    	=				config_and_inputs
          _a    	=				{
              '''input_ids''': input_ids,
              '''token_type_ids''': token_type_ids,
              '''lengths''': input_lengths,
              '''attention_mask''': input_mask,
          }
          return config, inputs_dict







@require_torch
class     __lowerCamelCase  (					a__  ,					a__  ,					unittest.TestCase				):

     '''simple docstring'''
     A_       :	Any    =		(
         (
             FlaubertModel,
             FlaubertWithLMHeadModel,
             FlaubertForQuestionAnswering,
             FlaubertForQuestionAnsweringSimple,
             FlaubertForSequenceClassification,
             FlaubertForTokenClassification,
             FlaubertForMultipleChoice,
         )
         if is_torch_available()
         else ()
     )
     A_       :	int    =		(
         {
             'feature-extraction': FlaubertModel,
             'fill-mask': FlaubertWithLMHeadModel,
             'question-answering': FlaubertForQuestionAnsweringSimple,
             'text-classification': FlaubertForSequenceClassification,
             'token-classification': FlaubertForTokenClassification,
             'zero-shot': FlaubertForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase							)       ->							List[str]:
          if (
              pipeline_test_casse_name == "QAPipelineTests"
              and tokenizer_name is not None
              and not tokenizer_name.endswith('''Fast'''							)
          ):
               # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
               # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
               # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
               return True

          return False


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase=False							)       ->							Optional[int]:
          _a    	=				super()._prepare_for_class(__UpperCAmelCase    ,				__UpperCAmelCase    ,				return_labels=__UpperCAmelCase							)

          if return_labels:
               if model_class.__name__ == "FlaubertForQuestionAnswering":
                    _a    	=				torch.zeros(
                        self.model_tester.batch_size    ,				dtype=torch.long    ,				device=__UpperCAmelCase							)
                    _a    	=				torch.zeros(
                        self.model_tester.batch_size    ,				dtype=torch.long    ,				device=__UpperCAmelCase							)

          return inputs_dict


     def 							_UpperCAmelCase      (      self							)       ->							Tuple:
          _a    	=				FlaubertModelTester(self							)
          _a    	=				ConfigTester(self    ,				config_class=__UpperCAmelCase    ,				emb_dim=37							)


     def 							_UpperCAmelCase      (      self							)       ->							int:
          self.config_tester.run_common_tests()


     def 							_UpperCAmelCase      (      self							)       ->							Optional[int]:
          _a    	=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_model(*__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self							)       ->							int:
          _a    	=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_lm_head(*__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self							)       ->							List[Any]:
          _a    	=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_simple_qa(*__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self							)       ->							Optional[Any]:
          _a    	=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_qa(*__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self							)       ->							List[str]:
          _a    	=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_sequence_classif(*__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self							)       ->							List[Any]:
          _a    	=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_token_classif(*__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self							)       ->							int:
          _a    	=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_flaubert_multiple_choice(*__UpperCAmelCase							)


     @slow
     def 							_UpperCAmelCase      (      self							)       ->							int:
          for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               _a    	=				FlaubertModel.from_pretrained(__UpperCAmelCase							)
               self.assertIsNotNone(__UpperCAmelCase							)





     @slow
     @require_torch_gpu
     def 							_UpperCAmelCase      (      self							)       ->							Optional[int]:
          _a	,      _a    	=				self.model_tester.prepare_config_and_inputs_for_common()
          for model_class in self.all_model_classes:
               # FlauBertForMultipleChoice behaves incorrectly in JIT environments.
               if model_class == FlaubertForMultipleChoice:
                    return

               _a    	=				True
               _a    	=				model_class(config=__UpperCAmelCase							)

               _a    	=				self._prepare_for_class(__UpperCAmelCase    ,				__UpperCAmelCase							)
               _a    	=				torch.jit.trace(
                   __UpperCAmelCase    ,				(inputs_dict['''input_ids'''].to('''cpu'''							), inputs_dict['''attention_mask'''].to('''cpu'''							))							)

               with tempfile.TemporaryDirectory() as tmp:
                    torch.jit.save(__UpperCAmelCase    ,				os.path.join(__UpperCAmelCase    ,				'''traced_model.pt'''							)							)
                    _a    	=				torch.jit.load(os.path.join(__UpperCAmelCase    ,				'''traced_model.pt'''							)    ,				map_location=__UpperCAmelCase							)
                    loaded(inputs_dict['''input_ids'''].to(__UpperCAmelCase							)    ,				inputs_dict['''attention_mask'''].to(__UpperCAmelCase							)							)







@require_torch
class     __lowerCamelCase  (					unittest.TestCase				):

     '''simple docstring'''


     @slow
     def 							_UpperCAmelCase      (      self							)       ->							Union[str, Any]:
          _a    	=				FlaubertModel.from_pretrained('''flaubert/flaubert_base_cased'''							)
          _a    	=				torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]							)
          with torch.no_grad():
               _a    	=				model(__UpperCAmelCase							)[0]
          _a    	=				torch.Size((1, 11, 768)							)
          self.assertEqual(output.shape    ,				__UpperCAmelCase							)
          _a    	=				torch.tensor(
              [[[-2.6251, -1.4298, -0.0227], [-2.8510, -1.6387, 0.2258], [-2.8114, -1.1832, -0.3066]]]							)

          self.assertTrue(torch.allclose(output[:, :3, :3]    ,				__UpperCAmelCase    ,				atol=1e-4							)							)



"""simple docstring"""






from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
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_vision_available, logging


if is_vision_available():
   import PIL


__snake_case		=       logging.get_logger(__name__)


class     __lowerCamelCase  (					a__				):

     '''simple docstring'''
     A_       :	Any    =		['pixel_values']


     def __init__(      self    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = PILImageResampling.BILINEAR    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = 1 / 255    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							None:
          super().__init__(**__UpperCAmelCase							)
          _a    	=				size if size is not None else {'''shortest_edge''': 384}
          _a    	=				get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase							)

          _a    	=				do_resize
          _a    	=				size
          # Default value set here for backwards compatibility where the value in config is None
          _a    	=				crop_pct if crop_pct is not None else 224 / 256
          _a    	=				resample
          _a    	=				do_rescale
          _a    	=				rescale_factor
          _a    	=				do_normalize
          _a    	=				image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
          _a    	=				image_std if image_std is not None else IMAGENET_STANDARD_STD


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase = PILImageResampling.BICUBIC    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							np.ndarray:
          _a    	=				get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase							)
          if "shortest_edge" not in size:
               raise ValueError(F'Size dictionary must contain \'shortest_edge\' key. Got {size.keys()}'							)
          _a    	=				size['''shortest_edge''']

          if shortest_edge < 384:
               # maintain same ratio, resizing shortest edge to shortest_edge/crop_pct
               _a    	=				int(shortest_edge / crop_pct							)
               _a    	=				get_resize_output_image_size(__UpperCAmelCase    ,				size=__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase							)
               _a    	=				resize(image=__UpperCAmelCase    ,				size=__UpperCAmelCase    ,				resample=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase							)
               # then crop to (shortest_edge, shortest_edge)
               return center_crop(image=__UpperCAmelCase    ,				size=(shortest_edge, shortest_edge)    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase							)
          else:
               # warping (no cropping) when evaluated at 384 or larger
               return resize(
                   __UpperCAmelCase    ,				size=(shortest_edge, shortest_edge)    ,				resample=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							Optional[int]:
          return rescale(__UpperCAmelCase    ,				scale=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							np.ndarray:
          return normalize(__UpperCAmelCase    ,				mean=__UpperCAmelCase    ,				std=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase							)





     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = ChannelDimension.FIRST    ,				**__UpperCAmelCase    ,				)       ->							PIL.Image.Image:
          _a    	=				do_resize if do_resize is not None else self.do_resize
          _a    	=				crop_pct if crop_pct is not None else self.crop_pct
          _a    	=				resample if resample is not None else self.resample
          _a    	=				do_rescale if do_rescale is not None else self.do_rescale
          _a    	=				rescale_factor if rescale_factor is not None else self.rescale_factor
          _a    	=				do_normalize if do_normalize is not None else self.do_normalize
          _a    	=				image_mean if image_mean is not None else self.image_mean
          _a    	=				image_std if image_std is not None else self.image_std

          _a    	=				size if size is not None else self.size
          _a    	=				get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase							)

          _a    	=				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 or resample is None:
               raise ValueError('''Size and resample must be specified if do_resize is True.'''							)

          if do_resize and size["shortest_edge"] < 384 and crop_pct is None:
               raise ValueError('''crop_pct must be specified if size < 384.'''							)

          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('''Image mean and std must be specified if do_normalize is True.'''							)

          # All transformations expect numpy arrays.
          _a    	=				[to_numpy_array(__UpperCAmelCase							) for image in images]

          if do_resize:
               _a    	=				[self.resize(image=__UpperCAmelCase    ,				size=__UpperCAmelCase    ,				crop_pct=__UpperCAmelCase    ,				resample=__UpperCAmelCase							) for image in images]

          if do_rescale:
               _a    	=				[self.rescale(image=__UpperCAmelCase    ,				scale=__UpperCAmelCase							) for image in images]

          if do_normalize:
               _a    	=				[self.normalize(image=__UpperCAmelCase    ,				mean=__UpperCAmelCase    ,				std=__UpperCAmelCase							) for image in images]

          _a    	=				[to_channel_dimension_format(__UpperCAmelCase    ,				__UpperCAmelCase							) for image in images]

          _a    	=				{'''pixel_values''': images}
          return BatchFeature(data=__UpperCAmelCase    ,				tensor_type=__UpperCAmelCase							)