


from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a					  =     {'configuration_focalnet': ['FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP', 'FocalNetConfig']}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a					  =     [
           'FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST',
           'FocalNetForImageClassification',
           'FocalNetForMaskedImageModeling',
           'FocalNetBackbone',
           'FocalNetModel',
           'FocalNetPreTrainedModel',
       ]

if TYPE_CHECKING:
       from .configuration_focalnet import FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP, FocalNetConfig

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_focalnet import (
                  FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST,
                  FocalNetBackbone,
                  FocalNetForImageClassification,
                  FocalNetForMaskedImageModeling,
                  FocalNetModel,
                  FocalNetPreTrainedModel,
              )

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


