



'''simple docstring'''
import unittest

import numpy as np
from datasets import load_dataset

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():
					from PIL import Image

					from transformers import BeitImageProcessor






class 				lowercase__      (				unittest.TestCase  ):





	def __init__(					self   :							Union[str, Any]					,lowerCamelCase__   :							List[str]					,lowerCamelCase__   :							List[str]=7					,lowerCamelCase__   :							List[str]=3					,lowerCamelCase__   :							List[str]=18					,lowerCamelCase__   :							Any=30					,lowerCamelCase__   :							List[Any]=400					,lowerCamelCase__   :							str=True					,lowerCamelCase__   :							List[str]=None					,lowerCamelCase__   :							Optional[Any]=True					,lowerCamelCase__   :							Union[str, Any]=None					,lowerCamelCase__   :							Dict=True					,lowerCamelCase__   :							Optional[Any]=[0.5, 0.5, 0.5]					,lowerCamelCase__   :							Union[str, Any]=[0.5, 0.5, 0.5]					,lowerCamelCase__   :							Any=False					,):







							'''simple docstring'''
							_UpperCamelCase   :						List[str]												=  size if size is not None else {'height': 20, 'width': 20}
							_UpperCamelCase   :						Any												=  crop_size if crop_size is not None else {'height': 18, 'width': 18}
							_UpperCamelCase   :						str												=  parent
							_UpperCamelCase   :						int												=  batch_size
							_UpperCamelCase   :						Optional[Any]												=  num_channels
							_UpperCamelCase   :						Dict												=  image_size
							_UpperCamelCase   :						Optional[Any]												=  min_resolution
							_UpperCamelCase   :						List[str]												=  max_resolution
							_UpperCamelCase   :						Dict												=  do_resize
							_UpperCamelCase   :						Union[str, Any]												=  size
							_UpperCamelCase   :						Union[str, Any]												=  do_center_crop
							_UpperCamelCase   :						Optional[int]												=  crop_size
							_UpperCamelCase   :						str												=  do_normalize
							_UpperCamelCase   :						str												=  image_mean
							_UpperCamelCase   :						List[Any]												=  image_std
							_UpperCamelCase   :						Optional[Any]												=  do_reduce_labels





	def       UpperCamelCase_    (					self   :							List[Any]					):







							'''simple docstring'''
							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_reduce_labels": self.do_reduce_labels,
							}






def A__       (	):
						_UpperCamelCase   :						Optional[Any]												=  load_dataset('hf-internal-testing/fixtures_ade20k'    ,    split='test'				)

						_UpperCamelCase   :						int												=  Image.open(dataset[0]['file']				)
						_UpperCamelCase   :						Optional[Any]												=  Image.open(dataset[1]['file']				)

						return image, map






def A__       (	):
						_UpperCamelCase   :						Any												=  load_dataset('hf-internal-testing/fixtures_ade20k'    ,    split='test'				)

						_UpperCamelCase   :						Optional[Any]												=  Image.open(ds[0]['file']				)
						_UpperCamelCase   :						Union[str, Any]												=  Image.open(ds[1]['file']				)
						_UpperCamelCase   :						int												=  Image.open(ds[2]['file']				)
						_UpperCamelCase   :						List[str]												=  Image.open(ds[3]['file']				)

						return [imagea, imagea], [mapa, mapa]






@require_torch
@require_vision
class 				lowercase__      (				lowercase		,   unittest.TestCase  ):
	lowercase__    							=     BeitImageProcessor if is_vision_available() else None





	def       UpperCamelCase_    (					self   :							Any					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[int]												=  BeitImageProcessingTester(self					)





	@property
	def       UpperCamelCase_    (					self   :							Dict					):







							'''simple docstring'''
							return self.image_processor_tester.prepare_image_processor_dict()





	def       UpperCamelCase_    (					self   :							str					):







							'''simple docstring'''
							_UpperCamelCase   :						Dict												=  self.image_processing_class(**self.image_processor_dict					)
							self.assertTrue(hasattr(lowerCamelCase__					,'do_resize'					)					)
							self.assertTrue(hasattr(lowerCamelCase__					,'size'					)					)
							self.assertTrue(hasattr(lowerCamelCase__					,'do_center_crop'					)					)
							self.assertTrue(hasattr(lowerCamelCase__					,'center_crop'					)					)
							self.assertTrue(hasattr(lowerCamelCase__					,'do_normalize'					)					)
							self.assertTrue(hasattr(lowerCamelCase__					,'image_mean'					)					)
							self.assertTrue(hasattr(lowerCamelCase__					,'image_std'					)					)





	def       UpperCamelCase_    (					self   :							Optional[Any]					):







							'''simple docstring'''
							_UpperCamelCase   :						List[Any]												=  self.image_processing_class.from_dict(self.image_processor_dict					)
							self.assertEqual(image_processor.size					,{'height': 20, 'width': 20}					)
							self.assertEqual(image_processor.crop_size					,{'height': 18, 'width': 18}					)
							self.assertEqual(image_processor.do_reduce_labels					,lowerCamelCase__					)

							_UpperCamelCase   :						Tuple												=  self.image_processing_class.from_dict(
							    self.image_processor_dict					,size=42					,crop_size=84					,reduce_labels=lowerCamelCase__					)
							self.assertEqual(image_processor.size					,{'height': 42, 'width': 42}					)
							self.assertEqual(image_processor.crop_size					,{'height': 84, 'width': 84}					)
							self.assertEqual(image_processor.do_reduce_labels					,lowerCamelCase__					)





	def       UpperCamelCase_    (					self   :							Optional[Any]					):







							'''simple docstring'''
							pass





	def       UpperCamelCase_    (					self   :							Dict					):







							'''simple docstring'''
							# Initialize image_processing
							_UpperCamelCase   :						str												=  self.image_processing_class(**self.image_processor_dict					)
							# create random PIL images
							_UpperCamelCase   :						Union[str, Any]												=  prepare_image_inputs(self.image_processor_tester					,equal_resolution=lowerCamelCase__					)
							for image in image_inputs:
													self.assertIsInstance(lowerCamelCase__					,Image.Image					)

							# Test not batched input
							_UpperCamelCase   :						int												=  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
							_UpperCamelCase   :						Optional[int]												=  image_processing(lowerCamelCase__					,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       UpperCamelCase_    (					self   :							List[Any]					):







							'''simple docstring'''
							# Initialize image_processing
							_UpperCamelCase   :						Union[str, Any]												=  self.image_processing_class(**self.image_processor_dict					)
							# create random numpy tensors
							_UpperCamelCase   :						Optional[Any]												=  prepare_image_inputs(self.image_processor_tester					,equal_resolution=lowerCamelCase__					,numpify=lowerCamelCase__					)
							for image in image_inputs:
													self.assertIsInstance(lowerCamelCase__					,np.ndarray					)

							# Test not batched input
							_UpperCamelCase   :						Optional[int]												=  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
							_UpperCamelCase   :						Dict												=  image_processing(lowerCamelCase__					,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       UpperCamelCase_    (					self   :							Union[str, Any]					):







							'''simple docstring'''
							# Initialize image_processing
							_UpperCamelCase   :						Optional[int]												=  self.image_processing_class(**self.image_processor_dict					)
							# create random PyTorch tensors
							_UpperCamelCase   :						Tuple												=  prepare_image_inputs(self.image_processor_tester					,equal_resolution=lowerCamelCase__					,torchify=lowerCamelCase__					)
							for image in image_inputs:
													self.assertIsInstance(lowerCamelCase__					,torch.Tensor					)

							# Test not batched input
							_UpperCamelCase   :						Tuple												=  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
							_UpperCamelCase   :						List[str]												=  image_processing(lowerCamelCase__					,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       UpperCamelCase_    (					self   :							Dict					):







							'''simple docstring'''
							# Initialize image_processing
							_UpperCamelCase   :						Union[str, Any]												=  self.image_processing_class(**self.image_processor_dict					)
							# create random PyTorch tensors
							_UpperCamelCase   :						List[str]												=  prepare_image_inputs(self.image_processor_tester					,equal_resolution=lowerCamelCase__					,torchify=lowerCamelCase__					)
							_UpperCamelCase   :						List[str]												=  []
							for image in image_inputs:
													self.assertIsInstance(lowerCamelCase__					,torch.Tensor					)
													maps.append(torch.zeros(image.shape[-2:]					).long()					)

							# Test not batched input
							_UpperCamelCase   :						Tuple												=  image_processing(image_inputs[0]					,maps[0]					,return_tensors='pt'					)
							self.assertEqual(
							    encoding['pixel_values'].shape					,(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )					,)
							self.assertEqual(
							    encoding['labels'].shape					,(
							        1,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )					,)
							self.assertEqual(encoding['labels'].dtype					,torch.long					)
							self.assertTrue(encoding['labels'].min().item() >= 0					)
							self.assertTrue(encoding['labels'].max().item() <= 255					)

							# Test batched
							_UpperCamelCase   :						Optional[Any]												=  image_processing(lowerCamelCase__					,lowerCamelCase__					,return_tensors='pt'					)
							self.assertEqual(
							    encoding['pixel_values'].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'],
							    )					,)
							self.assertEqual(
							    encoding['labels'].shape					,(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )					,)
							self.assertEqual(encoding['labels'].dtype					,torch.long					)
							self.assertTrue(encoding['labels'].min().item() >= 0					)
							self.assertTrue(encoding['labels'].max().item() <= 255					)

							# Test not batched input (PIL images)
							_UpperCamelCase							,     _UpperCamelCase   :						Optional[Any]												=  prepare_semantic_single_inputs()

							_UpperCamelCase   :						int												=  image_processing(lowerCamelCase__					,lowerCamelCase__					,return_tensors='pt'					)
							self.assertEqual(
							    encoding['pixel_values'].shape					,(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )					,)
							self.assertEqual(
							    encoding['labels'].shape					,(
							        1,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )					,)
							self.assertEqual(encoding['labels'].dtype					,torch.long					)
							self.assertTrue(encoding['labels'].min().item() >= 0					)
							self.assertTrue(encoding['labels'].max().item() <= 255					)

							# Test batched input (PIL images)
							_UpperCamelCase							,     _UpperCamelCase   :						List[Any]												=  prepare_semantic_batch_inputs()

							_UpperCamelCase   :						Optional[int]												=  image_processing(lowerCamelCase__					,lowerCamelCase__					,return_tensors='pt'					)
							self.assertEqual(
							    encoding['pixel_values'].shape					,(
							        2,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )					,)
							self.assertEqual(
							    encoding['labels'].shape					,(
							        2,
							        self.image_processor_tester.crop_size['height'],
							        self.image_processor_tester.crop_size['width'],
							    )					,)
							self.assertEqual(encoding['labels'].dtype					,torch.long					)
							self.assertTrue(encoding['labels'].min().item() >= 0					)
							self.assertTrue(encoding['labels'].max().item() <= 255					)





	def       UpperCamelCase_    (					self   :							Optional[Any]					):







							'''simple docstring'''
							# Initialize image_processing
							_UpperCamelCase   :						str												=  self.image_processing_class(**self.image_processor_dict					)

							# ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
							_UpperCamelCase							,     _UpperCamelCase   :						List[Any]												=  prepare_semantic_single_inputs()
							_UpperCamelCase   :						Optional[int]												=  image_processing(lowerCamelCase__					,lowerCamelCase__					,return_tensors='pt'					)
							self.assertTrue(encoding['labels'].min().item() >= 0					)
							self.assertTrue(encoding['labels'].max().item() <= 150					)

							_UpperCamelCase   :						Dict												=  True
							_UpperCamelCase   :						Any												=  image_processing(lowerCamelCase__					,lowerCamelCase__					,return_tensors='pt'					)
							self.assertTrue(encoding['labels'].min().item() >= 0					)
							self.assertTrue(encoding['labels'].max().item() <= 255					)







'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


snake_case_					:      Union[str, Any]    			=    {
    'configuration_transfo_xl': ['TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TransfoXLConfig'],
    'tokenization_transfo_xl': ['TransfoXLCorpus', 'TransfoXLTokenizer'],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_					:      str    			=    [
					    'TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'AdaptiveEmbedding',
					    'TransfoXLForSequenceClassification',
					    'TransfoXLLMHeadModel',
					    'TransfoXLModel',
					    'TransfoXLPreTrainedModel',
					    'load_tf_weights_in_transfo_xl',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_					:      Any    			=    [
					    'TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'TFAdaptiveEmbedding',
					    'TFTransfoXLForSequenceClassification',
					    'TFTransfoXLLMHeadModel',
					    'TFTransfoXLMainLayer',
					    'TFTransfoXLModel',
					    'TFTransfoXLPreTrainedModel',
					]


if TYPE_CHECKING:
					from .configuration_transfo_xl import TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP, TransfoXLConfig
					from .tokenization_transfo_xl import TransfoXLCorpus, TransfoXLTokenizer

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_transfo_xl import (
										    TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
										    AdaptiveEmbedding,
										    TransfoXLForSequenceClassification,
										    TransfoXLLMHeadModel,
										    TransfoXLModel,
										    TransfoXLPreTrainedModel,
										    load_tf_weights_in_transfo_xl,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_transfo_xl import (
										    TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFAdaptiveEmbedding,
										    TFTransfoXLForSequenceClassification,
										    TFTransfoXLLMHeadModel,
										    TFTransfoXLMainLayer,
										    TFTransfoXLModel,
										    TFTransfoXLPreTrainedModel,
										)

else:
					import sys

					snake_case_					:      Dict    			=    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


