



from . import (
    albert,
    align,
    altclip,
    audio_spectrogram_transformer,
    auto,
    autoformer,
    bark,
    bart,
    barthez,
    bartpho,
    beit,
    bert,
    bert_generation,
    bert_japanese,
    bertweet,
    big_bird,
    bigbird_pegasus,
    biogpt,
    bit,
    blenderbot,
    blenderbot_small,
    blip,
    blip_a,
    bloom,
    bridgetower,
    byta,
    camembert,
    canine,
    chinese_clip,
    clap,
    clip,
    clipseg,
    codegen,
    conditional_detr,
    convbert,
    convnext,
    convnextva,
    cpm,
    cpmant,
    ctrl,
    cvt,
    dataavec,
    deberta,
    deberta_va,
    decision_transformer,
    deformable_detr,
    deit,
    deprecated,
    deta,
    detr,
    dialogpt,
    dinat,
    distilbert,
    dit,
    donut,
    dpr,
    dpt,
    efficientformer,
    efficientnet,
    electra,
    encodec,
    encoder_decoder,
    ernie,
    ernie_m,
    esm,
    falcon,
    flaubert,
    flava,
    fnet,
    focalnet,
    fsmt,
    funnel,
    git,
    glpn,
    gpta,
    gpt_bigcode,
    gpt_neo,
    gpt_neox,
    gpt_neox_japanese,
    gpt_swa,
    gptj,
    gptsan_japanese,
    graphormer,
    groupvit,
    herbert,
    hubert,
    ibert,
    imagegpt,
    informer,
    instructblip,
    jukebox,
    layoutlm,
    layoutlmva,
    layoutlmva,
    layoutxlm,
    led,
    levit,
    lilt,
    llama,
    longformer,
    longta,
    luke,
    lxmert,
    mam_aaa,
    marian,
    markuplm,
    maskaformer,
    maskformer,
    mbart,
    mbartaa,
    mega,
    megatron_bert,
    megatron_gpta,
    mgp_str,
    mluke,
    mobilebert,
    mobilenet_va,
    mobilenet_va,
    mobilevit,
    mobilevitva,
    mpnet,
    mra,
    mta,
    musicgen,
    mvp,
    nat,
    nezha,
    nllb,
    nllb_moe,
    nystromformer,
    oneformer,
    open_llama,
    openai,
    opt,
    owlvit,
    pegasus,
    pegasus_x,
    perceiver,
    phobert,
    pixastruct,
    plbart,
    poolformer,
    prophetnet,
    qdqbert,
    rag,
    realm,
    reformer,
    regnet,
    rembert,
    resnet,
    roberta,
    roberta_prelayernorm,
    roc_bert,
    roformer,
    rwkv,
    sam,
    segformer,
    sew,
    sew_d,
    speech_encoder_decoder,
    speech_to_text,
    speech_to_text_a,
    speechta,
    splinter,
    squeezebert,
    swiftformer,
    swin,
    swinasr,
    swinva,
    switch_transformers,
    ta,
    table_transformer,
    tapas,
    time_series_transformer,
    timesformer,
    timm_backbone,
    transfo_xl,
    trocr,
    tvlt,
    umta,
    unispeech,
    unispeech_sat,
    upernet,
    videomae,
    vilt,
    vision_encoder_decoder,
    vision_text_dual_encoder,
    visual_bert,
    vit,
    vit_hybrid,
    vit_mae,
    vit_msn,
    vivit,
    wavaveca,
    wavaveca_conformer,
    wavaveca_phoneme,
    wavaveca_with_lm,
    wavlm,
    whisper,
    x_clip,
    xglm,
    xlm,
    xlm_prophetnet,
    xlm_roberta,
    xlm_roberta_xl,
    xlnet,
    xmod,
    yolos,
    yoso,
)









import unittest

import numpy as np
import requests

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

							from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
							lowercase_								=     False

if is_vision_available():
							from PIL import Image

							from transformers import PixaStructImageProcessor
class 				_snake_case			(					unittest.TestCase):




				def __init__(						self					:						List[Any],					__lowercase					:						int,					__lowercase					:						Optional[int]=7,					__lowercase					:						List[str]=3,					__lowercase					:						Tuple=18,					__lowercase					:						List[Any]=30,					__lowercase					:						Tuple=400,					__lowercase					:						Any=None,					__lowercase					:						Optional[int]=True,					__lowercase					:						List[str]=True,					__lowercase					:						Union[str, Any]=None,					):
							lowercase__					  =				size if size is not None else {"height": 20, "width": 20}
							lowercase__					  =				parent
							lowercase__					  =				batch_size
							lowercase__					  =				num_channels
							lowercase__					  =				image_size
							lowercase__					  =				min_resolution
							lowercase__					  =				max_resolution
							lowercase__					  =				size
							lowercase__					  =				do_normalize
							lowercase__					  =				do_convert_rgb
							lowercase__					  =				[512, 1024, 2048, 4096]
							lowercase__					  =				patch_size if patch_size is not None else {"height": 16, "width": 16}




				def 							A__      (						self					:						List[str]						):
							return {"do_normalize": self.do_normalize, "do_convert_rgb": self.do_convert_rgb}




				def 							A__      (						self					:						Any						):
							lowercase__					  =				"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/australia.jpg"
							lowercase__					  =				Image.open(requests.get(__lowercase,					stream=__lowercase						).raw						).convert("RGB"						)
							return raw_image
@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11    ,	reason="""`Pix2StructImageProcessor` requires `torch>=1.11.0`."""    ,	)
@require_torch
@require_vision
class 				_snake_case			(					lowercase__    ,	unittest.TestCase):
				UpperCamelCase__				:					Any     		=PixaStructImageProcessor if is_vision_available() else None




				def 							A__      (						self					:						Any						):
							lowercase__					  =				PixaStructImageProcessingTester(self						)




				@property
				def 							A__      (						self					:						Union[str, Any]						):
							return self.image_processor_tester.prepare_image_processor_dict()




				def 							A__      (						self					:						Optional[Any]						):
							lowercase__					  =				self.image_processing_class(**self.image_processor_dict						)
							self.assertTrue(hasattr(__lowercase,					"do_normalize"						)						)
							self.assertTrue(hasattr(__lowercase,					"do_convert_rgb"						)						)




				def 							A__      (						self					:						Optional[int]						):
							lowercase__					  =				self.image_processor_tester.prepare_dummy_image()

							lowercase__					  =				self.image_processing_class(**self.image_processor_dict						)
							lowercase__					  =				2048

							lowercase__					  =				image_processor(__lowercase,					return_tensors="pt",					max_patches=__lowercase						)
							self.assertTrue(torch.allclose(inputs.flattened_patches.mean(),					torch.tensor(0.0606						),					atol=1e-3,					rtol=1e-3						)						)




				def 							A__      (						self					:						Union[str, Any]						):
							# Initialize image_processor
							lowercase__					  =				self.image_processing_class(**self.image_processor_dict						)
							# create random PIL images
							lowercase__					  =				prepare_image_inputs(self.image_processor_tester,					equal_resolution=__lowercase						)
							for image in image_inputs:
										self.assertIsInstance(__lowercase,					Image.Image						)

							# Test not batched input
							lowercase__					  =				(
							    (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
							    * self.image_processor_tester.num_channels
							) + 2

							for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										lowercase__					  =				image_processor(
										    image_inputs[0],					return_tensors="pt",					max_patches=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(1, max_patch, expected_hidden_dim),					)

										# Test batched
										lowercase__					  =				image_processor(
										    __lowercase,					return_tensors="pt",					max_patches=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim),					)




				def 							A__      (						self					:						int						):
							# Initialize image_processor
							lowercase__					  =				self.image_processing_class(**self.image_processor_dict						)
							# create random PIL images
							lowercase__					  =				prepare_image_inputs(self.image_processor_tester,					equal_resolution=__lowercase						)
							for image in image_inputs:
										self.assertIsInstance(__lowercase,					Image.Image						)

							# Test not batched input
							lowercase__					  =				(
							    (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
							    * self.image_processor_tester.num_channels
							) + 2

							lowercase__					  =				True

							for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										with self.assertRaises(__lowercase						):
													lowercase__					  =				image_processor(
													    image_inputs[0],					return_tensors="pt",					max_patches=__lowercase						).flattened_patches

										lowercase__					  =				"Hello"

										lowercase__					  =				image_processor(
										    image_inputs[0],					return_tensors="pt",					max_patches=__lowercase,					header_text=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(1, max_patch, expected_hidden_dim),					)

										# Test batched
										lowercase__					  =				image_processor(
										    __lowercase,					return_tensors="pt",					max_patches=__lowercase,					header_text=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim),					)




				def 							A__      (						self					:						Tuple						):
							# Initialize image_processor
							lowercase__					  =				self.image_processing_class(**self.image_processor_dict						)
							# create random numpy tensors
							lowercase__					  =				prepare_image_inputs(self.image_processor_tester,					equal_resolution=__lowercase,					numpify=__lowercase						)
							for image in image_inputs:
										self.assertIsInstance(__lowercase,					np.ndarray						)

							lowercase__					  =				(
							    (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
							    * self.image_processor_tester.num_channels
							) + 2

							for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										lowercase__					  =				image_processor(
										    image_inputs[0],					return_tensors="pt",					max_patches=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(1, max_patch, expected_hidden_dim),					)

										# Test batched
										lowercase__					  =				image_processor(
										    __lowercase,					return_tensors="pt",					max_patches=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim),					)




				def 							A__      (						self					:						Any						):
							# Initialize image_processor
							lowercase__					  =				self.image_processing_class(**self.image_processor_dict						)
							# create random PyTorch tensors
							lowercase__					  =				prepare_image_inputs(self.image_processor_tester,					equal_resolution=__lowercase,					torchify=__lowercase						)
							for image in image_inputs:
										self.assertIsInstance(__lowercase,					torch.Tensor						)

							# Test not batched input
							lowercase__					  =				(
							    (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
							    * self.image_processor_tester.num_channels
							) + 2

							for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										lowercase__					  =				image_processor(
										    image_inputs[0],					return_tensors="pt",					max_patches=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(1, max_patch, expected_hidden_dim),					)

										# Test batched
										lowercase__					  =				image_processor(
										    __lowercase,					return_tensors="pt",					max_patches=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim),					)
@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11    ,	reason="""`Pix2StructImageProcessor` requires `torch>=1.11.0`."""    ,	)
@require_torch
@require_vision
class 				_snake_case			(					lowercase__    ,	unittest.TestCase):
				UpperCamelCase__				:					Optional[int]     		=PixaStructImageProcessor if is_vision_available() else None




				def 							A__      (						self					:						Optional[int]						):
							lowercase__					  =				PixaStructImageProcessingTester(self,					num_channels=4						)
							lowercase__					  =				3




				@property
				def 							A__      (						self					:						Union[str, Any]						):
							return self.image_processor_tester.prepare_image_processor_dict()




				def 							A__      (						self					:						Dict						):
							lowercase__					  =				self.image_processing_class(**self.image_processor_dict						)
							self.assertTrue(hasattr(__lowercase,					"do_normalize"						)						)
							self.assertTrue(hasattr(__lowercase,					"do_convert_rgb"						)						)




				def 							A__      (						self					:						Union[str, Any]						):
							# Initialize image_processor
							lowercase__					  =				self.image_processing_class(**self.image_processor_dict						)
							# create random PIL images
							lowercase__					  =				prepare_image_inputs(self.image_processor_tester,					equal_resolution=__lowercase						)
							for image in image_inputs:
										self.assertIsInstance(__lowercase,					Image.Image						)

							# Test not batched input
							lowercase__					  =				(
							    (self.image_processor_tester.patch_size["height"] * self.image_processor_tester.patch_size["width"])
							    * (self.image_processor_tester.num_channels - 1)
							) + 2

							for max_patch in self.image_processor_tester.max_patches:
										# Test not batched input
										lowercase__					  =				image_processor(
										    image_inputs[0],					return_tensors="pt",					max_patches=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(1, max_patch, expected_hidden_dim),					)

										# Test batched
										lowercase__					  =				image_processor(
										    __lowercase,					return_tensors="pt",					max_patches=__lowercase						).flattened_patches
										self.assertEqual(
										    encoded_images.shape,					(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim),					)




