





"""simple docstring"""





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,
    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,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
      import PIL


lowercase__				:str				   =       logging.get_logger(__name__)




class 							snake_case							(			__UpperCAmelCase ):

      '''simple docstring'''



      _A     :       Optional[int]         =       ['pixel_values']

      def __init__(							self       :      int						,				__lowercase       :      bool = True						,				__lowercase       :      Dict[str, int] = None						,				__lowercase       :      float = None						,				__lowercase       :      PILImageResampling = PILImageResampling.BILINEAR						,				__lowercase       :      bool = True						,				__lowercase       :      Union[int, float] = 1 / 255						,				__lowercase       :      bool = True						,				__lowercase       :      Optional[Union[float, List[float]]] = None						,				__lowercase       :      Optional[Union[float, List[float]]] = None						,				**__lowercase       :      List[Any]						,				):


        '''simple docstring'''




        super().__init__(**lowerCAmelCase_ )
        __UpperCAmelCase    :						List[Any]       =						size if size is not None else {'''shortest_edge''': 384}
        __UpperCAmelCase    :						Union[str, Any]       =						get_size_dict(lowerCAmelCase_						,				default_to_square=lowerCAmelCase_ )

        __UpperCAmelCase    :						str       =						do_resize
        __UpperCAmelCase    :						Optional[int]       =						size
        # Default value set here for backwards compatibility where the value in config is None
        __UpperCAmelCase    :						Tuple       =						crop_pct if crop_pct is not None else 224 / 256
        __UpperCAmelCase    :						List[str]       =						resample
        __UpperCAmelCase    :						Any       =						do_rescale
        __UpperCAmelCase    :						str       =						rescale_factor
        __UpperCAmelCase    :						Optional[int]       =						do_normalize
        __UpperCAmelCase    :						Optional[Any]       =						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        __UpperCAmelCase    :						Optional[int]       =						image_std if image_std is not None else IMAGENET_STANDARD_STD

      def       A_					(							self       :      Union[str, Any]						,				__lowercase       :      np.ndarray						,				__lowercase       :      Dict[str, int]						,				__lowercase       :      float						,				__lowercase       :      PILImageResampling = PILImageResampling.BICUBIC						,				__lowercase       :      Optional[Union[str, ChannelDimension]] = None						,				**__lowercase       :      Optional[int]						,				):


        '''simple docstring'''




        __UpperCAmelCase    :						Optional[int]       =						get_size_dict(lowerCAmelCase_						,				default_to_square=lowerCAmelCase_ )
        if "shortest_edge" not in size:
          raise ValueError(f'''Size dictionary must contain \'shortest_edge\' key. Got {size.keys()}''' )
        __UpperCAmelCase    :						Optional[int]       =						size['''shortest_edge''']

        if shortest_edge < 384:
          # maintain same ratio, resizing shortest edge to shortest_edge/crop_pct
          __UpperCAmelCase    :						Any       =						int(shortest_edge / crop_pct )
          __UpperCAmelCase    :						Optional[Any]       =						get_resize_output_image_size(lowerCAmelCase_						,				size=lowerCAmelCase_						,				default_to_square=lowerCAmelCase_ )
          __UpperCAmelCase    :						int       =						resize(image=lowerCAmelCase_						,				size=lowerCAmelCase_						,				resample=lowerCAmelCase_						,				data_format=lowerCAmelCase_						,				**lowerCAmelCase_ )
          # then crop to (shortest_edge, shortest_edge)
          return center_crop(image=lowerCAmelCase_						,				size=(shortest_edge, shortest_edge)						,				data_format=lowerCAmelCase_						,				**lowerCAmelCase_ )
        else:
          # warping (no cropping) when evaluated at 384 or larger
          return resize(
              lowerCAmelCase_						,				size=(shortest_edge, shortest_edge)						,				resample=lowerCAmelCase_						,				data_format=lowerCAmelCase_						,				**lowerCAmelCase_ )

      def       A_					(							self       :      List[Any]						,				__lowercase       :      np.ndarray						,				__lowercase       :      Union[int, float]						,				__lowercase       :      Optional[Union[str, ChannelDimension]] = None						,				**__lowercase       :      Dict						,				):


        '''simple docstring'''




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

      def       A_					(							self       :      List[str]						,				__lowercase       :      np.ndarray						,				__lowercase       :      Union[float, List[float]]						,				__lowercase       :      Union[float, List[float]]						,				__lowercase       :      Optional[Union[str, ChannelDimension]] = None						,				**__lowercase       :      List[str]						,				):


        '''simple docstring'''




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







      def       A_					(							self       :      Dict						,				__lowercase       :      ImageInput						,				__lowercase       :      bool = None						,				__lowercase       :      Dict[str, int] = None						,				__lowercase       :      float = None						,				__lowercase       :      PILImageResampling = None						,				__lowercase       :      bool = None						,				__lowercase       :      float = None						,				__lowercase       :      bool = None						,				__lowercase       :      Optional[Union[float, List[float]]] = None						,				__lowercase       :      Optional[Union[float, List[float]]] = None						,				__lowercase       :      Optional[Union[str, TensorType]] = None						,				__lowercase       :      ChannelDimension = ChannelDimension.FIRST						,				**__lowercase       :      Optional[int]						,				):


        '''simple docstring'''




        __UpperCAmelCase    :						int       =						do_resize if do_resize is not None else self.do_resize
        __UpperCAmelCase    :						Union[str, Any]       =						crop_pct if crop_pct is not None else self.crop_pct
        __UpperCAmelCase    :						Optional[Any]       =						resample if resample is not None else self.resample
        __UpperCAmelCase    :						Tuple       =						do_rescale if do_rescale is not None else self.do_rescale
        __UpperCAmelCase    :						Union[str, Any]       =						rescale_factor if rescale_factor is not None else self.rescale_factor
        __UpperCAmelCase    :						Dict       =						do_normalize if do_normalize is not None else self.do_normalize
        __UpperCAmelCase    :						Optional[int]       =						image_mean if image_mean is not None else self.image_mean
        __UpperCAmelCase    :						Optional[Any]       =						image_std if image_std is not None else self.image_std

        __UpperCAmelCase    :						List[Any]       =						size if size is not None else self.size
        __UpperCAmelCase    :						Union[str, Any]       =						get_size_dict(lowerCAmelCase_						,				default_to_square=lowerCAmelCase_ )

        __UpperCAmelCase    :						Optional[Any]       =						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_resize and size is None or resample is None:
          raise ValueError('''Size and resample must be specified if do_resize is True.''' )

        if do_resize and size["shortest_edge"] < 384 and crop_pct is None:
          raise ValueError('''crop_pct must be specified if size < 384.''' )

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

        # All transformations expect numpy arrays.
        __UpperCAmelCase    :						Optional[Any]       =						[to_numpy_array(lowerCAmelCase_ ) for image in images]

        if do_resize:
          __UpperCAmelCase    :						Dict       =						[self.resize(image=lowerCAmelCase_						,				size=lowerCAmelCase_						,				crop_pct=lowerCAmelCase_						,				resample=lowerCAmelCase_ ) for image in images]

        if do_rescale:
          __UpperCAmelCase    :						Tuple       =						[self.rescale(image=lowerCAmelCase_						,				scale=lowerCAmelCase_ ) for image in images]

        if do_normalize:
          __UpperCAmelCase    :						List[str]       =						[self.normalize(image=lowerCAmelCase_						,				mean=lowerCAmelCase_						,				std=lowerCAmelCase_ ) for image in images]

        __UpperCAmelCase    :						Any       =						[to_channel_dimension_format(lowerCAmelCase_						,				lowerCAmelCase_ ) for image in images]

        __UpperCAmelCase    :						Tuple       =						{'''pixel_values''': images}
        return BatchFeature(data=lowerCAmelCase_						,				tensor_type=lowerCAmelCase_ )






"""simple docstring"""





# coding=utf-8
# Copyright 2020 The HuggingFace Inc. team.
#
# 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.

# this script dumps information about the environment

import os
import sys

import transformers


lowercase__				:int				   =       '3'

print('Python version:', sys.version)
print('transformers version:', transformers.__version__)

try:
  import torch

  print('Torch version:', torch.__version__)
  print('Cuda available:', torch.cuda.is_available())
  print('Cuda version:', torch.version.cuda)
  print('CuDNN version:', torch.backends.cudnn.version())
  print('Number of GPUs available:', torch.cuda.device_count())
  print('NCCL version:', torch.cuda.nccl.version())
except ImportError:
  print('Torch version:', None)

try:
  import deepspeed

  print('DeepSpeed version:', deepspeed.__version__)
except ImportError:
  print('DeepSpeed version:', None)

try:
  import tensorflow as tf

  print('TensorFlow version:', tf.__version__)
  print('TF GPUs available:', bool(tf.config.list_physical_devices('GPU')))
  print('Number of TF GPUs available:', len(tf.config.list_physical_devices('GPU')))
except ImportError:
  print('TensorFlow version:', None)