






'''simple docstring'''
from typing import Dict, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    flip_channel_order,
    get_resize_output_image_size,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, is_vision_available, logging


if is_vision_available():
	import PIL

if is_torch_available():
	import torch


__magic_name__		:     int					=    logging.get_logger(__name__)







class 	UpperCamelCase__					(     __snake_case			):

		"""simple docstring"""
		UpperCAmelCase__     			=						['pixel_values']




		def __init__( self						:						int							,    __A						:						str = True							,    __A						:						str = None							,    __A						:						List[Any] = PILImageResampling.BILINEAR							,    __A						:						Optional[Any] = True							,    __A						:						Union[str, Any] = 1 / 2_5_5							,    __A						:						str = True							,    __A						:						Dict = None							,    __A						:						Tuple = True							,    **__A						:						Dict							,    ):







							"""simple docstring"""
							super().__init__(**__UpperCamelCase    )
							_lowercase			= size if size is not None else {"shortest_edge": 2_2_4}
							_lowercase			= get_size_dict(__UpperCamelCase							,    default_to_square=__UpperCamelCase    )
							_lowercase			= crop_size if crop_size is not None else {"height": 2_5_6, "width": 2_5_6}
							_lowercase			= get_size_dict(__UpperCamelCase							,    param_name="crop_size"    )

							_lowercase			= do_resize
							_lowercase			= size
							_lowercase			= resample
							_lowercase			= do_rescale
							_lowercase			= rescale_factor
							_lowercase			= do_center_crop
							_lowercase			= crop_size
							_lowercase			= do_flip_channel_order




		def       snake_case     ( self						:						List[Any]							,    __A						:						Optional[int]							,    __A						:						List[Any]							,    __A						:						Optional[Any] = PIL.Image.BILINEAR							,    __A						:						Optional[int] = None							,    **__A						:						Optional[Any]							,    ):







							"""simple docstring"""
							_lowercase			= get_size_dict(__UpperCamelCase							,    default_to_square=__UpperCamelCase    )
							if "shortest_edge" not in size:
												raise ValueError(f"""The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}"""    )
							_lowercase			= get_resize_output_image_size(__UpperCamelCase							,    size=size["shortest_edge"]							,    default_to_square=__UpperCamelCase    )
							return resize(__UpperCamelCase							,    size=__UpperCamelCase							,    resample=__UpperCamelCase							,    data_format=__UpperCamelCase							,    **__UpperCamelCase    )




		def       snake_case     ( self						:						Dict							,    __A						:						Optional[int]							,    __A						:						Optional[int]							,    __A						:						List[Any] = None							,    **__A						:						Any							,    ):







							"""simple docstring"""
							_lowercase			= get_size_dict(__UpperCamelCase    )
							if "height" not in size or "width" not in size:
												raise ValueError(f"""The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}"""    )
							return center_crop(__UpperCamelCase							,    size=(size["height"], size["width"])							,    data_format=__UpperCamelCase							,    **__UpperCamelCase    )




		def       snake_case     ( self						:						Any							,    __A						:						Optional[Any]							,    __A						:						Any							,    __A						:						Any = None							,    **__A						:						Tuple							,    ):







							"""simple docstring"""
							return rescale(__UpperCamelCase							,    scale=__UpperCamelCase							,    data_format=__UpperCamelCase							,    **__UpperCamelCase    )




		def       snake_case     ( self						:						Tuple							,    __A						:						str							,    __A						:						int = None    ):







							"""simple docstring"""
							return flip_channel_order(__UpperCamelCase							,    data_format=__UpperCamelCase    )




		def       snake_case     ( self						:						str							,    __A						:						Optional[int]							,    __A						:						str = None							,    __A						:						List[str] = None							,    __A						:						List[Any] = None							,    __A						:						str = None							,    __A						:						Union[str, Any] = None							,    __A						:						List[Any] = None							,    __A						:						str = None							,    __A						:						Dict = None							,    __A						:						Dict = None							,    __A						:						Optional[Any] = ChannelDimension.FIRST							,    **__A						:						Union[str, Any]							,    ):







							"""simple docstring"""
							_lowercase			= do_resize if do_resize is not None else self.do_resize
							_lowercase			= resample if resample is not None else self.resample
							_lowercase			= do_rescale if do_rescale is not None else self.do_rescale
							_lowercase			= rescale_factor if rescale_factor is not None else self.rescale_factor
							_lowercase			= do_center_crop if do_center_crop is not None else self.do_center_crop
							_lowercase			= (
							    do_flip_channel_order if do_flip_channel_order is not None else self.do_flip_channel_order
							)

							_lowercase			= size if size is not None else self.size
							_lowercase			= get_size_dict(__UpperCamelCase							,    default_to_square=__UpperCamelCase    )
							_lowercase			= crop_size if crop_size is not None else self.crop_size
							_lowercase			= get_size_dict(__UpperCamelCase							,    param_name="crop_size"    )

							_lowercase			= make_list_of_images(__UpperCamelCase    )

							if not valid_images(__UpperCamelCase    ):
												raise ValueError(
												    "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
												    "torch.Tensor, tf.Tensor or jax.ndarray."    )

							if do_resize and size is None:
												raise ValueError("Size must be specified if do_resize is True."    )

							if do_rescale and rescale_factor is None:
												raise ValueError("Rescale factor must be specified if do_rescale is True."    )

							if do_center_crop and crop_size is None:
												raise ValueError("Crop size must be specified if do_center_crop is True."    )

							# All transformations expect numpy arrays.
							_lowercase			= [to_numpy_array(__UpperCamelCase    ) for image in images]

							if do_resize:
												_lowercase			= [self.resize(image=__UpperCamelCase							,    size=__UpperCamelCase							,    resample=__UpperCamelCase    ) for image in images]

							if do_center_crop:
												_lowercase			= [self.center_crop(image=__UpperCamelCase							,    size=__UpperCamelCase    ) for image in images]

							if do_rescale:
												_lowercase			= [self.rescale(image=__UpperCamelCase							,    scale=__UpperCamelCase    ) for image in images]

							# the pretrained checkpoints assume images are BGR, not RGB
							if do_flip_channel_order:
												_lowercase			= [self.flip_channel_order(image=__UpperCamelCase    ) for image in images]

							_lowercase			= [to_channel_dimension_format(__UpperCamelCase							,    __UpperCamelCase    ) for image in images]

							_lowercase			= {"pixel_values": images}
							return BatchFeature(data=__UpperCamelCase							,    tensor_type=__UpperCamelCase    )




		def       snake_case     ( self						:						str							,    __A						:						Any							,    __A						:						Tuple = None    ):







							"""simple docstring"""
							_lowercase			= outputs.logits

							# Resize logits and compute semantic segmentation maps
							if target_sizes is not None:
												if len(__UpperCamelCase    ) != len(__UpperCamelCase    ):
																	raise ValueError(
																	    "Make sure that you pass in as many target sizes as the batch dimension of the logits"    )

												if is_torch_tensor(__UpperCamelCase    ):
																	_lowercase			= target_sizes.numpy()

												_lowercase			= []

												for idx in range(len(__UpperCamelCase    )    ):
																	_lowercase			= torch.nn.functional.interpolate(
																	    logits[idx].unsqueeze(dim=0    )							,    size=target_sizes[idx]							,    mode="bilinear"							,    align_corners=__UpperCamelCase    )
																	_lowercase			= resized_logits[0].argmax(dim=0    )
																	semantic_segmentation.append(__UpperCamelCase    )
							else:
												_lowercase			= logits.argmax(dim=1    )
												_lowercase			= [semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]    )]

							return semantic_segmentation




# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

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


A									=  {'configuration_mra': ['MRA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MraConfig']}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		A									=  [
		    'MRA_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'MraForMaskedLM',
		    'MraForMultipleChoice',
		    'MraForQuestionAnswering',
		    'MraForSequenceClassification',
		    'MraForTokenClassification',
		    'MraLayer',
		    'MraModel',
		    'MraPreTrainedModel',
		]


if TYPE_CHECKING:
		from .configuration_mra import MRA_PRETRAINED_CONFIG_ARCHIVE_MAP, MraConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mra import (
				    MRA_PRETRAINED_MODEL_ARCHIVE_LIST,
				    MraForMaskedLM,
				    MraForMultipleChoice,
				    MraForQuestionAnswering,
				    MraForSequenceClassification,
				    MraForTokenClassification,
				    MraLayer,
				    MraModel,
				    MraPreTrainedModel,
				)
else:
		import sys

		A									=  _LazyModule(__name__, globals()['__file__'], _import_structure)
