import json
import os
from functools import lru_cache
from typing import Dict, List, Optional, Tuple, Union

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...tokenization_utils_base import BatchEncoding, EncodedInput
from ...utils import PaddingStrategy, logging


_lowercase:	List[Any]       			=		logging.get_logger(__name__)


_lowercase:	Optional[int]       			=		{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt'''}

# See all LED models at https://huggingface.co/models?filter=LED
_lowercase:	List[Any]       			=		{
    '''vocab_file''': {
        '''allenai/led-base-16384''': '''https://huggingface.co/allenai/led-base-16384/resolve/main/vocab.json''',
    },
    '''merges_file''': {
        '''allenai/led-base-16384''': '''https://huggingface.co/allenai/led-base-16384/resolve/main/merges.txt''',
    },
    '''tokenizer_file''': {
        '''allenai/led-base-16384''': '''https://huggingface.co/allenai/led-base-16384/resolve/main/tokenizer.json''',
    },
}

_lowercase:	Dict       			=		{
    '''allenai/led-base-16384''': 1_6_3_8_4,
}






@lru_cache()
# Copied from transformers.models.bart.tokenization_bart.bytes_to_unicode
def _lowerCamelCase  (		):
							_lowerCAmelCase							=							(
							    list(range(ord('!'  )     , ord('~'  ) + 1  )  ) + list(range(ord('¡'  )     , ord('¬'  ) + 1  )  ) + list(range(ord('®'  )     , ord('ÿ'  ) + 1  )  )
							)
							_lowerCAmelCase							=							bs[:]
							_lowerCAmelCase							=							0
							for b in range(2**8  ):
														if b not in bs:
																					bs.append(snake_case  )
																					cs.append(2**8 + n  )
																					n += 1
							_lowerCAmelCase							=							[chr(snake_case  ) for n in cs]
							return dict(zip(snake_case     , snake_case  )  )






def _lowerCamelCase  (		snake_case  ):
							_lowerCAmelCase							=							set()
							_lowerCAmelCase							=							word[0]
							for char in word[1:]:
														pairs.add((prev_char, char)  )
														_lowerCAmelCase							=							char
							return pairs



class        lowerCamelCase__				(   UpperCAmelCase				):
			UpperCamelCase__    							=VOCAB_FILES_NAMES
			UpperCamelCase__    							=PRETRAINED_VOCAB_FILES_MAP
			UpperCamelCase__    							=PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			UpperCamelCase__    							=["input_ids", "attention_mask"]





			def __init__(       self	:	str  ,  lowercase__	:	Tuple  ,  lowercase__	:	Any  ,  lowercase__	:	List[str]="replace"  ,  lowercase__	:	List[str]="<s>"  ,  lowercase__	:	Optional[Any]="</s>"  ,  lowercase__	:	Any="</s>"  ,  lowercase__	:	List[Any]="<s>"  ,  lowercase__	:	Union[str, Any]="<unk>"  ,  lowercase__	:	str="<pad>"  ,  lowercase__	:	Any="<mask>"  ,  lowercase__	:	List[str]=False  ,  **lowercase__	:	Tuple  ,  ):
										_lowerCAmelCase							=							AddedToken(lowercase__  ,  lstrip=lowercase__  ,  rstrip=lowercase__						) if isinstance(lowercase__  ,  lowercase__						) else bos_token
										_lowerCAmelCase							=							AddedToken(lowercase__  ,  lstrip=lowercase__  ,  rstrip=lowercase__						) if isinstance(lowercase__  ,  lowercase__						) else eos_token
										_lowerCAmelCase							=							AddedToken(lowercase__  ,  lstrip=lowercase__  ,  rstrip=lowercase__						) if isinstance(lowercase__  ,  lowercase__						) else sep_token
										_lowerCAmelCase							=							AddedToken(lowercase__  ,  lstrip=lowercase__  ,  rstrip=lowercase__						) if isinstance(lowercase__  ,  lowercase__						) else cls_token
										_lowerCAmelCase							=							AddedToken(lowercase__  ,  lstrip=lowercase__  ,  rstrip=lowercase__						) if isinstance(lowercase__  ,  lowercase__						) else unk_token
										_lowerCAmelCase							=							AddedToken(lowercase__  ,  lstrip=lowercase__  ,  rstrip=lowercase__						) if isinstance(lowercase__  ,  lowercase__						) else pad_token

										# Mask token behave like a normal word, i.e. include the space before it
										_lowerCAmelCase							=							AddedToken(lowercase__  ,  lstrip=lowercase__  ,  rstrip=lowercase__						) if isinstance(lowercase__  ,  lowercase__						) else mask_token

										super().__init__(
										    errors=lowercase__  ,  bos_token=lowercase__  ,  eos_token=lowercase__  ,  unk_token=lowercase__  ,  sep_token=lowercase__  ,  cls_token=lowercase__  ,  pad_token=lowercase__  ,  mask_token=lowercase__  ,  add_prefix_space=lowercase__  ,  **lowercase__  ,  )

										with open(lowercase__  ,  encoding='utf-8'						) as vocab_handle:
																	_lowerCAmelCase							=							json.load(lowercase__						)
										_lowerCAmelCase							=							{v: k for k, v in self.encoder.items()}
										_lowerCAmelCase							=							errors  # how to handle errors in decoding
										_lowerCAmelCase							=							bytes_to_unicode()
										_lowerCAmelCase							=							{v: k for k, v in self.byte_encoder.items()}
										with open(lowercase__  ,  encoding='utf-8'						) as merges_handle:
																	_lowerCAmelCase							=							merges_handle.read().split('\n'						)[1:-1]
										_lowerCAmelCase							=							[tuple(merge.split()						) for merge in bpe_merges]
										_lowerCAmelCase							=							dict(zip(lowercase__  ,  range(len(lowercase__						)						)						)						)
										_lowerCAmelCase							=							{}
										_lowerCAmelCase							=							add_prefix_space

										# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
										_lowerCAmelCase							=							re.compile(R'\'s|\'t|\'re|\'ve|\'m|\'ll|\'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+'						)





			@property
			# Copied from transformers.models.bart.tokenization_bart.BartTokenizer.vocab_size
			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										return len(self.encoder						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[str]						):
										return dict(self.encoder  ,  **self.added_tokens_encoder						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	int  ,  lowercase__	:	List[str]						):
										if token in self.cache:
																	return self.cache[token]
										_lowerCAmelCase							=							tuple(lowercase__						)
										_lowerCAmelCase							=							get_pairs(lowercase__						)

										if not pairs:
																	return token

										while True:
																	_lowerCAmelCase							=							min(lowercase__  ,  key=lambda lowercase__						: self.bpe_ranks.get(lowercase__  ,  float('inf'						)						)						)
																	if bigram not in self.bpe_ranks:
																								break
																	_lowerCAmelCase			,		_lowerCAmelCase							=							bigram
																	_lowerCAmelCase							=							[]
																	_lowerCAmelCase							=							0
																	while i < len(lowercase__						):
																								try:
																															_lowerCAmelCase							=							word.index(lowercase__  ,  lowercase__						)
																								except ValueError:
																															new_word.extend(word[i:]						)
																															break
																								else:
																															new_word.extend(word[i:j]						)
																															_lowerCAmelCase							=							j

																								if word[i] == first and i < len(lowercase__						) - 1 and word[i + 1] == second:
																															new_word.append(first + second						)
																															i += 2
																								else:
																															new_word.append(word[i]						)
																															i += 1
																	_lowerCAmelCase							=							tuple(lowercase__						)
																	_lowerCAmelCase							=							new_word
																	if len(lowercase__						) == 1:
																								break
																	else:
																								_lowerCAmelCase							=							get_pairs(lowercase__						)
										_lowerCAmelCase							=							' '.join(lowercase__						)
										_lowerCAmelCase							=							word
										return word





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[str]  ,  lowercase__	:	Tuple						):
										_lowerCAmelCase							=							[]
										for token in re.findall(self.pat  ,  lowercase__						):
																	_lowerCAmelCase							=							''.join(
																	    self.byte_encoder[b] for b in token.encode('utf-8'						)						)  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
																	bpe_tokens.extend(bpe_token for bpe_token in self.bpe(lowercase__						).split(' '						)						)
										return bpe_tokens





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[int]  ,  lowercase__	:	str						):
										return self.encoder.get(lowercase__  ,  self.encoder.get(self.unk_token						)						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]  ,  lowercase__	:	List[Any]						):
										return self.decoder.get(lowercase__						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]  ,  lowercase__	:	str						):
										_lowerCAmelCase							=							''.join(lowercase__						)
										_lowerCAmelCase							=							bytearray([self.byte_decoder[c] for c in text]						).decode('utf-8'  ,  errors=self.errors						)
										return text





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]  ,  lowercase__	:	str  ,  lowercase__	:	Optional[str] = None						):
										if not os.path.isdir(lowercase__						):
																	logger.error(f'Vocabulary path ({save_directory}) should be a directory'						)
																	return
										_lowerCAmelCase							=							os.path.join(
										    lowercase__  ,  (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']						)
										_lowerCAmelCase							=							os.path.join(
										    lowercase__  ,  (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['merges_file']						)

										with open(lowercase__  ,  'w'  ,  encoding='utf-8'						) as f:
																	f.write(json.dumps(self.encoder  ,  indent=2  ,  sort_keys=lowercase__  ,  ensure_ascii=lowercase__						) + '\n'						)

										_lowerCAmelCase							=							0
										with open(lowercase__  ,  'w'  ,  encoding='utf-8'						) as writer:
																	writer.write('#version: 0.2\n'						)
																	for bpe_tokens, token_index in sorted(self.bpe_ranks.items()  ,  key=lambda lowercase__						: kv[1]						):
																								if index != token_index:
																															logger.warning(
																															    f'Saving vocabulary to {merge_file}: BPE merge indices are not consecutive.'
																															    ' Please check that the tokenizer is not corrupted!'						)
																															_lowerCAmelCase							=							token_index
																								writer.write(' '.join(lowercase__						) + '\n'						)
																								index += 1

										return vocab_file, merge_file





			def   SCREAMING_SNAKE_CASE__     (       self	:	Dict  ,  lowercase__	:	List[int]  ,  lowercase__	:	Optional[List[int]] = None						):
										if token_ids_a is None:
																	return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
										_lowerCAmelCase							=							[self.cls_token_id]
										_lowerCAmelCase							=							[self.sep_token_id]
										return cls + token_ids_a + sep + sep + token_ids_a + sep





			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple  ,  lowercase__	:	List[int]  ,  lowercase__	:	Optional[List[int]] = None  ,  lowercase__	:	bool = False						):
										if already_has_special_tokens:
																	return super().get_special_tokens_mask(
																	    token_ids_a=lowercase__  ,  token_ids_a=lowercase__  ,  already_has_special_tokens=lowercase__						)

										if token_ids_a is None:
																	return [1] + ([0] * len(lowercase__						)) + [1]
										return [1] + ([0] * len(lowercase__						)) + [1, 1] + ([0] * len(lowercase__						)) + [1]





			def   SCREAMING_SNAKE_CASE__     (       self	:	Union[str, Any]  ,  lowercase__	:	List[int]  ,  lowercase__	:	Optional[List[int]] = None						):
										_lowerCAmelCase							=							[self.sep_token_id]
										_lowerCAmelCase							=							[self.cls_token_id]

										if token_ids_a is None:
																	return len(cls + token_ids_a + sep						) * [0]
										return len(cls + token_ids_a + sep + sep + token_ids_a + sep						) * [0]





			def   SCREAMING_SNAKE_CASE__     (       self	:	Dict  ,  lowercase__	:	List[Any]  ,  lowercase__	:	Optional[Any]=False  ,  **lowercase__	:	Union[str, Any]						):
										_lowerCAmelCase							=							kwargs.pop('add_prefix_space'  ,  self.add_prefix_space						)
										if (is_split_into_words or add_prefix_space) and (len(lowercase__						) > 0 and not text[0].isspace()):
																	_lowerCAmelCase							=							' ' + text
										return (text, kwargs)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Union[str, Any]  ,  lowercase__	:	Union[Dict[str, EncodedInput], BatchEncoding]  ,  lowercase__	:	Optional[int] = None  ,  lowercase__	:	PaddingStrategy = PaddingStrategy.DO_NOT_PAD  ,  lowercase__	:	Optional[int] = None  ,  lowercase__	:	Optional[bool] = None  ,  ):
										_lowerCAmelCase							=							super()._pad(
										    encoded_inputs=lowercase__  ,  max_length=lowercase__  ,  padding_strategy=lowercase__  ,  pad_to_multiple_of=lowercase__  ,  return_attention_mask=lowercase__  ,  )

										# Load from model defaults
										if return_attention_mask is None:
																	_lowerCAmelCase							=							'attention_mask' in self.model_input_names

										if return_attention_mask and "global_attention_mask" in encoded_inputs:
																	_lowerCAmelCase							=							encoded_inputs[self.model_input_names[0]]
																	# `global_attention_mask` need to have the same length as other (sequential) inputs.
																	_lowerCAmelCase							=							len(encoded_inputs['global_attention_mask']						) != len(lowercase__						)

																	if needs_to_be_padded:
																								_lowerCAmelCase							=							len(lowercase__						) - len(encoded_inputs['global_attention_mask']						)

																								if self.padding_side == "right":
																															# Use `-1` since `0` in `global_attention_mask` means `local attention` instead of `not to attend`
																															_lowerCAmelCase							=							(
																															    encoded_inputs['global_attention_mask'] + [-1] * difference
																															)
																								elif self.padding_side == "left":
																															_lowerCAmelCase							=							[-1] * difference + encoded_inputs[
																															    'global_attention_mask'
																															]
																								else:
																															raise ValueError('Invalid padding strategy:' + str(self.padding_side						)						)

										return encoded_inputs







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


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import ChineseCLIPImageProcessor



class        lowerCamelCase__				(   unittest.TestCase				):





			def __init__(       self	:	List[str]  ,  lowercase__	:	Any  ,  lowercase__	:	List[Any]=7  ,  lowercase__	:	List[str]=3  ,  lowercase__	:	str=18  ,  lowercase__	:	List[Any]=30  ,  lowercase__	:	Optional[int]=4_00  ,  lowercase__	:	Dict=True  ,  lowercase__	:	List[str]=None  ,  lowercase__	:	int=True  ,  lowercase__	:	Tuple=None  ,  lowercase__	:	int=True  ,  lowercase__	:	Tuple=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]  ,  lowercase__	:	Optional[int]=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]  ,  lowercase__	:	Any=True  ,  ):
										_lowerCAmelCase							=							size if size is not None else {'height': 2_24, 'width': 2_24}
										_lowerCAmelCase							=							crop_size if crop_size is not None else {'height': 18, 'width': 18}
										_lowerCAmelCase							=							parent
										_lowerCAmelCase							=							batch_size
										_lowerCAmelCase							=							num_channels
										_lowerCAmelCase							=							image_size
										_lowerCAmelCase							=							min_resolution
										_lowerCAmelCase							=							max_resolution
										_lowerCAmelCase							=							do_resize
										_lowerCAmelCase							=							size
										_lowerCAmelCase							=							do_center_crop
										_lowerCAmelCase							=							crop_size
										_lowerCAmelCase							=							do_normalize
										_lowerCAmelCase							=							image_mean
										_lowerCAmelCase							=							image_std
										_lowerCAmelCase							=							do_convert_rgb





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]						):
										return {
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "do_center_crop": self.do_center_crop,
										    "crop_size": self.crop_size,
										    "do_normalize": self.do_normalize,
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										    "do_convert_rgb": self.do_convert_rgb,
										}





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[str]  ,  lowercase__	:	Tuple=False  ,  lowercase__	:	List[Any]=False  ,  lowercase__	:	str=False						):
										assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

										if equal_resolution:
																	_lowerCAmelCase							=							[]
																	for i in range(self.batch_size						):
																								image_inputs.append(
																								    np.random.randint(
																								        2_55  ,  size=(self.num_channels, self.max_resolution, self.max_resolution)  ,  dtype=np.uinta						)						)
										else:
																	_lowerCAmelCase							=							[]
																	for i in range(self.batch_size						):
																								_lowerCAmelCase			,		_lowerCAmelCase							=							np.random.choice(np.arange(self.min_resolution  ,  self.max_resolution						)  ,  2						)
																								image_inputs.append(np.random.randint(2_55  ,  size=(self.num_channels, width, height)  ,  dtype=np.uinta						)						)

										if not numpify and not torchify:
																	# PIL expects the channel dimension as last dimension
																	_lowerCAmelCase							=							[Image.fromarray(np.moveaxis(lowercase__  ,  0  ,  -1						)						) for x in image_inputs]

										if torchify:
																	_lowerCAmelCase							=							[torch.from_numpy(lowercase__						) for x in image_inputs]

										return image_inputs







@require_torch
@require_vision
class        lowerCamelCase__				(   UpperCAmelCase       ,unittest.TestCase				):
			UpperCamelCase__    							=ChineseCLIPImageProcessor if is_vision_available() else None





			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										_lowerCAmelCase							=							ChineseCLIPImageProcessingTester(self  ,  do_center_crop=lowercase__						)





			@property
			def   SCREAMING_SNAKE_CASE__     (       self	:	Any						):
										return self.image_processor_tester.prepare_image_processor_dict()





			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										self.assertTrue(hasattr(lowercase__  ,  'do_resize'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'size'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_center_crop'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'center_crop'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_normalize'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'image_mean'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'image_std'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_convert_rgb'						)						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Union[str, Any]						):
										_lowerCAmelCase							=							self.image_processing_class.from_dict(self.image_processor_dict						)
										self.assertEqual(image_processor.size  ,  {'height': 2_24, 'width': 2_24}						)
										self.assertEqual(image_processor.crop_size  ,  {'height': 18, 'width': 18}						)

										_lowerCAmelCase							=							self.image_processing_class.from_dict(self.image_processor_dict  ,  size=42  ,  crop_size=84						)
										self.assertEqual(image_processor.size  ,  {'shortest_edge': 42}						)
										self.assertEqual(image_processor.crop_size  ,  {'height': 84, 'width': 84}						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]						):
										pass





			def   SCREAMING_SNAKE_CASE__     (       self	:	str						):
										# Initialize image_processing
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										# create random PIL images
										_lowerCAmelCase							=							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__						)
										for image in image_inputs:
																	self.assertIsInstance(lowercase__  ,  Image.Image						)

										# Test not batched input
										_lowerCAmelCase							=							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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )

										# Test batched
										_lowerCAmelCase							=							image_processing(lowercase__  ,  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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )





			def   SCREAMING_SNAKE_CASE__     (       self	:	Any						):
										# Initialize image_processing
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										# create random numpy tensors
										_lowerCAmelCase							=							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__  ,  numpify=lowercase__						)
										for image in image_inputs:
																	self.assertIsInstance(lowercase__  ,  np.ndarray						)

										# Test not batched input
										_lowerCAmelCase							=							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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )

										# Test batched
										_lowerCAmelCase							=							image_processing(lowercase__  ,  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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )





			def   SCREAMING_SNAKE_CASE__     (       self	:	int						):
										# Initialize image_processing
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										# create random PyTorch tensors
										_lowerCAmelCase							=							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__  ,  torchify=lowercase__						)
										for image in image_inputs:
																	self.assertIsInstance(lowercase__  ,  torch.Tensor						)

										# Test not batched input
										_lowerCAmelCase							=							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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )

										# Test batched
										_lowerCAmelCase							=							image_processing(lowercase__  ,  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.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )







@require_torch
@require_vision
class        lowerCamelCase__				(   UpperCAmelCase       ,unittest.TestCase				):
			UpperCamelCase__    							=ChineseCLIPImageProcessor if is_vision_available() else None





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]						):
										_lowerCAmelCase							=							ChineseCLIPImageProcessingTester(self  ,  num_channels=4  ,  do_center_crop=lowercase__						)
										_lowerCAmelCase							=							3





			@property
			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										return self.image_processor_tester.prepare_image_processor_dict()





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]						):
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										self.assertTrue(hasattr(lowercase__  ,  'do_resize'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'size'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_center_crop'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'center_crop'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_normalize'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'image_mean'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'image_std'						)						)
										self.assertTrue(hasattr(lowercase__  ,  'do_convert_rgb'						)						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Union[str, Any]						):
										pass





			def   SCREAMING_SNAKE_CASE__     (       self	:	Dict						):
										# Initialize image_processing
										_lowerCAmelCase							=							self.image_processing_class(**self.image_processor_dict						)
										# create random PIL images
										_lowerCAmelCase							=							self.image_processor_tester.prepare_inputs(equal_resolution=lowercase__						)
										for image in image_inputs:
																	self.assertIsInstance(lowercase__  ,  Image.Image						)

										# Test not batched input
										_lowerCAmelCase							=							image_processing(image_inputs[0]  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        1,
										        self.expected_encoded_image_num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )

										# Test batched
										_lowerCAmelCase							=							image_processing(lowercase__  ,  return_tensors='pt'						).pixel_values
										self.assertEqual(
										    encoded_images.shape  ,  (
										        self.image_processor_tester.batch_size,
										        self.expected_encoded_image_num_channels,
										        self.image_processor_tester.crop_size['height'],
										        self.image_processor_tester.crop_size['width'],
										    )  ,  )






