


from typing import TYPE_CHECKING

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


a					  =     {
    "configuration_efficientformer": [
        "EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "EfficientFormerConfig",
    ]
}

try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a					  =     ["EfficientFormerImageProcessor"]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a					  =     [
           "EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
           "EfficientFormerForImageClassification",
           "EfficientFormerForImageClassificationWithTeacher",
           "EfficientFormerModel",
           "EfficientFormerPreTrainedModel",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a					  =     [
           "TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TFEfficientFormerForImageClassification",
           "TFEfficientFormerForImageClassificationWithTeacher",
           "TFEfficientFormerModel",
           "TFEfficientFormerPreTrainedModel",
       ]

if TYPE_CHECKING:
       from .configuration_efficientformer import EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, EfficientFormerConfig

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .image_processing_efficientformer import EfficientFormerImageProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_efficientformer import (
                  EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                  EfficientFormerForImageClassification,
                  EfficientFormerForImageClassificationWithTeacher,
                  EfficientFormerModel,
                  EfficientFormerPreTrainedModel,
              )
       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_efficientformer import (
                  TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFEfficientFormerForImageClassification,
                  TFEfficientFormerForImageClassificationWithTeacher,
                  TFEfficientFormerModel,
                  TFEfficientFormerPreTrainedModel,
              )

else:
       import sys

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






import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse('9.1.0'):
							a					  =     {
							    'linear': PIL.Image.Resampling.BILINEAR,
							    'bilinear': PIL.Image.Resampling.BILINEAR,
							    'bicubic': PIL.Image.Resampling.BICUBIC,
							    'lanczos': PIL.Image.Resampling.LANCZOS,
							    'nearest': PIL.Image.Resampling.NEAREST,
							}
else:
							a					  =     {
							    'linear': PIL.Image.LINEAR,
							    'bilinear': PIL.Image.BILINEAR,
							    'bicubic': PIL.Image.BICUBIC,
							    'lanczos': PIL.Image.LANCZOS,
							    'nearest': PIL.Image.NEAREST,
							}


def 			UpperCAmelCase_				(      UpperCAmelCase__  ):
					lowercase_  							=			(images / 2 + 0.5).clamp(0						,							1  )
					lowercase_  							=			images.cpu().permute(0						,							2						,							3						,							1  ).float().numpy()
					lowercase_  							=			numpy_to_pil(UpperCAmelCase__  )
					return images



def 			UpperCAmelCase_				(      UpperCAmelCase__  ):
					if images.ndim == 3:
										lowercase_  							=			images[None, ...]
					lowercase_  							=			(images * 2_5_5).round().astype("""uint8"""  )
					if images.shape[-1] == 1:
										# special case for grayscale (single channel) images
										lowercase_  							=			[Image.fromarray(image.squeeze()						,							mode="""L"""  ) for image in images]
					else:
										lowercase_  							=			[Image.fromarray(UpperCAmelCase__  ) for image in images]

					return pil_images


