





'''simple docstring'''






snake_case_     =	"2.13.1"

import platform

import pyarrow
from packaging import version


if version.parse(platform.python_version()) < version.parse("""3.7"""):
     raise ImportWarning(
         """To use `datasets`, Python>=3.7 is required, and the current version of Python doesn't match this condition."""
     )

if version.parse(pyarrow.__version__).major < 8:
     raise ImportWarning(
         """To use `datasets`, the module `pyarrow>=8.0.0` is required, and the current version of `pyarrow` doesn't match this condition.\n"""
         """If you are running this in a Google Colab, you should probably just restart the runtime to use the right version of `pyarrow`."""
     )

del platform
del pyarrow
del version

from .arrow_dataset import Dataset
from .arrow_reader import ReadInstruction
from .builder import ArrowBasedBuilder, BeamBasedBuilder, BuilderConfig, DatasetBuilder, GeneratorBasedBuilder
from .combine import concatenate_datasets, interleave_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .download import *
from .features import *
from .fingerprint import disable_caching, enable_caching, is_caching_enabled, set_caching_enabled
from .info import DatasetInfo, MetricInfo
from .inspect import (
    get_dataset_config_info,
    get_dataset_config_names,
    get_dataset_infos,
    get_dataset_split_names,
    inspect_dataset,
    inspect_metric,
    list_datasets,
    list_metrics,
)
from .iterable_dataset import IterableDataset
from .load import load_dataset, load_dataset_builder, load_from_disk, load_metric
from .metric import Metric
from .splits import (
    NamedSplit,
    NamedSplitAll,
    Split,
    SplitBase,
    SplitDict,
    SplitGenerator,
    SplitInfo,
    SubSplitInfo,
    percent,
)
from .tasks import *
from .utils import *
from .utils import logging


# deprecated modules
from datasets import arrow_dataset as _arrow_dataset  # isort:skip
from datasets import utils as _utils  # isort:skip
from datasets.utils import download_manager as _deprecated_download_manager  # isort:skip

snake_case_     =	concatenate_datasets
snake_case_     =	DownloadConfig
snake_case_     =	DownloadManager
snake_case_     =	DownloadMode
snake_case_     =	DownloadConfig
snake_case_     =	DownloadMode
snake_case_     =	DownloadManager

del _arrow_dataset, _utils, _deprecated_download_manager







'''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_     =	logging.get_logger(__name__)
def 							_lowerCamelCase(  UpperCamelCase__    : int		)		->  List[List[ImageInput]]:
    if isinstance(UpperCamelCase__    ,       (list, tuple)		) and isinstance(videos[0]    ,       (list, tuple)		) and is_valid_image(videos[0][0]		):
        return videos

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

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

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





class   _lowercase						(							a				):
   _UpperCamelCase       		=   ["""pixel_values"""]


   def __init__( self    ,   _UpperCAmelCase = True    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = PILImageResampling.BILINEAR    ,   _UpperCAmelCase = True    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = True    ,   _UpperCAmelCase = 1 / 255    ,   _UpperCAmelCase = True    ,   _UpperCAmelCase = True    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   **_UpperCAmelCase    ,   ):
       super().__init__(**_UpperCAmelCase					)
       A       :       int							=						size if size is not None else {'''shortest_edge''': 256}
       A       :       str							=						get_size_dict(_UpperCAmelCase    ,   default_to_square=_UpperCAmelCase					)
       A       :       List[Any]							=						crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
       A       :       List[Any]							=						get_size_dict(_UpperCAmelCase    ,   param_name='''crop_size'''					)

       A       :       Dict							=						do_resize
       A       :       Union[str, Any]							=						size
       A       :       int							=						do_center_crop
       A       :       Union[str, Any]							=						crop_size
       A       :       int							=						resample
       A       :       Any							=						do_rescale
       A       :       Optional[Any]							=						rescale_factor
       A       :       Any							=						offset
       A       :       int							=						do_normalize
       A       :       Optional[Any]							=						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
       A       :       str							=						image_std if image_std is not None else IMAGENET_STANDARD_STD


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase = PILImageResampling.BILINEAR    ,   _UpperCAmelCase = None    ,   **_UpperCAmelCase    ,   ):
       A       :       str							=						get_size_dict(_UpperCAmelCase    ,   default_to_square=_UpperCAmelCase					)
       if "shortest_edge" in size:
           A       :       Union[str, Any]							=						get_resize_output_image_size(_UpperCAmelCase    ,   size['''shortest_edge''']    ,   default_to_square=_UpperCAmelCase					)
       elif "height" in size and "width" in size:
           A       :       Optional[Any]							=						(size['''height'''], size['''width'''])
       else:
           raise ValueError(f'''Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'''					)
       return resize(_UpperCAmelCase    ,   size=_UpperCAmelCase    ,   resample=_UpperCAmelCase    ,   data_format=_UpperCAmelCase    ,   **_UpperCAmelCase					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase = None    ,   **_UpperCAmelCase    ,   ):
       A       :       Optional[int]							=						get_size_dict(_UpperCAmelCase					)
       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(_UpperCAmelCase    ,   size=(size['''height'''], size['''width'''])    ,   data_format=_UpperCAmelCase    ,   **_UpperCAmelCase					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase = True    ,   _UpperCAmelCase = None    ,   **_UpperCAmelCase    ,   ):
       A       :       Dict							=						image.astype(np.floataa					)
       if offset:
           A       :       List[str]							=						image - (scale / 2)
       return rescale(_UpperCAmelCase    ,   scale=_UpperCAmelCase    ,   data_format=_UpperCAmelCase    ,   **_UpperCAmelCase					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase = None    ,   **_UpperCAmelCase    ,   ):
       return normalize(_UpperCAmelCase    ,   mean=_UpperCAmelCase    ,   std=_UpperCAmelCase    ,   data_format=_UpperCAmelCase    ,   **_UpperCAmelCase					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = ChannelDimension.FIRST    ,   ):
       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       :       Dict							=						to_numpy_array(_UpperCAmelCase					)

       if do_resize:
           A       :       int							=						self.resize(image=_UpperCAmelCase    ,   size=_UpperCAmelCase    ,   resample=_UpperCAmelCase					)

       if do_center_crop:
           A       :       Optional[int]							=						self.center_crop(_UpperCAmelCase    ,   size=_UpperCAmelCase					)

       if do_rescale:
           A       :       int							=						self.rescale(image=_UpperCAmelCase    ,   scale=_UpperCAmelCase    ,   offset=_UpperCAmelCase					)

       if do_normalize:
           A       :       List[Any]							=						self.normalize(image=_UpperCAmelCase    ,   mean=_UpperCAmelCase    ,   std=_UpperCAmelCase					)

       A       :       Optional[int]							=						to_channel_dimension_format(_UpperCAmelCase    ,   _UpperCAmelCase					)
       return image


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = None    ,   _UpperCAmelCase = ChannelDimension.FIRST    ,   **_UpperCAmelCase    ,   ):
       A       :       Union[str, Any]							=						do_resize if do_resize is not None else self.do_resize
       A       :       Optional[Any]							=						resample if resample is not None else self.resample
       A       :       List[str]							=						do_center_crop if do_center_crop is not None else self.do_center_crop
       A       :       Union[str, Any]							=						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       :       List[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       :       List[str]							=						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(_UpperCAmelCase    ,   default_to_square=_UpperCAmelCase					)
       A       :       Optional[int]							=						crop_size if crop_size is not None else self.crop_size
       A       :       int							=						get_size_dict(_UpperCAmelCase    ,   param_name='''crop_size'''					)

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

       A       :       List[Any]							=						make_batched(_UpperCAmelCase					)

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

       A       :       Any							=						{'''pixel_values''': videos}
       return BatchFeature(data=_UpperCAmelCase    ,   tensor_type=_UpperCAmelCase					)
