

from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


_a	 =     logging.get_logger(__name__)


if is_vision_available():
		import PIL






class 							A_				(	lowerCamelCase__      ):
					_lowercase    :  List[Any]          =			['pixel_values']


					def __init__(							self    :	List[str]    ,						UpperCAmelCase    :	bool = True    ,						UpperCAmelCase    :	Dict[str, int] = None    ,						UpperCAmelCase    :	PILImageResampling = PILImageResampling.BICUBIC    ,						UpperCAmelCase    :	bool = True    ,						UpperCAmelCase    :	Dict[str, int] = None    ,						UpperCAmelCase    :	bool = True    ,						UpperCAmelCase    :	Union[int, float] = 1 / 2_5_5    ,						UpperCAmelCase    :	bool = True    ,						UpperCAmelCase    :	Optional[Union[float, List[float]]] = None    ,						UpperCAmelCase    :	Optional[Union[float, List[float]]] = None    ,						UpperCAmelCase    :	bool = True    ,						**UpperCAmelCase    :	Optional[Any]    ,						)							->			Dict:
						super().__init__(**SCREAMING_SNAKE_CASE_      )
						__lowerCAmelCase:     List[str]     			=   size if size is not None else {'shortest_edge': 2_2_4}
						__lowerCAmelCase:     Dict     			=   get_size_dict(SCREAMING_SNAKE_CASE_    ,						default_to_square=SCREAMING_SNAKE_CASE_      )
						__lowerCAmelCase:     Any     			=   crop_size if crop_size is not None else {'height': 2_2_4, 'width': 2_2_4}
						__lowerCAmelCase:     Optional[int]     			=   get_size_dict(SCREAMING_SNAKE_CASE_      )

						__lowerCAmelCase:     Dict     			=   do_resize
						__lowerCAmelCase:     List[Any]     			=   size
						__lowerCAmelCase:     Optional[Any]     			=   resample
						__lowerCAmelCase:     List[str]     			=   do_center_crop
						__lowerCAmelCase:     Tuple     			=   crop_size
						__lowerCAmelCase:     Tuple     			=   do_rescale
						__lowerCAmelCase:     int     			=   rescale_factor
						__lowerCAmelCase:     Tuple     			=   do_normalize
						__lowerCAmelCase:     int     			=   image_mean if image_mean is not None else OPENAI_CLIP_MEAN
						__lowerCAmelCase:     Dict     			=   image_std if image_std is not None else OPENAI_CLIP_STD
						__lowerCAmelCase:     Optional[int]     			=   do_convert_rgb


					def 						UpperCAmelCase						(							self    :	str    ,						UpperCAmelCase    :	np.ndarray    ,						UpperCAmelCase    :	Dict[str, int]    ,						UpperCAmelCase    :	PILImageResampling = PILImageResampling.BICUBIC    ,						UpperCAmelCase    :	Optional[Union[str, ChannelDimension]] = None    ,						**UpperCAmelCase    :	int    ,						)							->			List[str]:
						__lowerCAmelCase:     str     			=   get_size_dict(SCREAMING_SNAKE_CASE_    ,						default_to_square=SCREAMING_SNAKE_CASE_      )
						__lowerCAmelCase:     Any     			=   get_resize_output_image_size(
						    SCREAMING_SNAKE_CASE_    ,						size=(size['height'], size['width'])    ,						default_to_square=SCREAMING_SNAKE_CASE_      )
						return resize(SCREAMING_SNAKE_CASE_    ,						size=SCREAMING_SNAKE_CASE_    ,						resample=SCREAMING_SNAKE_CASE_    ,						data_format=SCREAMING_SNAKE_CASE_    ,						**SCREAMING_SNAKE_CASE_      )


					def 						UpperCAmelCase						(							self    :	Any    ,						UpperCAmelCase    :	np.ndarray    ,						UpperCAmelCase    :	Dict[str, int]    ,						UpperCAmelCase    :	Optional[Union[str, ChannelDimension]] = None    ,						**UpperCAmelCase    :	Dict    ,						)							->			List[str]:
						__lowerCAmelCase:     Optional[Any]     			=   get_size_dict(SCREAMING_SNAKE_CASE_      )
						return center_crop(SCREAMING_SNAKE_CASE_    ,						size=(size['height'], size['width'])    ,						data_format=SCREAMING_SNAKE_CASE_    ,						**SCREAMING_SNAKE_CASE_      )


					def 						UpperCAmelCase						(							self    :	str    ,						UpperCAmelCase    :	np.ndarray    ,						UpperCAmelCase    :	Union[int, float]    ,						UpperCAmelCase    :	Optional[Union[str, ChannelDimension]] = None    ,						**UpperCAmelCase    :	Dict    ,						)							->			Tuple:
						return rescale(SCREAMING_SNAKE_CASE_    ,						scale=SCREAMING_SNAKE_CASE_    ,						data_format=SCREAMING_SNAKE_CASE_    ,						**SCREAMING_SNAKE_CASE_      )


					def 						UpperCAmelCase						(							self    :	Union[str, Any]    ,						UpperCAmelCase    :	np.ndarray    ,						UpperCAmelCase    :	Union[float, List[float]]    ,						UpperCAmelCase    :	Union[float, List[float]]    ,						UpperCAmelCase    :	Optional[Union[str, ChannelDimension]] = None    ,						**UpperCAmelCase    :	Union[str, Any]    ,						)							->			Union[str, Any]:
						return normalize(SCREAMING_SNAKE_CASE_    ,						mean=SCREAMING_SNAKE_CASE_    ,						std=SCREAMING_SNAKE_CASE_    ,						data_format=SCREAMING_SNAKE_CASE_    ,						**SCREAMING_SNAKE_CASE_      )


					def 						UpperCAmelCase						(							self    :	Union[str, Any]    ,						UpperCAmelCase    :	ImageInput    ,						UpperCAmelCase    :	bool = None    ,						UpperCAmelCase    :	Dict[str, int] = None    ,						UpperCAmelCase    :	PILImageResampling = None    ,						UpperCAmelCase    :	bool = None    ,						UpperCAmelCase    :	int = None    ,						UpperCAmelCase    :	bool = None    ,						UpperCAmelCase    :	float = None    ,						UpperCAmelCase    :	bool = None    ,						UpperCAmelCase    :	Optional[Union[float, List[float]]] = None    ,						UpperCAmelCase    :	Optional[Union[float, List[float]]] = None    ,						UpperCAmelCase    :	bool = None    ,						UpperCAmelCase    :	Optional[Union[str, TensorType]] = None    ,						UpperCAmelCase    :	Optional[ChannelDimension] = ChannelDimension.FIRST    ,						**UpperCAmelCase    :	Any    ,						)							->			List[str]:
						__lowerCAmelCase:     Dict     			=   do_resize if do_resize is not None else self.do_resize
						__lowerCAmelCase:     List[str]     			=   size if size is not None else self.size
						__lowerCAmelCase:     List[Any]     			=   get_size_dict(SCREAMING_SNAKE_CASE_    ,						default_to_square=SCREAMING_SNAKE_CASE_      )
						__lowerCAmelCase:     Optional[int]     			=   resample if resample is not None else self.resample
						__lowerCAmelCase:     Optional[Any]     			=   do_center_crop if do_center_crop is not None else self.do_center_crop
						__lowerCAmelCase:     List[Any]     			=   crop_size if crop_size is not None else self.crop_size
						__lowerCAmelCase:     int     			=   get_size_dict(SCREAMING_SNAKE_CASE_      )
						__lowerCAmelCase:     List[str]     			=   do_rescale if do_rescale is not None else self.do_rescale
						__lowerCAmelCase:     Optional[Any]     			=   rescale_factor if rescale_factor is not None else self.rescale_factor
						__lowerCAmelCase:     Tuple     			=   do_normalize if do_normalize is not None else self.do_normalize
						__lowerCAmelCase:     Optional[Any]     			=   image_mean if image_mean is not None else self.image_mean
						__lowerCAmelCase:     Dict     			=   image_std if image_std is not None else self.image_std
						__lowerCAmelCase:     Any     			=   do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

						__lowerCAmelCase:     Tuple     			=   make_list_of_images(SCREAMING_SNAKE_CASE_      )

						if not valid_images(SCREAMING_SNAKE_CASE_      ):
							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_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.'      )

						# PIL RGBA images are converted to RGB
						if do_convert_rgb:
							__lowerCAmelCase:     Tuple     			=   [convert_to_rgb(SCREAMING_SNAKE_CASE_      ) for image in images]

						# All transformations expect numpy arrays.
						__lowerCAmelCase:     str     			=   [to_numpy_array(SCREAMING_SNAKE_CASE_      ) for image in images]

						if do_resize:
							__lowerCAmelCase:     int     			=   [self.resize(image=SCREAMING_SNAKE_CASE_    ,						size=SCREAMING_SNAKE_CASE_    ,						resample=SCREAMING_SNAKE_CASE_      ) for image in images]

						if do_center_crop:
							__lowerCAmelCase:     Dict     			=   [self.center_crop(image=SCREAMING_SNAKE_CASE_    ,						size=SCREAMING_SNAKE_CASE_      ) for image in images]

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

						if do_normalize:
							__lowerCAmelCase:     str     			=   [self.normalize(image=SCREAMING_SNAKE_CASE_    ,						mean=SCREAMING_SNAKE_CASE_    ,						std=SCREAMING_SNAKE_CASE_      ) for image in images]

						__lowerCAmelCase:     List[Any]     			=   [to_channel_dimension_format(SCREAMING_SNAKE_CASE_    ,						SCREAMING_SNAKE_CASE_      ) for image in images]

						__lowerCAmelCase:     str     			=   {'pixel_values': images}
						return BatchFeature(data=SCREAMING_SNAKE_CASE_    ,						tensor_type=SCREAMING_SNAKE_CASE_      )








# 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

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
    is_vision_available,
)


_a	 =     {
    '''configuration_tvlt''': ['''TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''TvltConfig'''],
    '''feature_extraction_tvlt''': ['''TvltFeatureExtractor'''],
    '''processing_tvlt''': ['''TvltProcessor'''],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _a	 =     [
      '''TVLT_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''TvltModel''',
      '''TvltForPreTraining''',
      '''TvltForAudioVisualClassification''',
      '''TvltPreTrainedModel''',
  ]

try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _a	 =     ['''TvltImageProcessor''']


if TYPE_CHECKING:
  from .configuration_tvlt import TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP, TvltConfig
  from .processing_tvlt import TvltProcessor
  from .feature_extraction_tvlt import TvltFeatureExtractor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tvlt import (
        TVLT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TvltForAudioVisualClassification,
        TvltForPreTraining,
        TvltModel,
        TvltPreTrainedModel,
    )

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .image_processing_tvlt import TvltImageProcessor


else:
  import sys

  _a	 =     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





