'''simple docstring'''





import unittest

import numpy as np

from transformers.file_utils import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import DPTImageProcessor




class  __magic_name__  (		unittest.TestCase    ):





   """simple docstring"""




   def __init__(	self					:  List[str]		,  _lowercase					:  List[str]		,  _lowercase					:  Dict=7		,  _lowercase					:  List[str]=3		,  _lowercase					:  str=18		,  _lowercase					:  int=30		,  _lowercase					:  Optional[Any]=400		,  _lowercase					:  List[str]=True		,  _lowercase					:  str=None		,  _lowercase					:  int=True		,  _lowercase					:  List[Any]=[0.5, 0.5, 0.5]		,  _lowercase					:  Union[str, Any]=[0.5, 0.5, 0.5]		,  ):



    """simple docstring"""



    _UpperCamelCase:     Optional[int]							= size if size is not None else {'''height''': 18, '''width''': 18}
    _UpperCamelCase:     Tuple							= parent
    _UpperCamelCase:     Optional[Any]							= batch_size
    _UpperCamelCase:     Optional[int]							= num_channels
    _UpperCamelCase:     Dict							= image_size
    _UpperCamelCase:     Optional[Any]							= min_resolution
    _UpperCamelCase:     Dict							= max_resolution
    _UpperCamelCase:     Any							= do_resize
    _UpperCamelCase:     Optional[int]							= size
    _UpperCamelCase:     Tuple							= do_normalize
    _UpperCamelCase:     str							= image_mean
    _UpperCamelCase:     List[str]							= image_std



   def   lowerCAmelCase						(	self					:  Any							):



    """simple docstring"""



    return {
        "image_mean": self.image_mean,
        "image_std": self.image_std,
        "do_normalize": self.do_normalize,
        "do_resize": self.do_resize,
        "size": self.size,
    }




@require_torch
@require_vision
class  __magic_name__  (		__a      ,	unittest.TestCase    ):





   """simple docstring"""




   lowerCAmelCase      :    List[Any]  			=   DPTImageProcessor if is_vision_available() else None



   def   lowerCAmelCase						(	self					:  Tuple							):



    """simple docstring"""



    _UpperCamelCase:     Dict							= DPTImageProcessingTester(self							)



   @property
   def   lowerCAmelCase						(	self					:  Union[str, Any]							):



    """simple docstring"""



    return self.image_processor_tester.prepare_image_processor_dict()



   def   lowerCAmelCase						(	self					:  Any							):



    """simple docstring"""



    _UpperCamelCase:     List[Any]							= self.image_processing_class(**self.image_processor_dict							)
    self.assertTrue(hasattr(_lowercase		,  '''image_mean'''							)							)
    self.assertTrue(hasattr(_lowercase		,  '''image_std'''							)							)
    self.assertTrue(hasattr(_lowercase		,  '''do_normalize'''							)							)
    self.assertTrue(hasattr(_lowercase		,  '''do_resize'''							)							)
    self.assertTrue(hasattr(_lowercase		,  '''size'''							)							)



   def   lowerCAmelCase						(	self					:  str							):



    """simple docstring"""



    _UpperCamelCase:     Optional[Any]							= self.image_processing_class.from_dict(self.image_processor_dict							)
    self.assertEqual(image_processor.size		,  {'''height''': 18, '''width''': 18}							)

    _UpperCamelCase:     Tuple							= self.image_processing_class.from_dict(self.image_processor_dict		,  size=42							)
    self.assertEqual(image_processor.size		,  {'''height''': 42, '''width''': 42}							)



   def   lowerCAmelCase						(	self					:  Dict							):



    """simple docstring"""



    _UpperCamelCase:     Optional[Any]							= self.image_processing_class(**self.image_processor_dict							)
    # create random PIL images
    _UpperCamelCase:     Tuple							= prepare_image_inputs(self.image_processor_tester		,  equal_resolution=_lowercase							)
    for image in image_inputs:
     self.assertIsInstance(_lowercase		,  Image.Image							)

    # Test not batched input
    _UpperCamelCase:     Optional[Any]							= image_processing(image_inputs[0]		,  return_tensors='''pt'''							).pixel_values
    self.assertEqual(
        encoded_images.shape		,  (
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.size['''height'''],
            self.image_processor_tester.size['''width'''],
        )		,  )

    # Test batched
    _UpperCamelCase:     List[Any]							= image_processing(_lowercase		,  return_tensors='''pt'''							).pixel_values
    self.assertEqual(
        encoded_images.shape		,  (
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.size['''height'''],
            self.image_processor_tester.size['''width'''],
        )		,  )



   def   lowerCAmelCase						(	self					:  int							):



    """simple docstring"""



    _UpperCamelCase:     Optional[int]							= self.image_processing_class(**self.image_processor_dict							)
    # create random numpy tensors
    _UpperCamelCase:     List[Any]							= prepare_image_inputs(self.image_processor_tester		,  equal_resolution=_lowercase		,  numpify=_lowercase							)
    for image in image_inputs:
     self.assertIsInstance(_lowercase		,  np.ndarray							)

    # Test not batched input
    _UpperCamelCase:     List[str]							= image_processing(image_inputs[0]		,  return_tensors='''pt'''							).pixel_values
    self.assertEqual(
        encoded_images.shape		,  (
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.size['''height'''],
            self.image_processor_tester.size['''width'''],
        )		,  )

    # Test batched
    _UpperCamelCase:     Any							= image_processing(_lowercase		,  return_tensors='''pt'''							).pixel_values
    self.assertEqual(
        encoded_images.shape		,  (
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.size['''height'''],
            self.image_processor_tester.size['''width'''],
        )		,  )



   def   lowerCAmelCase						(	self					:  int							):



    """simple docstring"""



    _UpperCamelCase:     List[str]							= self.image_processing_class(**self.image_processor_dict							)
    # create random PyTorch tensors
    _UpperCamelCase:     List[Any]							= prepare_image_inputs(self.image_processor_tester		,  equal_resolution=_lowercase		,  torchify=_lowercase							)
    for image in image_inputs:
     self.assertIsInstance(_lowercase		,  torch.Tensor							)

    # Test not batched input
    _UpperCamelCase:     Union[str, Any]							= image_processing(image_inputs[0]		,  return_tensors='''pt'''							).pixel_values
    self.assertEqual(
        encoded_images.shape		,  (
            1,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.size['''height'''],
            self.image_processor_tester.size['''width'''],
        )		,  )

    # Test batched
    _UpperCamelCase:     int							= image_processing(_lowercase		,  return_tensors='''pt'''							).pixel_values
    self.assertEqual(
        encoded_images.shape		,  (
            self.image_processor_tester.batch_size,
            self.image_processor_tester.num_channels,
            self.image_processor_tester.size['''height'''],
            self.image_processor_tester.size['''width'''],
        )		,  )
import warnings

from ..trainer import Trainer
from ..utils import logging


UpperCAmelCase_			    =							logging.get_logger(__name__)




class  __magic_name__  (		__a    ):





   """simple docstring"""




   def __init__(	self					:  List[Any]		,  _lowercase					:  int=None		,  **_lowercase					:  Optional[Any]							):



    """simple docstring"""



    warnings.warn(
        '''`SageMakerTrainer` is deprecated and will be removed in v5 of Transformers. You can use `Trainer` '''
        '''instead.'''		,  _lowercase		,  )
    super().__init__(args=_lowercase		,  **_lowercase							)