






'''simple docstring'''





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 BlipImageProcessor





class 		SCREAMING_SNAKE_CASE__   (     unittest.TestCase    ):



		def __init__(    self:    int				,   a:    Optional[int]				,   a:    Tuple=7				,   a:    List[str]=3				,   a:    Tuple=18				,   a:    List[str]=30				,   a:    Any=4_00				,   a:    Optional[Any]=True				,   a:    Optional[int]=None				,   a:    Tuple=True				,   a:    Tuple=False				,   a:    int=[0.4814_5466, 0.457_8275, 0.4082_1073]				,   a:    str=[0.2686_2954, 0.2613_0258, 0.2757_7711]				,   a:    List[Any]=True				,   )  ->Dict:






								'''simple docstring'''


								a_				     =   size if size is not None else {"height": 20, "width": 20}
								a_				     =   parent
								a_				     =   batch_size
								a_				     =   num_channels
								a_				     =   image_size
								a_				     =   min_resolution
								a_				     =   max_resolution
								a_				     =   do_resize
								a_				     =   size
								a_				     =   do_normalize
								a_				     =   image_mean
								a_				     =   image_std
								a_				     =   do_pad
								a_				     =   do_convert_rgb



		def _lowerCAmelCase     (    self:    Any)  ->Optional[Any]:






								'''simple docstring'''


								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_convert_rgb": self.do_convert_rgb,
								    "do_pad": self.do_pad,
								}




		def _lowerCAmelCase     (    self:    str				,   a:    Dict=False				,   a:    List[Any]=False				,   a:    Union[str, Any]=False)  ->Union[str, Any]:






								'''simple docstring'''


								assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

								if equal_resolution:
														a_				     =   []
														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:
														a_				     =   []
														for i in range(self.batch_size):
																				a_     ,       a_				     =   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
														a_				     =   [Image.fromarray(np.moveaxis(a				,   0				,   -1)) for x in image_inputs]

								if torchify:
														a_				     =   [torch.from_numpy(a) for x in image_inputs]

								return image_inputs





@require_torch
@require_vision
class 		SCREAMING_SNAKE_CASE__   (     lowercase_		,		unittest.TestCase    ):
		_UpperCAmelCase         =BlipImageProcessor if is_vision_available() else None



		def _lowerCAmelCase     (    self:    Optional[Any])  ->Any:






								'''simple docstring'''


								a_				     =   BlipImageProcessingTester(self)



		@property
		def _lowerCAmelCase     (    self:    Any)  ->Any:






								'''simple docstring'''


								return self.image_processor_tester.prepare_image_processor_dict()



		def _lowerCAmelCase     (    self:    Union[str, Any])  ->Optional[int]:






								'''simple docstring'''


								a_				     =   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_convert_rgb"))



		def _lowerCAmelCase     (    self:    Dict)  ->Tuple:






								'''simple docstring'''


								pass



		def _lowerCAmelCase     (    self:    Dict)  ->Dict:






								'''simple docstring'''


								a_				     =   self.image_processing_class(**self.image_processor_dict)
								# create random PIL images
								a_				     =   self.image_processor_tester.prepare_inputs(equal_resolution=a)
								for image in image_inputs:
														self.assertIsInstance(a				,   Image.Image)

								# Test not batched input
								a_				     =   image_processor(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
								a_				     =   image_processor(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 _lowerCAmelCase     (    self:    List[Any])  ->Optional[int]:






								'''simple docstring'''


								a_				     =   self.image_processing_class(**self.image_processor_dict)
								# create random numpy tensors
								a_				     =   self.image_processor_tester.prepare_inputs(equal_resolution=a				,   numpify=a)
								for image in image_inputs:
														self.assertIsInstance(a				,   np.ndarray)

								# Test not batched input
								a_				     =   image_processor(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
								a_				     =   image_processor(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 _lowerCAmelCase     (    self:    Optional[Any])  ->Tuple:






								'''simple docstring'''


								a_				     =   self.image_processing_class(**self.image_processor_dict)
								# create random PyTorch tensors
								a_				     =   self.image_processor_tester.prepare_inputs(equal_resolution=a				,   torchify=a)
								for image in image_inputs:
														self.assertIsInstance(a				,   torch.Tensor)

								# Test not batched input
								a_				     =   image_processor(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
								a_				     =   image_processor(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"],
								    )				,   )





@require_torch
@require_vision
class 		SCREAMING_SNAKE_CASE__   (     lowercase_		,		unittest.TestCase    ):
		_UpperCAmelCase         =BlipImageProcessor if is_vision_available() else None



		def _lowerCAmelCase     (    self:    Union[str, Any])  ->Any:






								'''simple docstring'''


								a_				     =   BlipImageProcessingTester(self				,   num_channels=4)
								a_				     =   3



		@property
		def _lowerCAmelCase     (    self:    List[str])  ->Optional[Any]:






								'''simple docstring'''


								return self.image_processor_tester.prepare_image_processor_dict()



		def _lowerCAmelCase     (    self:    List[str])  ->Tuple:






								'''simple docstring'''


								a_				     =   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_convert_rgb"))



		def _lowerCAmelCase     (    self:    Optional[Any])  ->Dict:






								'''simple docstring'''


								pass




		def _lowerCAmelCase     (    self:    Optional[Any])  ->List[Any]:






								'''simple docstring'''


								a_				     =   self.image_processing_class(**self.image_processor_dict)
								# create random PIL images
								a_				     =   self.image_processor_tester.prepare_inputs(equal_resolution=a)
								for image in image_inputs:
														self.assertIsInstance(a				,   Image.Image)

								# Test not batched input
								a_				     =   image_processor(image_inputs[0]				,   return_tensors="pt").pixel_values
								self.assertEqual(
								    encoded_images.shape				,   (
								        1,
								        self.expected_encoded_image_num_channels,
								        self.image_processor_tester.size["height"],
								        self.image_processor_tester.size["width"],
								    )				,   )

								# Test batched
								a_				     =   image_processor(a				,   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.size["height"],
								        self.image_processor_tester.size["width"],
								    )				,   )











'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


a_      = {
    'configuration_segformer': ['SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'SegformerConfig', 'SegformerOnnxConfig']
}

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a_      = ['SegformerFeatureExtractor']
							a_      = ['SegformerImageProcessor']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a_      = [
							    'SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'SegformerDecodeHead',
							    'SegformerForImageClassification',
							    'SegformerForSemanticSegmentation',
							    'SegformerLayer',
							    'SegformerModel',
							    'SegformerPreTrainedModel',
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a_      = [
							    'TF_SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'TFSegformerDecodeHead',
							    'TFSegformerForImageClassification',
							    'TFSegformerForSemanticSegmentation',
							    'TFSegformerModel',
							    'TFSegformerPreTrainedModel',
							]


if TYPE_CHECKING:
							from .configuration_segformer import SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, SegformerConfig, SegformerOnnxConfig

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .feature_extraction_segformer import SegformerFeatureExtractor
														from .image_processing_segformer import SegformerImageProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_segformer import (
														    SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
														    SegformerDecodeHead,
														    SegformerForImageClassification,
														    SegformerForSemanticSegmentation,
														    SegformerLayer,
														    SegformerModel,
														    SegformerPreTrainedModel,
														)
							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_segformer import (
														    TF_SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFSegformerDecodeHead,
														    TFSegformerForImageClassification,
														    TFSegformerForSemanticSegmentation,
														    TFSegformerModel,
														    TFSegformerPreTrainedModel,
														)

else:
							import sys

							a_      = _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



