



'''simple docstring'''




from typing import Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import get_image_size, pad, rescale, to_channel_dimension_format
from ...image_utils import ChannelDimension, ImageInput, make_list_of_images, to_numpy_array, valid_images
from ...utils import TensorType, logging


UpperCamelCase__ :			str												=				logging.get_logger(__name__)






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			_A   :	str    					=	['''pixel_values''']

			def __init__(							self  :				int							,  lowerCAmelCase__  :				bool = True							,  lowerCAmelCase__  :				Union[int, float] = 1 / 2_5_5							,  lowerCAmelCase__  :				bool = True							,  lowerCAmelCase__  :				int = 8							,  **lowerCAmelCase__  :				List[Any]							,  ):





					"""simple docstring"""






					super().__init__(**lowerCAmelCase__		)

					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	do_rescale
					__SCREAMING_SNAKE_CASE :	List[str]					 =	rescale_factor
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	do_pad
					__SCREAMING_SNAKE_CASE :	str					 =	pad_size

			def UpperCamelCase__      (							self  :				Optional[int]							,  lowerCAmelCase__  :				np.ndarray							,  lowerCAmelCase__  :				float							,  lowerCAmelCase__  :				Optional[Union[str, ChannelDimension]] = None							,  **lowerCAmelCase__  :				Any		):





					"""simple docstring"""






					return rescale(lowerCAmelCase__							,  scale=lowerCAmelCase__							,  data_format=lowerCAmelCase__							,  **lowerCAmelCase__		)

			def UpperCamelCase__      (							self  :				int							,  lowerCAmelCase__  :				np.ndarray							,  lowerCAmelCase__  :				int							,  lowerCAmelCase__  :				Optional[Union[str, ChannelDimension]] = None		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE :	List[Any]					 =	get_image_size(lowerCAmelCase__		)
					__SCREAMING_SNAKE_CASE :	str					 =	(old_height // size + 1) * size - old_height
					__SCREAMING_SNAKE_CASE :	Dict					 =	(old_width // size + 1) * size - old_width

					return pad(lowerCAmelCase__							,  ((0, pad_height), (0, pad_width))							,  mode="""symmetric"""							,  data_format=lowerCAmelCase__		)



			def UpperCamelCase__      (							self  :				Union[str, Any]							,  lowerCAmelCase__  :				ImageInput							,  lowerCAmelCase__  :				Optional[bool] = None							,  lowerCAmelCase__  :				Optional[float] = None							,  lowerCAmelCase__  :				Optional[bool] = None							,  lowerCAmelCase__  :				Optional[int] = None							,  lowerCAmelCase__  :				Optional[Union[str, TensorType]] = None							,  lowerCAmelCase__  :				Union[str, ChannelDimension] = ChannelDimension.FIRST							,  **lowerCAmelCase__  :				Optional[Any]							,  ):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	do_rescale if do_rescale is not None else self.do_rescale
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	rescale_factor if rescale_factor is not None else self.rescale_factor
					__SCREAMING_SNAKE_CASE :	Dict					 =	do_pad if do_pad is not None else self.do_pad
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	pad_size if pad_size is not None else self.pad_size

					__SCREAMING_SNAKE_CASE :	Dict					 =	make_list_of_images(lowerCAmelCase__		)

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

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

					# All transformations expect numpy arrays.
					__SCREAMING_SNAKE_CASE :	Tuple					 =	[to_numpy_array(lowerCAmelCase__		) for image in images]

					if do_rescale:
							__SCREAMING_SNAKE_CASE :	Optional[int]					 =	[self.rescale(image=lowerCAmelCase__							,  scale=lowerCAmelCase__		) for image in images]

					if do_pad:
							__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	[self.pad(lowerCAmelCase__							,  size=lowerCAmelCase__		) for image in images]

					__SCREAMING_SNAKE_CASE :	List[str]					 =	[to_channel_dimension_format(lowerCAmelCase__							,  lowerCAmelCase__		) for image in images]

					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	{"""pixel_values""": images}
					return BatchFeature(data=lowerCAmelCase__							,  tensor_type=lowerCAmelCase__		)




'''simple docstring'''




UpperCamelCase__ :			List[str]												=				'''0.21.0'''

from .accelerator import Accelerator
from .big_modeling import (
    cpu_offload,
    cpu_offload_with_hook,
    disk_offload,
    dispatch_model,
    init_empty_weights,
    init_on_device,
    load_checkpoint_and_dispatch,
)
from .data_loader import skip_first_batches
from .launchers import debug_launcher, notebook_launcher
from .state import PartialState
from .utils import (
    DeepSpeedPlugin,
    DistributedDataParallelKwargs,
    DistributedType,
    FullyShardedDataParallelPlugin,
    GradScalerKwargs,
    InitProcessGroupKwargs,
    find_executable_batch_size,
    infer_auto_device_map,
    is_rich_available,
    load_checkpoint_in_model,
    synchronize_rng_states,
)


if is_rich_available():
						from .utils import rich