





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'''):
							UpperCAmelCase__						:			str									={
							    '''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:
							UpperCAmelCase__						:			Optional[int]									={
							    '''linear''': PIL.Image.LINEAR,
							    '''bilinear''': PIL.Image.BILINEAR,
							    '''bicubic''': PIL.Image.BICUBIC,
							    '''lanczos''': PIL.Image.LANCZOS,
							    '''nearest''': PIL.Image.NEAREST,
							}





def      _lowercase					(						_UpperCAmelCase				)						->  Optional[Any]:
				lowerCamelCase	 =(images / 2 + 0.5).clamp(0			,      1				)
				lowerCamelCase	 =images.cpu().permute(0			,      2			,      3			,      1				).float().numpy()
				lowerCamelCase	 =numpy_to_pil(_UpperCAmelCase				)
				return images





def      _lowercase					(						_UpperCAmelCase				)						->  Union[str, Any]:
				if images.ndim == 3:
								lowerCamelCase	 =images[None, ...]
				lowerCamelCase	 =(images * 2_55).round().astype("""uint8"""				)
				if images.shape[-1] == 1:
								# special case for grayscale (single channel) images
								lowerCamelCase	 =[Image.fromarray(image.squeeze()			,      mode="""L"""				) for image in images]
				else:
								lowerCamelCase	 =[Image.fromarray(_UpperCAmelCase				) for image in images]

				return pil_images












from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCAmelCase__						:			str									={'''configuration_fnet''': ['''FNET_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''FNetConfig''']}

try:
							if not is_sentencepiece_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__						:			List[Any]									=['''FNetTokenizer''']

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__						:			Any									=['''FNetTokenizerFast''']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase__						:			Dict									=[
							    '''FNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''FNetForMaskedLM''',
							    '''FNetForMultipleChoice''',
							    '''FNetForNextSentencePrediction''',
							    '''FNetForPreTraining''',
							    '''FNetForQuestionAnswering''',
							    '''FNetForSequenceClassification''',
							    '''FNetForTokenClassification''',
							    '''FNetLayer''',
							    '''FNetModel''',
							    '''FNetPreTrainedModel''',
							]


if TYPE_CHECKING:
							from .configuration_fnet import FNET_PRETRAINED_CONFIG_ARCHIVE_MAP, FNetConfig

							try:
														if not is_sentencepiece_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_fnet import FNetTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_fnet_fast import FNetTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_fnet import (
														    FNET_PRETRAINED_MODEL_ARCHIVE_LIST,
														    FNetForMaskedLM,
														    FNetForMultipleChoice,
														    FNetForNextSentencePrediction,
														    FNetForPreTraining,
														    FNetForQuestionAnswering,
														    FNetForSequenceClassification,
														    FNetForTokenClassification,
														    FNetLayer,
														    FNetModel,
														    FNetPreTrainedModel,
														)


else:
							import sys

							UpperCAmelCase__						:			Optional[int]									=_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





