'''simple docstring'''
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path
from shutil import copyfile

from huggingface_hub import HfFolder, Repository, create_repo, delete_repo
from requests.exceptions import HTTPError

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    PROCESSOR_MAPPING,
    TOKENIZER_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    AutoProcessor,
    AutoTokenizer,
    BertTokenizer,
    ProcessorMixin,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
    WavaVecaProcessor,
)
from transformers.testing_utils import TOKEN, USER, get_tests_dir, is_staging_test
from transformers.tokenization_utils import TOKENIZER_CONFIG_FILE
from transformers.utils import FEATURE_EXTRACTOR_NAME, is_tokenizers_available


sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils"))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402
from test_module.custom_processing import CustomProcessor  # noqa E402
from test_module.custom_tokenization import CustomTokenizer  # noqa E402


lowercase__  :      Tuple        =					get_tests_dir("fixtures/dummy_feature_extractor_config.json")
lowercase__  :      Union[str, Any]        =					get_tests_dir("fixtures/vocab.json")
lowercase__  :      Union[str, Any]        =					get_tests_dir("fixtures")







class lowerCamelCase							(	unittest.TestCase					):




  '''simple docstring'''



  lowerCAmelCase__										=	['''[UNK]''', '''[CLS]''', '''[SEP]''', '''[PAD]''', '''[MASK]''', '''bla''', '''blou''']






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->Optional[Any]:
        UpperCAmelCase_            =  0






  def  lowerCAmelCase__ (      self			:       List[Any]  )				->Union[str, Any]:
        UpperCAmelCase_            =  AutoProcessor.from_pretrained('''facebook/wav2vec2-base-960h'''  )
        self.assertIsInstance(snake_case__  ,							snake_case__  )






  def  lowerCAmelCase__ (      self			:       List[Any]  )				->int:
        with tempfile.TemporaryDirectory() as tmpdirname:
              UpperCAmelCase_            =  WavaVecaConfig()
              UpperCAmelCase_            =  AutoProcessor.from_pretrained('''facebook/wav2vec2-base-960h'''  )

              # save in new folder
              model_config.save_pretrained(snake_case__  )
              processor.save_pretrained(snake_case__  )

              UpperCAmelCase_            =  AutoProcessor.from_pretrained(snake_case__  )

        self.assertIsInstance(snake_case__  ,							snake_case__  )






  def  lowerCAmelCase__ (      self			:       Any  )				->Tuple:
        with tempfile.TemporaryDirectory() as tmpdirname:
              # copy relevant files
              copyfile(snake_case__  ,							os.path.join(snake_case__  ,							snake_case__  )  )
              copyfile(snake_case__  ,							os.path.join(snake_case__  ,							'''vocab.json'''  )  )

              UpperCAmelCase_            =  AutoProcessor.from_pretrained(snake_case__  )

        self.assertIsInstance(snake_case__  ,							snake_case__  )






  def  lowerCAmelCase__ (      self			:       int  )				->Union[str, Any]:
        with tempfile.TemporaryDirectory() as tmpdirname:
              UpperCAmelCase_            =  WavaVecaFeatureExtractor()
              UpperCAmelCase_            =  AutoTokenizer.from_pretrained('''facebook/wav2vec2-base-960h'''  )

              UpperCAmelCase_            =  WavaVecaProcessor(snake_case__  ,							snake_case__  )

              # save in new folder
              processor.save_pretrained(snake_case__  )

              # drop `processor_class` in tokenizer
              with open(os.path.join(snake_case__  ,							snake_case__  )  ,							'''r'''  ) as f:
                    UpperCAmelCase_            =  json.load(snake_case__  )
                    config_dict.pop('''processor_class'''  )

              with open(os.path.join(snake_case__  ,							snake_case__  )  ,							'''w'''  ) as f:
                    f.write(json.dumps(snake_case__  )  )

              UpperCAmelCase_            =  AutoProcessor.from_pretrained(snake_case__  )

        self.assertIsInstance(snake_case__  ,							snake_case__  )






  def  lowerCAmelCase__ (      self			:       Any  )				->Optional[Any]:
        with tempfile.TemporaryDirectory() as tmpdirname:
              UpperCAmelCase_            =  WavaVecaFeatureExtractor()
              UpperCAmelCase_            =  AutoTokenizer.from_pretrained('''facebook/wav2vec2-base-960h'''  )

              UpperCAmelCase_            =  WavaVecaProcessor(snake_case__  ,							snake_case__  )

              # save in new folder
              processor.save_pretrained(snake_case__  )

              # drop `processor_class` in feature extractor
              with open(os.path.join(snake_case__  ,							snake_case__  )  ,							'''r'''  ) as f:
                    UpperCAmelCase_            =  json.load(snake_case__  )
                    config_dict.pop('''processor_class'''  )

              with open(os.path.join(snake_case__  ,							snake_case__  )  ,							'''w'''  ) as f:
                    f.write(json.dumps(snake_case__  )  )

              UpperCAmelCase_            =  AutoProcessor.from_pretrained(snake_case__  )

        self.assertIsInstance(snake_case__  ,							snake_case__  )






  def  lowerCAmelCase__ (      self			:       str  )				->List[str]:
        with tempfile.TemporaryDirectory() as tmpdirname:
              UpperCAmelCase_            =  WavaVecaConfig(processor_class='''Wav2Vec2Processor'''  )
              model_config.save_pretrained(snake_case__  )
              # copy relevant files
              copyfile(snake_case__  ,							os.path.join(snake_case__  ,							'''vocab.json'''  )  )
              # create emtpy sample processor
              with open(os.path.join(snake_case__  ,							snake_case__  )  ,							'''w'''  ) as f:
                    f.write('''{}'''  )

              UpperCAmelCase_            =  AutoProcessor.from_pretrained(snake_case__  )

        self.assertIsInstance(snake_case__  ,							snake_case__  )






  def  lowerCAmelCase__ (      self			:       Tuple  )				->int:
        # If remote code is not set, we will time out when asking whether to load the model.
        with self.assertRaises(snake_case__  ):
              UpperCAmelCase_            =  AutoProcessor.from_pretrained('''hf-internal-testing/test_dynamic_processor'''  )
        # If remote code is disabled, we can't load this config.
        with self.assertRaises(snake_case__  ):
              UpperCAmelCase_            =  AutoProcessor.from_pretrained(
                  '''hf-internal-testing/test_dynamic_processor'''  ,							trust_remote_code=snake_case__  )

        UpperCAmelCase_            =  AutoProcessor.from_pretrained('''hf-internal-testing/test_dynamic_processor'''  ,							trust_remote_code=snake_case__  )
        self.assertTrue(processor.special_attribute_present  )
        self.assertEqual(processor.__class__.__name__  ,							'''NewProcessor'''  )

        UpperCAmelCase_            =  processor.feature_extractor
        self.assertTrue(feature_extractor.special_attribute_present  )
        self.assertEqual(feature_extractor.__class__.__name__  ,							'''NewFeatureExtractor'''  )

        UpperCAmelCase_            =  processor.tokenizer
        self.assertTrue(tokenizer.special_attribute_present  )
        if is_tokenizers_available():
              self.assertEqual(tokenizer.__class__.__name__  ,							'''NewTokenizerFast'''  )

              # Test we can also load the slow version
              UpperCAmelCase_            =  AutoProcessor.from_pretrained(
                  '''hf-internal-testing/test_dynamic_processor'''  ,							trust_remote_code=snake_case__  ,							use_fast=snake_case__  )
              UpperCAmelCase_            =  new_processor.tokenizer
              self.assertTrue(new_tokenizer.special_attribute_present  )
              self.assertEqual(new_tokenizer.__class__.__name__  ,							'''NewTokenizer'''  )
        else:
              self.assertEqual(tokenizer.__class__.__name__  ,							'''NewTokenizer'''  )






  def  lowerCAmelCase__ (      self			:       Union[str, Any]  )				->Optional[Any]:
        try:
              AutoConfig.register('''custom'''  ,							snake_case__  )
              AutoFeatureExtractor.register(snake_case__  ,							snake_case__  )
              AutoTokenizer.register(snake_case__  ,							slow_tokenizer_class=snake_case__  )
              AutoProcessor.register(snake_case__  ,							snake_case__  )
              # Trying to register something existing in the Transformers library will raise an error
              with self.assertRaises(snake_case__  ):
                    AutoProcessor.register(snake_case__  ,							snake_case__  )

              # Now that the config is registered, it can be used as any other config with the auto-API
              UpperCAmelCase_            =  CustomFeatureExtractor.from_pretrained(snake_case__  )

              with tempfile.TemporaryDirectory() as tmp_dir:
                    UpperCAmelCase_            =  os.path.join(snake_case__  ,							'''vocab.txt'''  )
                    with open(snake_case__  ,							'''w'''  ,							encoding='''utf-8'''  ) as vocab_writer:
                          vocab_writer.write(''''''.join([x + '''\n''' for x in self.vocab_tokens]  )  )
                    UpperCAmelCase_            =  CustomTokenizer(snake_case__  )

              UpperCAmelCase_            =  CustomProcessor(snake_case__  ,							snake_case__  )

              with tempfile.TemporaryDirectory() as tmp_dir:
                    processor.save_pretrained(snake_case__  )
                    UpperCAmelCase_            =  AutoProcessor.from_pretrained(snake_case__  )
                    self.assertIsInstance(snake_case__  ,							snake_case__  )

        finally:
              if "custom" in CONFIG_MAPPING._extra_content:
                    del CONFIG_MAPPING._extra_content["custom"]
              if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                    del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]
              if CustomConfig in TOKENIZER_MAPPING._extra_content:
                    del TOKENIZER_MAPPING._extra_content[CustomConfig]
              if CustomConfig in PROCESSOR_MAPPING._extra_content:
                    del PROCESSOR_MAPPING._extra_content[CustomConfig]






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->Tuple:







        class lowerCamelCase							(	__a					):




          '''simple docstring'''



          lowerCAmelCase__										=	False







        class lowerCamelCase							(	__a					):




          '''simple docstring'''



          lowerCAmelCase__										=	False







        class lowerCamelCase							(	__a					):




          '''simple docstring'''



          lowerCAmelCase__										=	'''AutoFeatureExtractor'''
          lowerCAmelCase__										=	'''AutoTokenizer'''
          lowerCAmelCase__										=	False

        try:
              AutoConfig.register('''custom'''  ,							snake_case__  )
              AutoFeatureExtractor.register(snake_case__  ,							snake_case__  )
              AutoTokenizer.register(snake_case__  ,							slow_tokenizer_class=snake_case__  )
              AutoProcessor.register(snake_case__  ,							snake_case__  )
              # If remote code is not set, the default is to use local classes.
              UpperCAmelCase_            =  AutoProcessor.from_pretrained('''hf-internal-testing/test_dynamic_processor'''  )
              self.assertEqual(processor.__class__.__name__  ,							'''NewProcessor'''  )
              self.assertFalse(processor.special_attribute_present  )
              self.assertFalse(processor.feature_extractor.special_attribute_present  )
              self.assertFalse(processor.tokenizer.special_attribute_present  )

              # If remote code is disabled, we load the local ones.
              UpperCAmelCase_            =  AutoProcessor.from_pretrained(
                  '''hf-internal-testing/test_dynamic_processor'''  ,							trust_remote_code=snake_case__  )
              self.assertEqual(processor.__class__.__name__  ,							'''NewProcessor'''  )
              self.assertFalse(processor.special_attribute_present  )
              self.assertFalse(processor.feature_extractor.special_attribute_present  )
              self.assertFalse(processor.tokenizer.special_attribute_present  )

              # If remote is enabled, we load from the Hub.
              UpperCAmelCase_            =  AutoProcessor.from_pretrained(
                  '''hf-internal-testing/test_dynamic_processor'''  ,							trust_remote_code=snake_case__  )
              self.assertEqual(processor.__class__.__name__  ,							'''NewProcessor'''  )
              self.assertTrue(processor.special_attribute_present  )
              self.assertTrue(processor.feature_extractor.special_attribute_present  )
              self.assertTrue(processor.tokenizer.special_attribute_present  )

        finally:
              if "custom" in CONFIG_MAPPING._extra_content:
                    del CONFIG_MAPPING._extra_content["custom"]
              if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                    del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]
              if CustomConfig in TOKENIZER_MAPPING._extra_content:
                    del TOKENIZER_MAPPING._extra_content[CustomConfig]
              if CustomConfig in PROCESSOR_MAPPING._extra_content:
                    del PROCESSOR_MAPPING._extra_content[CustomConfig]






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->Optional[int]:
        UpperCAmelCase_            =  AutoProcessor.from_pretrained('''hf-internal-testing/tiny-random-bert'''  )
        self.assertEqual(processor.__class__.__name__  ,							'''BertTokenizerFast'''  )






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->str:
        UpperCAmelCase_            =  AutoProcessor.from_pretrained('''hf-internal-testing/tiny-random-convnext'''  )
        self.assertEqual(processor.__class__.__name__  ,							'''ConvNextImageProcessor'''  )







@is_staging_test
class lowerCamelCase							(	unittest.TestCase					):




  '''simple docstring'''



  lowerCAmelCase__										=	['''[UNK]''', '''[CLS]''', '''[SEP]''', '''[PAD]''', '''[MASK]''', '''bla''', '''blou''']






  @classmethod
  def  lowerCAmelCase__ (      cls			:       Optional[int]  )				->Tuple:
        UpperCAmelCase_            =  TOKEN
        HfFolder.save_token(snake_case__  )






  @classmethod
  def  lowerCAmelCase__ (      cls			:       Union[str, Any]  )				->Union[str, Any]:
        try:
              delete_repo(token=cls._token  ,							repo_id='''test-processor'''  )
        except HTTPError:
              pass

        try:
              delete_repo(token=cls._token  ,							repo_id='''valid_org/test-processor-org'''  )
        except HTTPError:
              pass

        try:
              delete_repo(token=cls._token  ,							repo_id='''test-dynamic-processor'''  )
        except HTTPError:
              pass






  def  lowerCAmelCase__ (      self			:       List[str]  )				->Optional[Any]:
        UpperCAmelCase_            =  WavaVecaProcessor.from_pretrained(snake_case__  )
        with tempfile.TemporaryDirectory() as tmp_dir:
              processor.save_pretrained(
                  os.path.join(snake_case__  ,							'''test-processor'''  )  ,							push_to_hub=snake_case__  ,							use_auth_token=self._token  )

              UpperCAmelCase_            =  WavaVecaProcessor.from_pretrained(f"""{USER}/test-processor"""  )
              for k, v in processor.feature_extractor.__dict__.items():
                    self.assertEqual(snake_case__  ,							getattr(new_processor.feature_extractor  ,							snake_case__  )  )
              self.assertDictEqual(new_processor.tokenizer.get_vocab()  ,							processor.tokenizer.get_vocab()  )






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->Dict:
        UpperCAmelCase_            =  WavaVecaProcessor.from_pretrained(snake_case__  )

        with tempfile.TemporaryDirectory() as tmp_dir:
              processor.save_pretrained(
                  os.path.join(snake_case__  ,							'''test-processor-org'''  )  ,							push_to_hub=snake_case__  ,							use_auth_token=self._token  ,							organization='''valid_org'''  ,							)

              UpperCAmelCase_            =  WavaVecaProcessor.from_pretrained('''valid_org/test-processor-org'''  )
              for k, v in processor.feature_extractor.__dict__.items():
                    self.assertEqual(snake_case__  ,							getattr(new_processor.feature_extractor  ,							snake_case__  )  )
              self.assertDictEqual(new_processor.tokenizer.get_vocab()  ,							processor.tokenizer.get_vocab()  )






  def  lowerCAmelCase__ (      self			:       Tuple  )				->int:
        CustomFeatureExtractor.register_for_auto_class()
        CustomTokenizer.register_for_auto_class()
        CustomProcessor.register_for_auto_class()

        UpperCAmelCase_            =  CustomFeatureExtractor.from_pretrained(snake_case__  )

        with tempfile.TemporaryDirectory() as tmp_dir:
              UpperCAmelCase_            =  os.path.join(snake_case__  ,							'''vocab.txt'''  )
              with open(snake_case__  ,							'''w'''  ,							encoding='''utf-8'''  ) as vocab_writer:
                    vocab_writer.write(''''''.join([x + '''\n''' for x in self.vocab_tokens]  )  )
              UpperCAmelCase_            =  CustomTokenizer(snake_case__  )

        UpperCAmelCase_            =  CustomProcessor(snake_case__  ,							snake_case__  )

        with tempfile.TemporaryDirectory() as tmp_dir:
              create_repo(f"""{USER}/test-dynamic-processor"""  ,							token=self._token  )
              UpperCAmelCase_            =  Repository(snake_case__  ,							clone_from=f"""{USER}/test-dynamic-processor"""  ,							token=self._token  )
              processor.save_pretrained(snake_case__  )

              # This has added the proper auto_map field to the feature extractor config
              self.assertDictEqual(
                  processor.feature_extractor.auto_map  ,							{
                      '''AutoFeatureExtractor''': '''custom_feature_extraction.CustomFeatureExtractor''',
                      '''AutoProcessor''': '''custom_processing.CustomProcessor''',
                  }  ,							)

              # This has added the proper auto_map field to the tokenizer config
              with open(os.path.join(snake_case__  ,							'''tokenizer_config.json'''  )  ) as f:
                    UpperCAmelCase_            =  json.load(snake_case__  )
              self.assertDictEqual(
                  tokenizer_config['''auto_map''']  ,							{
                      '''AutoTokenizer''': ['''custom_tokenization.CustomTokenizer''', None],
                      '''AutoProcessor''': '''custom_processing.CustomProcessor''',
                  }  ,							)

              # The code has been copied from fixtures
              self.assertTrue(os.path.isfile(os.path.join(snake_case__  ,							'''custom_feature_extraction.py'''  )  )  )
              self.assertTrue(os.path.isfile(os.path.join(snake_case__  ,							'''custom_tokenization.py'''  )  )  )
              self.assertTrue(os.path.isfile(os.path.join(snake_case__  ,							'''custom_processing.py'''  )  )  )

              repo.push_to_hub()

        UpperCAmelCase_            =  AutoProcessor.from_pretrained(f"""{USER}/test-dynamic-processor"""  ,							trust_remote_code=snake_case__  )
        # Can't make an isinstance check because the new_processor is from the CustomProcessor class of a dynamic module
        self.assertEqual(new_processor.__class__.__name__  ,							'''CustomProcessor'''  )


'''simple docstring'''
import unittest
from typing import Dict, List, Optional, Union

import numpy as np

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

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 BridgeTowerImageProcessor







class lowerCamelCase							(	unittest.TestCase					):




  '''simple docstring'''



  def __init__(      self			:       int  ,							UpperCAmelCase__			:       Dict  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Dict[str, int] = None  ,							UpperCAmelCase__			:       int = 32  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Union[int, float] = 1 / 255  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = [0.4814_5466, 0.457_8275, 0.4082_1073]  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = [0.2686_2954, 0.2613_0258, 0.2757_7711]  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Union[str, Any]=7  ,							UpperCAmelCase__			:       Optional[int]=30  ,							UpperCAmelCase__			:       Union[str, Any]=400  ,							UpperCAmelCase__			:       List[Any]=3  ,							)				->Dict:
        UpperCAmelCase_            =  parent
        UpperCAmelCase_            =  do_resize
        UpperCAmelCase_            =  size if size is not None else {'''shortest_edge''': 288}
        UpperCAmelCase_            =  size_divisor
        UpperCAmelCase_            =  do_rescale
        UpperCAmelCase_            =  rescale_factor
        UpperCAmelCase_            =  do_normalize
        UpperCAmelCase_            =  do_center_crop
        UpperCAmelCase_            =  image_mean
        UpperCAmelCase_            =  image_std
        UpperCAmelCase_            =  do_pad
        UpperCAmelCase_            =  batch_size
        UpperCAmelCase_            =  num_channels
        UpperCAmelCase_            =  min_resolution
        UpperCAmelCase_            =  max_resolution






  def  lowerCAmelCase__ (      self			:       Tuple  )				->List[Any]:
        return {
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_normalize": self.do_normalize,
            "do_resize": self.do_resize,
            "size": self.size,
            "size_divisor": self.size_divisor,
        }






  def  lowerCAmelCase__ (      self			:       Optional[int]  ,							UpperCAmelCase__			:       List[str]  ,							UpperCAmelCase__			:       Dict=False  )				->Any:
        if not batched:
              UpperCAmelCase_            =  self.size['''shortest_edge''']
              UpperCAmelCase_            =  image_inputs[0]
              if isinstance(UpperCAmelCase__  ,							Image.Image  ):
                    UpperCAmelCase_      ,		UpperCAmelCase_            =  image.size
              else:
                    UpperCAmelCase_      ,		UpperCAmelCase_            =  image.shape[1], image.shape[2]
              UpperCAmelCase_            =  size / min(UpperCAmelCase__  ,							UpperCAmelCase__  )
              if h < w:
                    UpperCAmelCase_      ,		UpperCAmelCase_            =  size, scale * w
              else:
                    UpperCAmelCase_      ,		UpperCAmelCase_            =  scale * h, size

              UpperCAmelCase_            =  int((1333 / 800) * size  )
              if max(UpperCAmelCase__  ,							UpperCAmelCase__  ) > max_size:
                    UpperCAmelCase_            =  max_size / max(UpperCAmelCase__  ,							UpperCAmelCase__  )
                    UpperCAmelCase_            =  newh * scale
                    UpperCAmelCase_            =  neww * scale

              UpperCAmelCase_      ,		UpperCAmelCase_            =  int(newh + 0.5  ), int(neww + 0.5  )
              UpperCAmelCase_      ,		UpperCAmelCase_            =  (
                  newh // self.size_divisor * self.size_divisor,
                  neww // self.size_divisor * self.size_divisor,
              )

        else:
              UpperCAmelCase_            =  []
              for image in image_inputs:
                    UpperCAmelCase_      ,		UpperCAmelCase_            =  self.get_expected_values([image]  )
                    expected_values.append((expected_height, expected_width)  )
              UpperCAmelCase_            =  max(UpperCAmelCase__  ,							key=lambda UpperCAmelCase__  : item[0]  )[0]
              UpperCAmelCase_            =  max(UpperCAmelCase__  ,							key=lambda UpperCAmelCase__  : item[1]  )[1]

        return expected_height, expected_width







@require_torch
@require_vision
class lowerCamelCase							(	lowerCamelCase     ,		unittest.TestCase					):




  '''simple docstring'''



  lowerCAmelCase__										=	BridgeTowerImageProcessor if is_vision_available() else None






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->str:
        UpperCAmelCase_            =  BridgeTowerImageProcessingTester(self  )






  @property
  def  lowerCAmelCase__ (      self			:       List[str]  )				->Dict:
        return self.image_processor_tester.prepare_image_processor_dict()






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->int:
        UpperCAmelCase_            =  self.image_processing_class(**self.image_processor_dict  )
        self.assertTrue(hasattr(UpperCAmelCase__  ,							'''image_mean'''  )  )
        self.assertTrue(hasattr(UpperCAmelCase__  ,							'''image_std'''  )  )
        self.assertTrue(hasattr(UpperCAmelCase__  ,							'''do_normalize'''  )  )
        self.assertTrue(hasattr(UpperCAmelCase__  ,							'''do_resize'''  )  )
        self.assertTrue(hasattr(UpperCAmelCase__  ,							'''size'''  )  )
        self.assertTrue(hasattr(UpperCAmelCase__  ,							'''size_divisor'''  )  )






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->Union[str, Any]:
        pass






  def  lowerCAmelCase__ (      self			:       List[str]  )				->Union[str, Any]:
        # Initialize image processor
        UpperCAmelCase_            =  self.image_processing_class(**self.image_processor_dict  )
        # create random PIL images
        UpperCAmelCase_            =  prepare_image_inputs(self.image_processor_tester  ,							equal_resolution=UpperCAmelCase__  )
        for image in image_inputs:
              self.assertIsInstance(UpperCAmelCase__  ,							Image.Image  )

        # Test not batched input
        UpperCAmelCase_            =  image_processing(image_inputs[0]  ,							return_tensors='''pt'''  ).pixel_values

        UpperCAmelCase_      ,		UpperCAmelCase_            =  self.image_processor_tester.get_expected_values(UpperCAmelCase__  )
        self.assertEqual(
            encoded_images.shape  ,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)  ,							)

        # Test batched
        UpperCAmelCase_            =  image_processing(UpperCAmelCase__  ,							return_tensors='''pt'''  ).pixel_values

        UpperCAmelCase_      ,		UpperCAmelCase_            =  self.image_processor_tester.get_expected_values(UpperCAmelCase__  ,							batched=UpperCAmelCase__  )
        self.assertEqual(
            encoded_images.shape  ,							(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )  ,							)






  def  lowerCAmelCase__ (      self			:       Any  )				->Optional[int]:
        # Initialize image processor
        UpperCAmelCase_            =  self.image_processing_class(**self.image_processor_dict  )
        # create random numpy tensors
        UpperCAmelCase_            =  prepare_image_inputs(self.image_processor_tester  ,							equal_resolution=UpperCAmelCase__  ,							numpify=UpperCAmelCase__  )
        for image in image_inputs:
              self.assertIsInstance(UpperCAmelCase__  ,							np.ndarray  )

        # Test not batched input
        UpperCAmelCase_            =  image_processing(image_inputs[0]  ,							return_tensors='''pt'''  ).pixel_values

        UpperCAmelCase_      ,		UpperCAmelCase_            =  self.image_processor_tester.get_expected_values(UpperCAmelCase__  )
        self.assertEqual(
            encoded_images.shape  ,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)  ,							)

        # Test batched
        UpperCAmelCase_            =  image_processing(UpperCAmelCase__  ,							return_tensors='''pt'''  ).pixel_values

        UpperCAmelCase_      ,		UpperCAmelCase_            =  self.image_processor_tester.get_expected_values(UpperCAmelCase__  ,							batched=UpperCAmelCase__  )
        self.assertEqual(
            encoded_images.shape  ,							(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )  ,							)






  def  lowerCAmelCase__ (      self			:       int  )				->List[str]:
        # Initialize image processor
        UpperCAmelCase_            =  self.image_processing_class(**self.image_processor_dict  )
        # create random PyTorch tensors
        UpperCAmelCase_            =  prepare_image_inputs(self.image_processor_tester  ,							equal_resolution=UpperCAmelCase__  ,							torchify=UpperCAmelCase__  )
        for image in image_inputs:
              self.assertIsInstance(UpperCAmelCase__  ,							torch.Tensor  )

        # Test not batched input
        UpperCAmelCase_            =  image_processing(image_inputs[0]  ,							return_tensors='''pt'''  ).pixel_values

        UpperCAmelCase_      ,		UpperCAmelCase_            =  self.image_processor_tester.get_expected_values(UpperCAmelCase__  )
        self.assertEqual(
            encoded_images.shape  ,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)  ,							)

        # Test batched
        UpperCAmelCase_            =  image_processing(UpperCAmelCase__  ,							return_tensors='''pt'''  ).pixel_values

        UpperCAmelCase_      ,		UpperCAmelCase_            =  self.image_processor_tester.get_expected_values(UpperCAmelCase__  ,							batched=UpperCAmelCase__  )
        self.assertEqual(
            encoded_images.shape  ,							(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )  ,							)





