
'''simple docstring'''

from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
    import PIL

__snake_case:  Tuple								=			logging.get_logger(__name__)






def 	_snake_case						(      A_       :    Tuple   ):
  """simple docstring"""







  if isinstance(A_     ,		(list, tuple)   ) and isinstance(videos[0]     ,		(list, tuple)   ) and is_valid_image(videos[0][0]   ):
    return videos

  elif isinstance(A_     ,		(list, tuple)   ) and is_valid_image(videos[0]   ):
    return [videos]

  elif is_valid_image(A_   ):
    return [[videos]]

  raise ValueError(f'''Could not make batched video from {videos}'''   )




class  _UpperCAmelCase ( lowerCAmelCase__    ):

     """simple docstring"""

     a_    	=					["pixel_values"]


     def __init__(      self							,		lowerCAmelCase_ = True							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = PILImageResampling.BILINEAR							,		lowerCAmelCase_ = True							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = True							,		lowerCAmelCase_ = 1 / 2_55							,		lowerCAmelCase_ = True							,		lowerCAmelCase_ = True							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		**lowerCAmelCase_							,		):

       '''simple docstring'''

       super().__init__(**lowerCAmelCase_ )
       a_      :	List[str]      =							size if size is not None else {"""shortest_edge""": 2_56}
       a_      :	Any      =							get_size_dict(lowerCAmelCase_							,		default_to_square=lowerCAmelCase_ )
       a_      :	List[Any]      =							crop_size if crop_size is not None else {"""height""": 2_24, """width""": 2_24}
       a_      :	Union[str, Any]      =							get_size_dict(lowerCAmelCase_							,		param_name="""crop_size""" )

       a_      :	Optional[Any]      =							do_resize
       a_      :	Tuple      =							size
       a_      :	List[str]      =							do_center_crop
       a_      :	List[str]      =							crop_size
       a_      :	str      =							resample
       a_      :	List[Any]      =							do_rescale
       a_      :	Optional[int]      =							rescale_factor
       a_      :	Optional[int]      =							offset
       a_      :	str      =							do_normalize
       a_      :	List[str]      =							image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
       a_      :	Optional[Any]      =							image_std if image_std is not None else IMAGENET_STANDARD_STD


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ = PILImageResampling.BILINEAR							,		lowerCAmelCase_ = None							,		**lowerCAmelCase_							,		):

       '''simple docstring'''

       a_      :	int      =							get_size_dict(lowerCAmelCase_							,		default_to_square=lowerCAmelCase_ )
       if "shortest_edge" in size:
         a_      :	Optional[Any]      =							get_resize_output_image_size(lowerCAmelCase_							,		size["""shortest_edge"""]							,		default_to_square=lowerCAmelCase_ )
       elif "height" in size and "width" in size:
         a_      :	str      =							(size["""height"""], size["""width"""])
       else:
         raise ValueError(f'''Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}''' )
       return resize(lowerCAmelCase_							,		size=lowerCAmelCase_							,		resample=lowerCAmelCase_							,		data_format=lowerCAmelCase_							,		**lowerCAmelCase_ )


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ = None							,		**lowerCAmelCase_							,		):

       '''simple docstring'''

       a_      :	str      =							get_size_dict(lowerCAmelCase_ )
       if "height" not in size or "width" not in size:
         raise ValueError(f'''Size must have \'height\' and \'width\' as keys. Got {size.keys()}''' )
       return center_crop(lowerCAmelCase_							,		size=(size["""height"""], size["""width"""])							,		data_format=lowerCAmelCase_							,		**lowerCAmelCase_ )


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ = True							,		lowerCAmelCase_ = None							,		**lowerCAmelCase_							,		):

       '''simple docstring'''

       a_      :	Any      =							image.astype(np.floataa )
       if offset:
         a_      :	List[str]      =							image - (scale / 2)
       return rescale(lowerCAmelCase_							,		scale=lowerCAmelCase_							,		data_format=lowerCAmelCase_							,		**lowerCAmelCase_ )


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ = None							,		**lowerCAmelCase_							,		):

       '''simple docstring'''

       return normalize(lowerCAmelCase_							,		mean=lowerCAmelCase_							,		std=lowerCAmelCase_							,		data_format=lowerCAmelCase_							,		**lowerCAmelCase_ )


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = ChannelDimension.FIRST							,		):

       '''simple docstring'''

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

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

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

       if do_normalize and (image_mean is None or image_std is None):
         raise ValueError("""Image mean and std must be specified if do_normalize is True.""" )

       if offset and not do_rescale:
         raise ValueError("""For offset, do_rescale must also be set to True.""" )

       # All transformations expect numpy arrays.
       a_      :	Optional[int]      =							to_numpy_array(lowerCAmelCase_ )

       if do_resize:
         a_      :	List[str]      =							self.resize(image=lowerCAmelCase_							,		size=lowerCAmelCase_							,		resample=lowerCAmelCase_ )

       if do_center_crop:
         a_      :	Optional[int]      =							self.center_crop(lowerCAmelCase_							,		size=lowerCAmelCase_ )

       if do_rescale:
         a_      :	List[Any]      =							self.rescale(image=lowerCAmelCase_							,		scale=lowerCAmelCase_							,		offset=lowerCAmelCase_ )

       if do_normalize:
         a_      :	List[str]      =							self.normalize(image=lowerCAmelCase_							,		mean=lowerCAmelCase_							,		std=lowerCAmelCase_ )

       a_      :	Tuple      =							to_channel_dimension_format(lowerCAmelCase_							,		lowerCAmelCase_ )
       return image






     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = None							,		lowerCAmelCase_ = ChannelDimension.FIRST							,		**lowerCAmelCase_							,		):

       '''simple docstring'''

       a_      :	List[Any]      =							do_resize if do_resize is not None else self.do_resize
       a_      :	int      =							resample if resample is not None else self.resample
       a_      :	List[Any]      =							do_center_crop if do_center_crop is not None else self.do_center_crop
       a_      :	Optional[int]      =							do_rescale if do_rescale is not None else self.do_rescale
       a_      :	Dict      =							rescale_factor if rescale_factor is not None else self.rescale_factor
       a_      :	Any      =							offset if offset is not None else self.offset
       a_      :	str      =							do_normalize if do_normalize is not None else self.do_normalize
       a_      :	Any      =							image_mean if image_mean is not None else self.image_mean
       a_      :	Optional[Any]      =							image_std if image_std is not None else self.image_std

       a_      :	List[Any]      =							size if size is not None else self.size
       a_      :	Any      =							get_size_dict(lowerCAmelCase_							,		default_to_square=lowerCAmelCase_ )
       a_      :	Any      =							crop_size if crop_size is not None else self.crop_size
       a_      :	Dict      =							get_size_dict(lowerCAmelCase_							,		param_name="""crop_size""" )

       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.""" )

       a_      :	Any      =							make_batched(lowerCAmelCase_ )

       a_      :	Union[str, Any]      =							[
           [
               self._preprocess_image(
                   image=lowerCAmelCase_							,		do_resize=lowerCAmelCase_							,		size=lowerCAmelCase_							,		resample=lowerCAmelCase_							,		do_center_crop=lowerCAmelCase_							,		crop_size=lowerCAmelCase_							,		do_rescale=lowerCAmelCase_							,		rescale_factor=lowerCAmelCase_							,		offset=lowerCAmelCase_							,		do_normalize=lowerCAmelCase_							,		image_mean=lowerCAmelCase_							,		image_std=lowerCAmelCase_							,		data_format=lowerCAmelCase_							,		)
               for img in video
           ]
           for video in videos
       ]

       a_      :	Dict      =							{"""pixel_values""": videos}
       return BatchFeature(data=lowerCAmelCase_							,		tensor_type=lowerCAmelCase_ )

'''simple docstring'''

from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


__snake_case:  Optional[Any]								=			logging.get_logger(__name__)


__snake_case:  Tuple								=			TypeVar("DatasetType", Dataset, IterableDataset)






def 	_snake_case						(      A_       :    List[DatasetType]     ,		A_       :    Optional[List[float]] = None     ,		A_       :    Optional[int] = None     ,		A_       :    Optional[DatasetInfo] = None     ,		A_       :    Optional[NamedSplit] = None     ,		A_       :    Literal["first_exhausted", "all_exhausted"] = "first_exhausted"     ,		):
  """simple docstring"""







  from .arrow_dataset import Dataset
  from .iterable_dataset import IterableDataset

  if not datasets:
    raise ValueError("""Unable to interleave an empty list of datasets."""   )
  for i, dataset in enumerate(A_   ):
    if not isinstance(A_     ,		(Dataset, IterableDataset)   ):
      if isinstance(A_     ,		(DatasetDict, IterableDatasetDict)   ):
        if not dataset:
          raise ValueError(
              f'''Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} '''
              """is an empty dataset dictionary."""   )
        raise ValueError(
            f'''Dataset at position {i} has at least one split: {list(A_   )}\n'''
            f'''Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(A_   )   )}\']'''   )
      raise ValueError(
          f'''Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(A_   ).__name__}.'''   )
    if i == 0:
      a_      , a_      :	Union[str, Any]      =							(
          (Dataset, IterableDataset) if isinstance(A_     ,		A_   ) else (IterableDataset, Dataset)
      )
    elif not isinstance(A_     ,		A_   ):
      raise ValueError(
          f'''Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects.'''   )
  if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
    raise ValueError(f'''{stopping_strategy} is not supported. Please enter a valid stopping_strategy.'''   )
  if dataset_type is Dataset:
    return _interleave_map_style_datasets(
        A_     ,		A_     ,		A_     ,		info=A_     ,		split=A_     ,		stopping_strategy=A_   )
  else:
    return _interleave_iterable_datasets(
        A_     ,		A_     ,		A_     ,		info=A_     ,		split=A_     ,		stopping_strategy=A_   )






def 	_snake_case						(      A_       :    List[DatasetType]     ,		A_       :    Optional[DatasetInfo] = None     ,		A_       :    Optional[NamedSplit] = None     ,		A_       :    int = 0     ,		):
  """simple docstring"""







  if not dsets:
    raise ValueError("""Unable to concatenate an empty list of datasets."""   )
  for i, dataset in enumerate(A_   ):
    if not isinstance(A_     ,		(Dataset, IterableDataset)   ):
      if isinstance(A_     ,		(DatasetDict, IterableDatasetDict)   ):
        if not dataset:
          raise ValueError(
              f'''Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} '''
              """is an empty dataset dictionary."""   )
        raise ValueError(
            f'''Dataset at position {i} has at least one split: {list(A_   )}\n'''
            f'''Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(A_   )   )}\']'''   )
      raise ValueError(
          f'''Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(A_   ).__name__}.'''   )
    if i == 0:
      a_      , a_      :	str      =							(
          (Dataset, IterableDataset) if isinstance(A_     ,		A_   ) else (IterableDataset, Dataset)
      )
    elif not isinstance(A_     ,		A_   ):
      raise ValueError(
          f'''Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects.'''   )
  if dataset_type is Dataset:
    return _concatenate_map_style_datasets(A_     ,		info=A_     ,		split=A_     ,		axis=A_   )
  else:
    return _concatenate_iterable_datasets(A_     ,		info=A_     ,		split=A_     ,		axis=A_   )


