code: 
  
  
  
  
  
  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 SegformerImageProcessor
  
  
  
  
  
  
  class 	UpperCamelCase_     (     unittest.TestCase       ):
  
  
  
  					def __init__(		self    :    Tuple					,			lowerCamelCase    :    Optional[int]					,			lowerCamelCase    :    Union[str, Any]=7					,			lowerCamelCase    :    Tuple=3					,			lowerCamelCase    :    List[Any]=30					,			lowerCamelCase    :    str=4_00					,			lowerCamelCase    :    Optional[int]=True					,			lowerCamelCase    :    List[str]=None					,			lowerCamelCase    :    Dict=True					,			lowerCamelCase    :    Optional[int]=[0.5, 0.5, 0.5]					,			lowerCamelCase    :    Union[str, Any]=[0.5, 0.5, 0.5]					,			lowerCamelCase    :    Optional[int]=False					,			):
  							lowerCamelCase_  :    Dict   	=			size if size is not None else {'height': 30, 'width': 30}
  							lowerCamelCase_  :    Optional[Any]   	=			parent
  							lowerCamelCase_  :    List[str]   	=			batch_size
  							lowerCamelCase_  :    Any   	=			num_channels
  							lowerCamelCase_  :    Optional[int]   	=			min_resolution
  							lowerCamelCase_  :    List[str]   	=			max_resolution
  							lowerCamelCase_  :    str   	=			do_resize
  							lowerCamelCase_  :    Union[str, Any]   	=			size
  							lowerCamelCase_  :    Optional[int]   	=			do_normalize
  							lowerCamelCase_  :    Any   	=			image_mean
  							lowerCamelCase_  :    Dict   	=			image_std
  							lowerCamelCase_  :    List[str]   	=			do_reduce_labels
  
  
  
  
  
  					def      __a    (		self    :    Dict	):
  							return {
  							    "do_resize": self.do_resize,
  							    "size": self.size,
  							    "do_normalize": self.do_normalize,
  							    "image_mean": self.image_mean,
  							    "image_std": self.image_std,
  							    "do_reduce_labels": self.do_reduce_labels,
  							}
  
  
  def 		_SCREAMING_SNAKE_CASE    (   ):
  		lowerCamelCase_  :    str   	=			load_dataset('hf-internal-testing/fixtures_ade20k'       ,split='test'	)
  
  		lowerCamelCase_  :    List[str]   	=			Image.open(dataset[0]['file']	)
  		lowerCamelCase_  :    List[Any]   	=			Image.open(dataset[1]['file']	)
  
  		return image, map
  
  
  def 		_SCREAMING_SNAKE_CASE    (   ):
  		lowerCamelCase_  :    str   	=			load_dataset('hf-internal-testing/fixtures_ade20k'       ,split='test'	)
  
  		lowerCamelCase_  :    Any   	=			Image.open(dataset[0]['file']	)
  		lowerCamelCase_  :    str   	=			Image.open(dataset[1]['file']	)
  		lowerCamelCase_  :    Optional[int]   	=			Image.open(dataset[2]['file']	)
  		lowerCamelCase_  :    Dict   	=			Image.open(dataset[3]['file']	)
  
  		return [imagea, imagea], [mapa, mapa]
  
  
  
  
  
  
  @require_torch
  @require_vision
  class 	UpperCamelCase_     (     _SCREAMING_SNAKE_CASE     ,    unittest.TestCase       ):
  					_a			:	Optional[int]							=				SegformerImageProcessor if is_vision_available() else None
  
  
  
  					def      __a    (		self    :    Optional[Any]	):
  							lowerCamelCase_  :    List[Any]   	=			SegformerImageProcessingTester(self	)
  
  
  
  					@property
  					def      __a    (		self    :    Any	):
  							return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  					def      __a    (		self    :    Union[str, Any]	):
  							lowerCamelCase_  :    Dict   	=			self.image_processing_class(**self.image_processor_dict	)
  							self.assertTrue(hasattr(__A					,			'do_resize'	)	)
  							self.assertTrue(hasattr(__A					,			'size'	)	)
  							self.assertTrue(hasattr(__A					,			'do_normalize'	)	)
  							self.assertTrue(hasattr(__A					,			'image_mean'	)	)
  							self.assertTrue(hasattr(__A					,			'image_std'	)	)
  							self.assertTrue(hasattr(__A					,			'do_reduce_labels'	)	)
  
  
  
  					def      __a    (		self    :    Dict	):
  							lowerCamelCase_  :    List[Any]   	=			self.image_processing_class.from_dict(self.image_processor_dict	)
  							self.assertEqual(image_processor.size					,			{'height': 30, 'width': 30}	)
  							self.assertEqual(image_processor.do_reduce_labels					,			__A	)
  
  							lowerCamelCase_  :    Any   	=			self.image_processing_class.from_dict(self.image_processor_dict					,			size=42					,			reduce_labels=__A	)
  							self.assertEqual(image_processor.size					,			{'height': 42, 'width': 42}	)
  							self.assertEqual(image_processor.do_reduce_labels					,			__A	)
  
  
  
  					def      __a    (		self    :    List[Any]	):
  							pass
  
  
  
  					def      __a    (		self    :    Union[str, Any]	):
  							# Initialize image_processing
  							lowerCamelCase_  :    Union[str, Any]   	=			self.image_processing_class(**self.image_processor_dict	)
  							# create random PIL images
  							lowerCamelCase_  :    List[Any]   	=			prepare_image_inputs(self.image_processor_tester					,			equal_resolution=__A	)
  							for image in image_inputs:
  									self.assertIsInstance(__A					,			Image.Image	)
  
  							# Test not batched input
  							lowerCamelCase_  :    List[str]   	=			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.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  
  							# Test batched
  							lowerCamelCase_  :    Tuple   	=			image_processing(__A					,			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.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  
  
  
  					def      __a    (		self    :    Optional[int]	):
  							# Initialize image_processing
  							lowerCamelCase_  :    List[str]   	=			self.image_processing_class(**self.image_processor_dict	)
  							# create random numpy tensors
  							lowerCamelCase_  :    Optional[Any]   	=			prepare_image_inputs(self.image_processor_tester					,			equal_resolution=__A					,			numpify=__A	)
  							for image in image_inputs:
  									self.assertIsInstance(__A					,			np.ndarray	)
  
  							# Test not batched input
  							lowerCamelCase_  :    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.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  
  							# Test batched
  							lowerCamelCase_  :    Dict   	=			image_processing(__A					,			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.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  
  
  
  					def      __a    (		self    :    Dict	):
  							# Initialize image_processing
  							lowerCamelCase_  :    str   	=			self.image_processing_class(**self.image_processor_dict	)
  							# create random PyTorch tensors
  							lowerCamelCase_  :    Union[str, Any]   	=			prepare_image_inputs(self.image_processor_tester					,			equal_resolution=__A					,			torchify=__A	)
  							for image in image_inputs:
  									self.assertIsInstance(__A					,			torch.Tensor	)
  
  							# Test not batched input
  							lowerCamelCase_  :    List[str]   	=			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.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  
  							# Test batched
  							lowerCamelCase_  :    List[str]   	=			image_processing(__A					,			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.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  
  
  
  					def      __a    (		self    :    int	):
  							# Initialize image_processing
  							lowerCamelCase_  :    Optional[int]   	=			self.image_processing_class(**self.image_processor_dict	)
  							# create random PyTorch tensors
  							lowerCamelCase_  :    int   	=			prepare_image_inputs(self.image_processor_tester					,			equal_resolution=__A					,			torchify=__A	)
  							lowerCamelCase_  :    Any   	=			[]
  							for image in image_inputs:
  									self.assertIsInstance(__A					,			torch.Tensor	)
  									maps.append(torch.zeros(image.shape[-2:]	).long()	)
  
  							# Test not batched input
  							lowerCamelCase_  :    Union[str, Any]   	=			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.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  							self.assertEqual(
  							    encoding['labels'].shape					,			(
  							        1,
  							        self.image_processor_tester.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  							self.assertEqual(encoding['labels'].dtype					,			torch.long	)
  							self.assertTrue(encoding['labels'].min().item() >= 0	)
  							self.assertTrue(encoding['labels'].max().item() <= 2_55	)
  
  							# Test batched
  							lowerCamelCase_  :    Tuple   	=			image_processing(__A					,			__A					,			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.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  							self.assertEqual(
  							    encoding['labels'].shape					,			(
  							        self.image_processor_tester.batch_size,
  							        self.image_processor_tester.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  							self.assertEqual(encoding['labels'].dtype					,			torch.long	)
  							self.assertTrue(encoding['labels'].min().item() >= 0	)
  							self.assertTrue(encoding['labels'].max().item() <= 2_55	)
  
  							# Test not batched input (PIL images)
  							lowerCamelCase_	,			lowerCamelCase_  :    Optional[Any]   	=			prepare_semantic_single_inputs()
  
  							lowerCamelCase_  :    Any   	=			image_processing(__A					,			__A					,			return_tensors='pt'	)
  							self.assertEqual(
  							    encoding['pixel_values'].shape					,			(
  							        1,
  							        self.image_processor_tester.num_channels,
  							        self.image_processor_tester.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  							self.assertEqual(
  							    encoding['labels'].shape					,			(
  							        1,
  							        self.image_processor_tester.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  							self.assertEqual(encoding['labels'].dtype					,			torch.long	)
  							self.assertTrue(encoding['labels'].min().item() >= 0	)
  							self.assertTrue(encoding['labels'].max().item() <= 2_55	)
  
  							# Test batched input (PIL images)
  							lowerCamelCase_	,			lowerCamelCase_  :    Dict   	=			prepare_semantic_batch_inputs()
  
  							lowerCamelCase_  :    Tuple   	=			image_processing(__A					,			__A					,			return_tensors='pt'	)
  							self.assertEqual(
  							    encoding['pixel_values'].shape					,			(
  							        2,
  							        self.image_processor_tester.num_channels,
  							        self.image_processor_tester.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  							self.assertEqual(
  							    encoding['labels'].shape					,			(
  							        2,
  							        self.image_processor_tester.size['height'],
  							        self.image_processor_tester.size['width'],
  							    )					,			)
  							self.assertEqual(encoding['labels'].dtype					,			torch.long	)
  							self.assertTrue(encoding['labels'].min().item() >= 0	)
  							self.assertTrue(encoding['labels'].max().item() <= 2_55	)
  
  
  
  
  
  					def      __a    (		self    :    int	):
  							# Initialize image_processing
  							lowerCamelCase_  :    List[Any]   	=			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
  							lowerCamelCase_	,			lowerCamelCase_  :    Optional[Any]   	=			prepare_semantic_single_inputs()
  							lowerCamelCase_  :    Optional[Any]   	=			image_processing(__A					,			__A					,			return_tensors='pt'	)
  							self.assertTrue(encoding['labels'].min().item() >= 0	)
  							self.assertTrue(encoding['labels'].max().item() <= 1_50	)
  
  							lowerCamelCase_  :    Union[str, Any]   	=			True
  							lowerCamelCase_  :    int   	=			image_processing(__A					,			__A					,			return_tensors='pt'	)
  							self.assertTrue(encoding['labels'].min().item() >= 0	)
  							self.assertTrue(encoding['labels'].max().item() <= 2_55	)
  
style_context: 
  
  
  
  
  
  from typing import TYPE_CHECKING
  
  from ...utils import (
      OptionalDependencyNotAvailable,
      _LazyModule,
      is_flax_available,
      is_sentencepiece_available,
      is_tf_available,
      is_tokenizers_available,
      is_torch_available,
  )
  
  
  _lowercase		:     int 					={
      """configuration_marian""": ["""MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MarianConfig""", """MarianOnnxConfig"""],
  }
  
  try:
  		if not is_sentencepiece_available():
  				raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  		pass
  else:
  		_lowercase		:     Any 					=["""MarianTokenizer"""]
  
  try:
  		if not is_torch_available():
  				raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  		pass
  else:
  		_lowercase		:     Any 					=[
  		    """MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST""",
  		    """MarianForCausalLM""",
  		    """MarianModel""",
  		    """MarianMTModel""",
  		    """MarianPreTrainedModel""",
  		]
  
  try:
  		if not is_tf_available():
  				raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  		pass
  else:
  		_lowercase		:     Dict 					=["""TFMarianModel""", """TFMarianMTModel""", """TFMarianPreTrainedModel"""]
  
  try:
  		if not is_flax_available():
  				raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  		pass
  else:
  		_lowercase		:     Optional[Any] 					=["""FlaxMarianModel""", """FlaxMarianMTModel""", """FlaxMarianPreTrainedModel"""]
  
  if TYPE_CHECKING:
  		from .configuration_marian import MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP, MarianConfig, MarianOnnxConfig
  
  		try:
  				if not is_sentencepiece_available():
  						raise OptionalDependencyNotAvailable()
  		except OptionalDependencyNotAvailable:
  				pass
  		else:
  				from .tokenization_marian import MarianTokenizer
  
  		try:
  				if not is_torch_available():
  						raise OptionalDependencyNotAvailable()
  		except OptionalDependencyNotAvailable:
  				pass
  		else:
  				from .modeling_marian import (
  				    MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST,
  				    MarianForCausalLM,
  				    MarianModel,
  				    MarianMTModel,
  				    MarianPreTrainedModel,
  				)
  
  		try:
  				if not is_tf_available():
  						raise OptionalDependencyNotAvailable()
  		except OptionalDependencyNotAvailable:
  				pass
  		else:
  				from .modeling_tf_marian import TFMarianModel, TFMarianMTModel, TFMarianPreTrainedModel
  
  		try:
  				if not is_flax_available():
  						raise OptionalDependencyNotAvailable()
  		except OptionalDependencyNotAvailable:
  				pass
  		else:
  				from .modeling_flax_marian import FlaxMarianModel, FlaxMarianMTModel, FlaxMarianPreTrainedModel
  
  else:
  		import sys
  
  		_lowercase		:     List[str] 					=_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
  