



'''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, prepare_image_inputs


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import ViTImageProcessor



class 							lowercase (						unittest.TestCase       ):


 """simple docstring"""


 def __init__(							self						,a_						,a_=7						,a_=3						,a_=18						,a_=30						,a_=400						,a_=True						,a_=None						,a_=True						,a_=[0.5, 0.5, 0.5]						,a_=[0.5, 0.5, 0.5]						,)	->     Optional[int]:
        _UpperCAmelCase						:		Tuple      =				size if size is not None else {"""height""": 18, """width""": 18}
        _UpperCAmelCase						:		List[str]      =				parent
        _UpperCAmelCase						:		Any      =				batch_size
        _UpperCAmelCase						:		Optional[Any]      =				num_channels
        _UpperCAmelCase						:		Union[str, Any]      =				image_size
        _UpperCAmelCase						:		Union[str, Any]      =				min_resolution
        _UpperCAmelCase						:		Optional[Any]      =				max_resolution
        _UpperCAmelCase						:		int      =				do_resize
        _UpperCAmelCase						:		List[Any]      =				size
        _UpperCAmelCase						:		str      =				do_normalize
        _UpperCAmelCase						:		List[str]      =				image_mean
        _UpperCAmelCase						:		List[str]      =				image_std







 def _snake_case				(							self							)	->     Dict:
        return {
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_normalize": self.do_normalize,
            "do_resize": self.do_resize,
            "size": self.size,
        }







@require_torch
@require_vision
class 							lowercase (						_lowerCamelCase      ,      unittest.TestCase       ):


 """simple docstring"""


 UpperCAmelCase					=						ViTImageProcessor if is_vision_available() else None







 def _snake_case				(							self							)	->     Union[str, Any]:
        _UpperCAmelCase						:		Any      =				ViTImageProcessingTester(self							)







 @property
 def _snake_case				(							self							)	->     str:
        return self.image_processor_tester.prepare_image_processor_dict()







 def _snake_case				(							self							)	->     Tuple:
        _UpperCAmelCase						:		List[Any]      =				self.image_processing_class(**self.image_processor_dict							)
        self.assertTrue(hasattr(a_						,"""image_mean"""							)							)
        self.assertTrue(hasattr(a_						,"""image_std"""							)							)
        self.assertTrue(hasattr(a_						,"""do_normalize"""							)							)
        self.assertTrue(hasattr(a_						,"""do_resize"""							)							)
        self.assertTrue(hasattr(a_						,"""size"""							)							)







 def _snake_case				(							self							)	->     Union[str, Any]:
        _UpperCAmelCase						:		str      =				self.image_processing_class.from_dict(self.image_processor_dict							)
        self.assertEqual(image_processor.size						,{"""height""": 18, """width""": 18}							)

        _UpperCAmelCase						:		Union[str, Any]      =				self.image_processing_class.from_dict(self.image_processor_dict						,size=42							)
        self.assertEqual(image_processor.size						,{"""height""": 42, """width""": 42}							)







 def _snake_case				(							self							)	->     Dict:
        pass







 def _snake_case				(							self							)	->     Optional[int]:
        # Initialize image_processing
        _UpperCAmelCase						:		Dict      =				self.image_processing_class(**self.image_processor_dict							)
        # create random PIL images
        _UpperCAmelCase						:		Tuple      =				prepare_image_inputs(self.image_processor_tester						,equal_resolution=a_							)
        for image in image_inputs:
               self.assertIsInstance(a_						,Image.Image							)

        # Test not batched input
        _UpperCAmelCase						:		Dict      =				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
        _UpperCAmelCase						:		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 _snake_case				(							self							)	->     List[str]:
        # Initialize image_processing
        _UpperCAmelCase						:		Optional[int]      =				self.image_processing_class(**self.image_processor_dict							)
        # create random numpy tensors
        _UpperCAmelCase						:		Union[str, 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
        _UpperCAmelCase						:		Dict      =				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
        _UpperCAmelCase						:		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 _snake_case				(							self							)	->     str:
        # Initialize image_processing
        _UpperCAmelCase						:		int      =				self.image_processing_class(**self.image_processor_dict							)
        # create random PyTorch tensors
        _UpperCAmelCase						:		int      =				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
        _UpperCAmelCase						:		List[Any]      =				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
        _UpperCAmelCase						:		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"""],
            )						,)








'''simple docstring'''






from typing import TYPE_CHECKING

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


A_							:				Union[str, Any]						=			{
    """configuration_segformer""": ["""SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""", """SegformerConfig""", """SegformerOnnxConfig"""]
}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_							:				Tuple						=			["""SegformerFeatureExtractor"""]
   A_							:				Tuple						=			["""SegformerImageProcessor"""]

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

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_							:				List[str]						=			[
       """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_							:				Optional[Any]						=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



