




import unittest

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 ViTImageProcessor




class 		UpperCamelCase__     (unittest.TestCase					):

    '''simple docstring'''



    def __init__(   self					,  UpperCamelCase__					,  UpperCamelCase__=7					,  UpperCamelCase__=3					,  UpperCamelCase__=18					,  UpperCamelCase__=30					,  UpperCamelCase__=400					,  UpperCamelCase__=True					,  UpperCamelCase__=None					,  UpperCamelCase__=True					,  UpperCamelCase__=[0.5, 0.5, 0.5]					,  UpperCamelCase__=[0.5, 0.5, 0.5]					,  )					->				Optional[int]:
           lowerCamelCase       :				Tuple      			= size if size is not None else {"height": 18, "width": 18}
           lowerCamelCase       :				int      			= parent
           lowerCamelCase       :				Any      			= batch_size
           lowerCamelCase       :				Any      			= num_channels
           lowerCamelCase       :				str      			= image_size
           lowerCamelCase       :				List[str]      			= min_resolution
           lowerCamelCase       :				List[Any]      			= max_resolution
           lowerCamelCase       :				Tuple      			= do_resize
           lowerCamelCase       :				Optional[Any]      			= size
           lowerCamelCase       :				Optional[Any]      			= do_normalize
           lowerCamelCase       :				Union[str, Any]      			= image_mean
           lowerCamelCase       :				Tuple      			= image_std







    def    _lowercase					(   self					)					->				Optional[int]:
           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 		UpperCamelCase__     (lowerCAmelCase__   ,    unittest.TestCase					):

    '''simple docstring'''



    lowerCamelCase_				:     int     					=				ViTImageProcessor if is_vision_available() else None







    def    _lowercase					(   self					)					->				Optional[int]:
           lowerCamelCase       :				List[Any]      			= ViTImageProcessingTester(self					)







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







    def    _lowercase					(   self					)					->				Optional[Any]:
           lowerCamelCase       :				Dict      			= 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"					)					)







    def    _lowercase					(   self					)					->				Optional[int]:
           lowerCamelCase       :				Any      			= self.image_processing_class.from_dict(self.image_processor_dict					)
           self.assertEqual(image_processor.size					,  {"height": 18, "width": 18}					)

           lowerCamelCase       :				str      			= self.image_processing_class.from_dict(self.image_processor_dict					,  size=42					)
           self.assertEqual(image_processor.size					,  {"height": 42, "width": 42}					)







    def    _lowercase					(   self					)					->				Optional[int]:
           pass







    def    _lowercase					(   self					)					->				Optional[Any]:
           # Initialize image_processing
           lowerCamelCase       :				Any      			= self.image_processing_class(**self.image_processor_dict					)
           # create random PIL images
           lowerCamelCase       :				str      			= prepare_image_inputs(self.image_processor_tester					,  equal_resolution=UpperCamelCase__					)
           for image in image_inputs:
                  self.assertIsInstance(UpperCamelCase__					,  Image.Image					)

           # Test not batched input
           lowerCamelCase       :				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
           lowerCamelCase       :				Any      			= image_processing(UpperCamelCase__					,  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    _lowercase					(   self					)					->				Union[str, Any]:
           # Initialize image_processing
           lowerCamelCase       :				Union[str, Any]      			= self.image_processing_class(**self.image_processor_dict					)
           # create random numpy tensors
           lowerCamelCase       :				int      			= 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
           lowerCamelCase       :				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
           lowerCamelCase       :				List[Any]      			= image_processing(UpperCamelCase__					,  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    _lowercase					(   self					)					->				Any:
           # Initialize image_processing
           lowerCamelCase       :				Any      			= self.image_processing_class(**self.image_processor_dict					)
           # create random PyTorch tensors
           lowerCamelCase       :				Tuple      			= 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
           lowerCamelCase       :				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
           lowerCamelCase       :				List[str]      			= image_processing(UpperCamelCase__					,  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"],
               )					,  )












from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


SCREAMING_SNAKE_CASE__	:				Optional[int]  =       {
    'configuration_gptsan_japanese': ['GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP', 'GPTSanJapaneseConfig'],
    'tokenization_gptsan_japanese': ['GPTSanJapaneseTokenizer'],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       SCREAMING_SNAKE_CASE__	:				Optional[int]  =       [
           'GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST',
           'GPTSanJapaneseForConditionalGeneration',
           'GPTSanJapaneseModel',
           'GPTSanJapanesePreTrainedModel',
       ]
       SCREAMING_SNAKE_CASE__	:				List[str]  =       [
           'GPTSanJapaneseTokenizer',
       ]


if TYPE_CHECKING:
       from .configuration_gptsan_japanese import GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTSanJapaneseConfig
       from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_gptsan_japanese import (
                  GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST,
                  GPTSanJapaneseForConditionalGeneration,
                  GPTSanJapaneseModel,
                  GPTSanJapanesePreTrainedModel,
              )
              from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer


else:
       import sys

       SCREAMING_SNAKE_CASE__	:				Optional[Any]  =       _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






