code: 
  
  '''simple docstring'''
  
  
  
  
  
  import random
  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():
  					import PIL
  
  					from transformers import FlavaImageProcessor
  					from transformers.image_utils import PILImageResampling
  					from transformers.models.flava.image_processing_flava import (
  					    FLAVA_CODEBOOK_MEAN,
  					    FLAVA_CODEBOOK_STD,
  					    FLAVA_IMAGE_MEAN,
  					    FLAVA_IMAGE_STD,
  					)
  else:
  					_lowerCAmelCase     :			List[Any]    =None
  
  class __UpperCamelCase    (							unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					def __init__(							self							,			lowerCamelCase__							,			lowerCamelCase__=7							,			lowerCamelCase__=3							,			lowerCamelCase__=3_0							,			lowerCamelCase__=4_0_0							,			lowerCamelCase__=True							,			lowerCamelCase__=None							,			lowerCamelCase__=True							,			lowerCamelCase__=None							,			lowerCamelCase__=None							,			lowerCamelCase__=True							,			lowerCamelCase__=1 / 2_5_5							,			lowerCamelCase__=True							,			lowerCamelCase__=FLAVA_IMAGE_MEAN							,			lowerCamelCase__=FLAVA_IMAGE_STD							,			lowerCamelCase__=1_4							,			lowerCamelCase__=7_5							,			lowerCamelCase__=None							,			lowerCamelCase__=1_6							,			lowerCamelCase__=0.3							,			lowerCamelCase__=None							,			lowerCamelCase__=True							,			lowerCamelCase__=None							,			lowerCamelCase__=None							,			lowerCamelCase__=True							,			lowerCamelCase__=None							,			lowerCamelCase__=True							,			lowerCamelCase__=True							,			lowerCamelCase__=FLAVA_CODEBOOK_MEAN							,			lowerCamelCase__=FLAVA_CODEBOOK_STD							,			):
  						UpperCAmelCase__:  str		       =   size if size is not None else {"height": 2_2_4, "width": 2_2_4}
  						UpperCAmelCase__:  Union[str, Any]		       =   crop_size if crop_size is not None else {"height": 2_2_4, "width": 2_2_4}
  						UpperCAmelCase__:  List[str]		       =   codebook_size if codebook_size is not None else {"height": 1_1_2, "width": 1_1_2}
  						UpperCAmelCase__:  Dict		       =   codebook_crop_size if codebook_crop_size is not None else {"height": 1_1_2, "width": 1_1_2}
  
  						UpperCAmelCase__:  Optional[int]		       =   parent
  						UpperCAmelCase__:  List[Any]		       =   batch_size
  						UpperCAmelCase__:  str		       =   num_channels
  						UpperCAmelCase__:  str		       =   do_resize
  						UpperCAmelCase__:  List[str]		       =   do_rescale
  						UpperCAmelCase__:  str		       =   rescale_factor
  						UpperCAmelCase__:  List[str]		       =   min_resolution
  						UpperCAmelCase__:  Optional[Any]		       =   max_resolution
  						UpperCAmelCase__:  Optional[int]		       =   size
  						UpperCAmelCase__:  str		       =   resample if resample is not None else PILImageResampling.BICUBIC
  						UpperCAmelCase__:  Any		       =   do_normalize
  						UpperCAmelCase__:  Dict		       =   image_mean
  						UpperCAmelCase__:  Dict		       =   image_std
  						UpperCAmelCase__:  Optional[int]		       =   do_center_crop
  						UpperCAmelCase__:  Tuple		       =   crop_size
  
  						UpperCAmelCase__:  Tuple		       =   input_size_patches
  						UpperCAmelCase__:  Any		       =   total_mask_patches
  						UpperCAmelCase__:  Union[str, Any]		       =   mask_group_max_patches
  						UpperCAmelCase__:  Optional[int]		       =   mask_group_min_patches
  						UpperCAmelCase__:  Any		       =   mask_group_min_aspect_ratio
  						UpperCAmelCase__:  Optional[int]		       =   mask_group_max_aspect_ratio
  
  						UpperCAmelCase__:  Tuple		       =   codebook_do_resize
  						UpperCAmelCase__:  Tuple		       =   codebook_size
  						UpperCAmelCase__:  Tuple		       =   codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
  						UpperCAmelCase__:  Optional[int]		       =   codebook_do_center_crop
  						UpperCAmelCase__:  Tuple		       =   codebook_crop_size
  						UpperCAmelCase__:  str		       =   codebook_do_map_pixels
  						UpperCAmelCase__:  Tuple		       =   codebook_do_normalize
  						UpperCAmelCase__:  Tuple		       =   codebook_image_mean
  						UpperCAmelCase__:  Optional[int]		       =   codebook_image_std
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						return {
  						    "image_mean": self.image_mean,
  						    "image_std": self.image_std,
  						    "do_normalize": self.do_normalize,
  						    "do_resize": self.do_resize,
  						    "size": self.size,
  						    "resample": self.resample,
  						    "do_rescale": self.do_rescale,
  						    "rescale_factor": self.rescale_factor,
  						    "do_center_crop": self.do_center_crop,
  						    "crop_size": self.crop_size,
  						    "input_size_patches": self.input_size_patches,
  						    "total_mask_patches": self.total_mask_patches,
  						    "mask_group_max_patches": self.mask_group_max_patches,
  						    "mask_group_min_patches": self.mask_group_min_patches,
  						    "mask_group_min_aspect_ratio": self.mask_group_min_aspect_ratio,
  						    "mask_group_max_aspect_ratio": self.mask_group_min_aspect_ratio,
  						    "codebook_do_resize": self.codebook_do_resize,
  						    "codebook_size": self.codebook_size,
  						    "codebook_resample": self.codebook_resample,
  						    "codebook_do_center_crop": self.codebook_do_center_crop,
  						    "codebook_crop_size": self.codebook_crop_size,
  						    "codebook_do_map_pixels": self.codebook_do_map_pixels,
  						    "codebook_do_normalize": self.codebook_do_normalize,
  						    "codebook_image_mean": self.codebook_image_mean,
  						    "codebook_image_std": self.codebook_image_std,
  						}
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						return (self.size["height"], self.size["width"])
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						return (
  						    (self.input_size_patches, self.input_size_patches)
  						    if not isinstance(self.input_size_patches							,			UpperCamelCase_	)
  						    else self.input_size_patches
  						)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						return (self.codebook_size["height"], self.codebook_size["width"])
  
  @require_torch
  @require_vision
  class __UpperCamelCase    (							_a				,unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					__magic_name__     			=      FlavaImageProcessor if is_vision_available() else None
  					__magic_name__     			=      None
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[str]		       =   FlavaImageProcessingTester(self	)
  
  
  
  
  
  					@property
  					def       _UpperCAmelCase						(							self	):
  						return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Dict		       =   self.image_processing_class(**self.image_processor_dict	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"image_mean"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"image_std"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"do_normalize"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"do_resize"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"resample"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"crop_size"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"do_center_crop"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"do_rescale"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"rescale_factor"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"masking_generator"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"codebook_do_resize"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"codebook_size"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"codebook_resample"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"codebook_do_center_crop"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"codebook_crop_size"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"codebook_do_map_pixels"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"codebook_do_normalize"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"codebook_image_mean"	)	)
  						self.assertTrue(hasattr(UpperCamelCase_							,			"codebook_image_std"	)	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Dict		       =   self.image_processing_class.from_dict(self.image_processor_dict	)
  						self.assertEqual(image_processor.size							,			{"height": 2_2_4, "width": 2_2_4}	)
  						self.assertEqual(image_processor.crop_size							,			{"height": 2_2_4, "width": 2_2_4}	)
  						self.assertEqual(image_processor.codebook_size							,			{"height": 1_1_2, "width": 1_1_2}	)
  						self.assertEqual(image_processor.codebook_crop_size							,			{"height": 1_1_2, "width": 1_1_2}	)
  
  						UpperCAmelCase__:  Any		       =   self.image_processing_class.from_dict(
  						    self.image_processor_dict							,			size=4_2							,			crop_size=8_4							,			codebook_size=3_3							,			codebook_crop_size=6_6	)
  						self.assertEqual(image_processor.size							,			{"height": 4_2, "width": 4_2}	)
  						self.assertEqual(image_processor.crop_size							,			{"height": 8_4, "width": 8_4}	)
  						self.assertEqual(image_processor.codebook_size							,			{"height": 3_3, "width": 3_3}	)
  						self.assertEqual(image_processor.codebook_crop_size							,			{"height": 6_6, "width": 6_6}	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						pass
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						# Initialize image_processing
  						UpperCAmelCase__:  Tuple		       =   self.image_processing_class(**self.image_processor_dict	)
  						# create random PIL images
  						UpperCAmelCase__:  Tuple		       =   prepare_image_inputs(self.image_processor_tester							,			equal_resolution=UpperCamelCase_	)
  						for image in image_inputs:
  							self.assertIsInstance(UpperCamelCase_							,			PIL.Image.Image	)
  
  						# Test not batched input
  						UpperCAmelCase__:  int		       =   image_processing(image_inputs[0]							,			return_tensors="pt"	)
  
  						# Test no bool masked pos
  						self.assertFalse("bool_masked_pos" in encoded_images	)
  
  						UpperCAmelCase__       ,	UpperCAmelCase__:  int		       =   self.image_processor_tester.get_expected_image_size()
  
  						self.assertEqual(
  						    encoded_images.pixel_values.shape							,			(1, self.image_processor_tester.num_channels, expected_height, expected_width)							,			)
  
  						# Test batched
  						UpperCAmelCase__:  Optional[Any]		       =   image_processing(UpperCamelCase_							,			return_tensors="pt"	)
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Optional[int]		       =   self.image_processor_tester.get_expected_image_size()
  
  						# Test no bool masked pos
  						self.assertFalse("bool_masked_pos" in encoded_images	)
  
  						self.assertEqual(
  						    encoded_images.pixel_values.shape							,			(
  						        self.image_processor_tester.batch_size,
  						        self.image_processor_tester.num_channels,
  						        expected_height,
  						        expected_width,
  						    )							,			)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__	):
  						# Initialize image_processing
  						UpperCAmelCase__:  Union[str, Any]		       =   self.image_processing_class(**self.image_processor_dict	)
  						# create random tensors
  						UpperCAmelCase__:  str		       =   prepare_image_inputs(self.image_processor_tester							,			equal_resolution=UpperCamelCase_							,			**UpperCamelCase_	)
  						for image in image_inputs:
  							self.assertIsInstance(UpperCamelCase_							,			UpperCamelCase_	)
  
  						# Test not batched input
  						UpperCAmelCase__:  List[str]		       =   image_processing(image_inputs[0]							,			return_tensors="pt"	)
  
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Union[str, Any]		       =   self.image_processor_tester.get_expected_image_size()
  						self.assertEqual(
  						    encoded_images.pixel_values.shape							,			(1, self.image_processor_tester.num_channels, expected_height, expected_width)							,			)
  
  						UpperCAmelCase__:  Optional[Any]		       =   image_processing(UpperCamelCase_							,			return_image_mask=UpperCamelCase_							,			return_tensors="pt"	)
  
  						UpperCAmelCase__       ,	UpperCAmelCase__:  str		       =   self.image_processor_tester.get_expected_image_size()
  						self.assertEqual(
  						    encoded_images.pixel_values.shape							,			(
  						        self.image_processor_tester.batch_size,
  						        self.image_processor_tester.num_channels,
  						        expected_height,
  						        expected_width,
  						    )							,			)
  
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Dict		       =   self.image_processor_tester.get_expected_mask_size()
  						self.assertEqual(
  						    encoded_images.bool_masked_pos.shape							,			(
  						        self.image_processor_tester.batch_size,
  						        expected_height,
  						        expected_width,
  						    )							,			)
  
  						# Test batched
  						UpperCAmelCase__:  Tuple		       =   image_processing(UpperCamelCase_							,			return_tensors="pt"	).pixel_values
  
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Optional[Any]		       =   self.image_processor_tester.get_expected_image_size()
  						self.assertEqual(
  						    encoded_images.shape							,			(
  						        self.image_processor_tester.batch_size,
  						        self.image_processor_tester.num_channels,
  						        expected_height,
  						        expected_width,
  						    )							,			)
  
  						# Test masking
  						UpperCAmelCase__:  Optional[Any]		       =   image_processing(UpperCamelCase_							,			return_image_mask=UpperCamelCase_							,			return_tensors="pt"	)
  
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Dict		       =   self.image_processor_tester.get_expected_image_size()
  						self.assertEqual(
  						    encoded_images.pixel_values.shape							,			(
  						        self.image_processor_tester.batch_size,
  						        self.image_processor_tester.num_channels,
  						        expected_height,
  						        expected_width,
  						    )							,			)
  
  						UpperCAmelCase__       ,	UpperCAmelCase__:  str		       =   self.image_processor_tester.get_expected_mask_size()
  						self.assertEqual(
  						    encoded_images.bool_masked_pos.shape							,			(
  						        self.image_processor_tester.batch_size,
  						        expected_height,
  						        expected_width,
  						    )							,			)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						self._test_call_framework(np.ndarray							,			prepare_kwargs={"numpify": True}	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						self._test_call_framework(torch.Tensor							,			prepare_kwargs={"torchify": True}	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						# Initialize image_processing
  						random.seed(1_2_3_4	)
  						UpperCAmelCase__:  Optional[Any]		       =   self.image_processing_class(**self.image_processor_dict	)
  						UpperCAmelCase__:  Optional[Any]		       =   prepare_image_inputs(self.image_processor_tester							,			equal_resolution=UpperCamelCase_							,			torchify=UpperCamelCase_	)
  
  						# Test not batched input
  						UpperCAmelCase__:  Dict		       =   image_processing(image_inputs[0]							,			return_image_mask=UpperCamelCase_							,			return_tensors="pt"	)
  						self.assertEqual(encoded_images.bool_masked_pos.sum().item()							,			7_5	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						# Initialize image_processing
  						UpperCAmelCase__:  str		       =   self.image_processing_class(**self.image_processor_dict	)
  						# create random PIL images
  						UpperCAmelCase__:  int		       =   prepare_image_inputs(self.image_processor_tester							,			equal_resolution=UpperCamelCase_	)
  						for image in image_inputs:
  							self.assertIsInstance(UpperCamelCase_							,			PIL.Image.Image	)
  
  						# Test not batched input
  						UpperCAmelCase__:  Optional[int]		       =   image_processing(image_inputs[0]							,			return_codebook_pixels=UpperCamelCase_							,			return_tensors="pt"	)
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Any		       =   self.image_processor_tester.get_expected_codebook_image_size()
  						self.assertEqual(
  						    encoded_images.codebook_pixel_values.shape							,			(1, self.image_processor_tester.num_channels, expected_height, expected_width)							,			)
  
  						# Test batched
  						UpperCAmelCase__:  Optional[Any]		       =   image_processing(UpperCamelCase_							,			return_codebook_pixels=UpperCamelCase_							,			return_tensors="pt"	)
  						UpperCAmelCase__       ,	UpperCAmelCase__:  str		       =   self.image_processor_tester.get_expected_codebook_image_size()
  						self.assertEqual(
  						    encoded_images.codebook_pixel_values.shape							,			(
  						        self.image_processor_tester.batch_size,
  						        self.image_processor_tester.num_channels,
  						        expected_height,
  						        expected_width,
  						    )							,			)
style_context: 
  
  import json
  import os
  import random
  import shutil
  import tempfile
  import unittest
  
  import numpy as np
  import pytest
  
  from transformers import BertTokenizer, BertTokenizerFast
  from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
  from transformers.testing_utils import require_vision
  from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available
  
  
  if is_vision_available():
  					from PIL import Image
  
  					from transformers import FlavaImageProcessor, FlavaProcessor
  					from transformers.models.flava.image_processing_flava import (
  					    FLAVA_CODEBOOK_MEAN,
  					    FLAVA_CODEBOOK_STD,
  					    FLAVA_IMAGE_MEAN,
  					    FLAVA_IMAGE_STD,
  					)
  
  @require_vision
  class __UpperCamelCase    (							unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Optional[int]		       =   tempfile.mkdtemp()
  
  						# fmt: off
  						UpperCAmelCase__:  Optional[Any]		       =   ["[UNK]", "[CLS]", "[SEP]", "[PAD]", "[MASK]", "want", "##want", "##ed", "wa", "un", "runn", "##ing", ",", "low", "lowest"]
  						# fmt: on
  						UpperCAmelCase__:  str		       =   os.path.join(self.tmpdirname							,			VOCAB_FILES_NAMES["vocab_file"]	)
  
  						with open(self.vocab_file							,			"w"							,			encoding="utf-8"	) as fp:
  							fp.write("".join([x + "\n" for x in vocab_tokens]	)	)
  
  						UpperCAmelCase__:  Tuple		       =   {
  						    "image_mean": FLAVA_IMAGE_MEAN,
  						    "image_std": FLAVA_IMAGE_STD,
  						    "do_normalize": True,
  						    "do_resize": True,
  						    "size": 2_2_4,
  						    "do_center_crop": True,
  						    "crop_size": 2_2_4,
  						    "input_size_patches": 1_4,
  						    "total_mask_patches": 7_5,
  						    "mask_group_max_patches": None,
  						    "mask_group_min_patches": 1_6,
  						    "mask_group_min_aspect_ratio": 0.3,
  						    "mask_group_max_aspect_ratio": None,
  						    "codebook_do_resize": True,
  						    "codebook_size": 1_1_2,
  						    "codebook_do_center_crop": True,
  						    "codebook_crop_size": 1_1_2,
  						    "codebook_do_map_pixels": True,
  						    "codebook_do_normalize": True,
  						    "codebook_image_mean": FLAVA_CODEBOOK_MEAN,
  						    "codebook_image_std": FLAVA_CODEBOOK_STD,
  						}
  
  						UpperCAmelCase__:  Tuple		       =   os.path.join(self.tmpdirname							,			lowerCamelCase__	)
  						with open(self.image_processor_file							,			"w"							,			encoding="utf-8"	) as fp:
  							json.dump(lowerCamelCase__							,			lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			**lowerCamelCase__	):
  						return BertTokenizer.from_pretrained(self.tmpdirname							,			**lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			**lowerCamelCase__	):
  						return BertTokenizerFast.from_pretrained(self.tmpdirname							,			**lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self							,			**lowerCamelCase__	):
  						return FlavaImageProcessor.from_pretrained(self.tmpdirname							,			**lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						shutil.rmtree(self.tmpdirname	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Dict		       =   [np.random.randint(2_5_5							,			size=(3, 3_0, 4_0_0)							,			dtype=np.uinta	)]
  
  						UpperCAmelCase__:  Any		       =   [Image.fromarray(np.moveaxis(lowerCamelCase__							,			0							,			-1	)	) for x in image_inputs]
  
  						return image_inputs
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  int		       =   self.get_tokenizer()
  						UpperCAmelCase__:  Any		       =   self.get_rust_tokenizer()
  						UpperCAmelCase__:  List[Any]		       =   self.get_image_processor()
  
  						UpperCAmelCase__:  Tuple		       =   FlavaProcessor(tokenizer=lowerCamelCase__							,			image_processor=lowerCamelCase__	)
  						processor_slow.save_pretrained(self.tmpdirname	)
  						UpperCAmelCase__:  Dict		       =   FlavaProcessor.from_pretrained(self.tmpdirname							,			use_fast=lowerCamelCase__	)
  
  						UpperCAmelCase__:  Union[str, Any]		       =   FlavaProcessor(tokenizer=lowerCamelCase__							,			image_processor=lowerCamelCase__	)
  						processor_fast.save_pretrained(self.tmpdirname	)
  						UpperCAmelCase__:  int		       =   FlavaProcessor.from_pretrained(self.tmpdirname	)
  
  						self.assertEqual(processor_slow.tokenizer.get_vocab()							,			tokenizer_slow.get_vocab()	)
  						self.assertEqual(processor_fast.tokenizer.get_vocab()							,			tokenizer_fast.get_vocab()	)
  						self.assertEqual(tokenizer_slow.get_vocab()							,			tokenizer_fast.get_vocab()	)
  						self.assertIsInstance(processor_slow.tokenizer							,			lowerCamelCase__	)
  						self.assertIsInstance(processor_fast.tokenizer							,			lowerCamelCase__	)
  
  						self.assertEqual(processor_slow.image_processor.to_json_string()							,			image_processor.to_json_string()	)
  						self.assertEqual(processor_fast.image_processor.to_json_string()							,			image_processor.to_json_string()	)
  						self.assertIsInstance(processor_slow.image_processor							,			lowerCamelCase__	)
  						self.assertIsInstance(processor_fast.image_processor							,			lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Any		       =   FlavaProcessor(tokenizer=self.get_tokenizer()							,			image_processor=self.get_image_processor()	)
  						processor.save_pretrained(self.tmpdirname	)
  
  						UpperCAmelCase__:  Any		       =   self.get_tokenizer(bos_token="(BOS)"							,			eos_token="(EOS)"	)
  						UpperCAmelCase__:  str		       =   self.get_image_processor(do_normalize=lowerCamelCase__							,			padding_value=1.0	)
  
  						UpperCAmelCase__:  str		       =   FlavaProcessor.from_pretrained(
  						    self.tmpdirname							,			bos_token="(BOS)"							,			eos_token="(EOS)"							,			do_normalize=lowerCamelCase__							,			padding_value=1.0	)
  
  						self.assertEqual(processor.tokenizer.get_vocab()							,			tokenizer_add_kwargs.get_vocab()	)
  						self.assertIsInstance(processor.tokenizer							,			lowerCamelCase__	)
  
  						self.assertEqual(processor.image_processor.to_json_string()							,			image_processor_add_kwargs.to_json_string()	)
  						self.assertIsInstance(processor.image_processor							,			lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  int		       =   self.get_image_processor()
  						UpperCAmelCase__:  Optional[Any]		       =   self.get_tokenizer()
  
  						UpperCAmelCase__:  Optional[Any]		       =   FlavaProcessor(tokenizer=lowerCamelCase__							,			image_processor=lowerCamelCase__	)
  
  						UpperCAmelCase__:  Optional[int]		       =   self.prepare_image_inputs()
  
  						UpperCAmelCase__:  Tuple		       =   image_processor(lowerCamelCase__							,			return_tensors="np"	)
  						UpperCAmelCase__:  str		       =   processor(images=lowerCamelCase__							,			return_tensors="np"	)
  
  						for key in input_feat_extract.keys():
  							self.assertAlmostEqual(input_feat_extract[key].sum()							,			input_processor[key].sum()							,			delta=1e-2	)
  
  						# With rest of the args
  						random.seed(1_2_3_4	)
  						UpperCAmelCase__:  Optional[int]		       =   image_processor(
  						    lowerCamelCase__							,			return_image_mask=lowerCamelCase__							,			return_codebook_pixels=lowerCamelCase__							,			return_tensors="np"	)
  						random.seed(1_2_3_4	)
  						UpperCAmelCase__:  Tuple		       =   processor(
  						    images=lowerCamelCase__							,			return_image_mask=lowerCamelCase__							,			return_codebook_pixels=lowerCamelCase__							,			return_tensors="np"	)
  
  						for key in input_feat_extract.keys():
  							self.assertAlmostEqual(input_feat_extract[key].sum()							,			input_processor[key].sum()							,			delta=1e-2	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Dict		       =   self.get_image_processor()
  						UpperCAmelCase__:  str		       =   self.get_tokenizer()
  
  						UpperCAmelCase__:  List[str]		       =   FlavaProcessor(tokenizer=lowerCamelCase__							,			image_processor=lowerCamelCase__	)
  
  						UpperCAmelCase__:  Union[str, Any]		       =   "lower newer"
  
  						UpperCAmelCase__:  Optional[Any]		       =   processor(text=lowerCamelCase__	)
  
  						UpperCAmelCase__:  Optional[Any]		       =   tokenizer(lowerCamelCase__	)
  
  						for key in encoded_tok.keys():
  							self.assertListEqual(encoded_tok[key]							,			encoded_processor[key]	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[Any]		       =   self.get_image_processor()
  						UpperCAmelCase__:  int		       =   self.get_tokenizer()
  
  						UpperCAmelCase__:  str		       =   FlavaProcessor(tokenizer=lowerCamelCase__							,			image_processor=lowerCamelCase__	)
  
  						UpperCAmelCase__:  Any		       =   "lower newer"
  						UpperCAmelCase__:  Any		       =   self.prepare_image_inputs()
  
  						UpperCAmelCase__:  Optional[int]		       =   processor(text=lowerCamelCase__							,			images=lowerCamelCase__	)
  
  						self.assertListEqual(list(inputs.keys()	)							,			["input_ids", "token_type_ids", "attention_mask", "pixel_values"]	)
  
  						# add extra args
  						UpperCAmelCase__:  str		       =   processor(text=lowerCamelCase__							,			images=lowerCamelCase__							,			return_codebook_pixels=lowerCamelCase__							,			return_image_mask=lowerCamelCase__	)
  
  						self.assertListEqual(
  						    list(inputs.keys()	)							,			[
  						        "input_ids",
  						        "token_type_ids",
  						        "attention_mask",
  						        "pixel_values",
  						        "codebook_pixel_values",
  						        "bool_masked_pos",
  						    ]							,			)
  
  						# test if it raises when no input is passed
  						with pytest.raises(lowerCamelCase__	):
  							processor()
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Optional[Any]		       =   self.get_image_processor()
  						UpperCAmelCase__:  List[Any]		       =   self.get_tokenizer()
  
  						UpperCAmelCase__:  Any		       =   FlavaProcessor(tokenizer=lowerCamelCase__							,			image_processor=lowerCamelCase__	)
  
  						UpperCAmelCase__:  List[Any]		       =   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
  						UpperCAmelCase__:  str		       =   processor.batch_decode(lowerCamelCase__	)
  						UpperCAmelCase__:  Dict		       =   tokenizer.batch_decode(lowerCamelCase__	)
  
  						self.assertListEqual(lowerCamelCase__							,			lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[str]		       =   self.get_image_processor()
  						UpperCAmelCase__:  Dict		       =   self.get_tokenizer()
  
  						UpperCAmelCase__:  Tuple		       =   FlavaProcessor(tokenizer=lowerCamelCase__							,			image_processor=lowerCamelCase__	)
  
  						UpperCAmelCase__:  Optional[Any]		       =   "lower newer"
  						UpperCAmelCase__:  Dict		       =   self.prepare_image_inputs()
  
  						UpperCAmelCase__:  int		       =   processor(text=lowerCamelCase__							,			images=lowerCamelCase__	)
  
  						self.assertListEqual(list(inputs.keys()	)							,			processor.model_input_names	)