






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 ConvNextImageProcessor




class        _lowerCAmelCase( unittest.TestCase      ):





							"""simple docstring"""







							def __init__(      self						,    _lowerCamelCase						,    _lowerCamelCase=7						,    _lowerCamelCase=3						,    _lowerCamelCase=1_8						,    _lowerCamelCase=3_0						,    _lowerCamelCase=4_0_0						,    _lowerCamelCase=True						,    _lowerCamelCase=None						,    _lowerCamelCase=0.8_7_5						,    _lowerCamelCase=True						,    _lowerCamelCase=[0.5, 0.5, 0.5]						,    _lowerCamelCase=[0.5, 0.5, 0.5]						,    ):
									UpperCamelCase_:      Union[str, Any]					   =       size if size is not None else {'''shortest_edge''': 2_0}
									UpperCamelCase_:      str					   =       parent
									UpperCamelCase_:      Dict					   =       batch_size
									UpperCamelCase_:      Union[str, Any]					   =       num_channels
									UpperCamelCase_:      int					   =       image_size
									UpperCamelCase_:      Optional[int]					   =       min_resolution
									UpperCamelCase_:      Tuple					   =       max_resolution
									UpperCamelCase_:      List[str]					   =       do_resize
									UpperCamelCase_:      Optional[int]					   =       size
									UpperCamelCase_:      Any					   =       crop_pct
									UpperCamelCase_:      Tuple					   =       do_normalize
									UpperCamelCase_:      Union[str, Any]					   =       image_mean
									UpperCamelCase_:      Optional[int]					   =       image_std





							def     _a					(      self							):
									return {
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									    "do_normalize": self.do_normalize,
									    "do_resize": self.do_resize,
									    "size": self.size,
									    "crop_pct": self.crop_pct,
									}







@require_torch
@require_vision
class        _lowerCAmelCase( A_							,			unittest.TestCase      ):





							"""simple docstring"""







							a       :	Any								=ConvNextImageProcessor if is_vision_available() else None





							def     _a					(      self							):
									UpperCamelCase_:      Optional[int]					   =       ConvNextImageProcessingTester(self							)





							@property
							def     _a					(      self							):
									return self.image_processor_tester.prepare_image_processor_dict()





							def     _a					(      self							):
									UpperCamelCase_:      int					   =       self.image_processing_class(**self.image_processor_dict							)
									self.assertTrue(hasattr(_lowerCamelCase						,    'do_resize'							)							)
									self.assertTrue(hasattr(_lowerCamelCase						,    'size'							)							)
									self.assertTrue(hasattr(_lowerCamelCase						,    'crop_pct'							)							)
									self.assertTrue(hasattr(_lowerCamelCase						,    'do_normalize'							)							)
									self.assertTrue(hasattr(_lowerCamelCase						,    'image_mean'							)							)
									self.assertTrue(hasattr(_lowerCamelCase						,    'image_std'							)							)





							def     _a					(      self							):
									UpperCamelCase_:      Optional[Any]					   =       self.image_processing_class.from_dict(self.image_processor_dict							)
									self.assertEqual(image_processor.size						,    {'shortest_edge': 2_0}							)

									UpperCamelCase_:      List[Any]					   =       self.image_processing_class.from_dict(self.image_processor_dict						,    size=4_2							)
									self.assertEqual(image_processor.size						,    {'shortest_edge': 4_2}							)





							def     _a					(      self							):
									pass





							def     _a					(      self							):
									UpperCamelCase_:      Optional[Any]					   =       self.image_processing_class(**self.image_processor_dict							)
									# create random PIL images
									UpperCamelCase_:      Union[str, Any]					   =       prepare_image_inputs(self.image_processor_tester						,    equal_resolution=_lowerCamelCase							)
									for image in image_inputs:
											self.assertIsInstance(_lowerCamelCase						,    Image.Image							)

									# Test not batched input
									UpperCamelCase_:      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['shortest_edge'],
									        self.image_processor_tester.size['shortest_edge'],
									    )						,    )

									# Test batched
									UpperCamelCase_:      Union[str, Any]					   =       image_processing(_lowerCamelCase						,    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['shortest_edge'],
									        self.image_processor_tester.size['shortest_edge'],
									    )						,    )





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

									# Test not batched input
									UpperCamelCase_:      Tuple					   =       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['shortest_edge'],
									        self.image_processor_tester.size['shortest_edge'],
									    )						,    )

									# Test batched
									UpperCamelCase_:      Optional[Any]					   =       image_processing(_lowerCamelCase						,    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['shortest_edge'],
									        self.image_processor_tester.size['shortest_edge'],
									    )						,    )





							def     _a					(      self							):
									UpperCamelCase_:      Dict					   =       self.image_processing_class(**self.image_processor_dict							)
									# create random PyTorch tensors
									UpperCamelCase_:      Tuple					   =       prepare_image_inputs(self.image_processor_tester						,    equal_resolution=_lowerCamelCase						,    torchify=_lowerCamelCase							)
									for image in image_inputs:
											self.assertIsInstance(_lowerCamelCase						,    torch.Tensor							)

									# Test not batched input
									UpperCamelCase_:      Optional[int]					   =       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['shortest_edge'],
									        self.image_processor_tester.size['shortest_edge'],
									    )						,    )

									# Test batched
									UpperCamelCase_:      Union[str, Any]					   =       image_processing(_lowerCamelCase						,    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['shortest_edge'],
									        self.image_processor_tester.size['shortest_edge'],
									    )						,    )







from typing import TYPE_CHECKING

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


A_	:	List[Any]				=				{
    'configuration_openai': ['OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'OpenAIGPTConfig'],
    'tokenization_openai': ['OpenAIGPTTokenizer'],
}

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_	:	List[str]				=				['OpenAIGPTTokenizerFast']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_	:	Any				=				[
       'OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'OpenAIGPTDoubleHeadsModel',
       'OpenAIGPTForSequenceClassification',
       'OpenAIGPTLMHeadModel',
       'OpenAIGPTModel',
       'OpenAIGPTPreTrainedModel',
       'load_tf_weights_in_openai_gpt',
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_	:	str				=				[
       'TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'TFOpenAIGPTDoubleHeadsModel',
       'TFOpenAIGPTForSequenceClassification',
       'TFOpenAIGPTLMHeadModel',
       'TFOpenAIGPTMainLayer',
       'TFOpenAIGPTModel',
       'TFOpenAIGPTPreTrainedModel',
   ]


if TYPE_CHECKING:
   from .configuration_openai import OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP, OpenAIGPTConfig
   from .tokenization_openai import OpenAIGPTTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_openai_fast import OpenAIGPTTokenizerFast

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_openai import (
          OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
          OpenAIGPTDoubleHeadsModel,
          OpenAIGPTForSequenceClassification,
          OpenAIGPTLMHeadModel,
          OpenAIGPTModel,
          OpenAIGPTPreTrainedModel,
          load_tf_weights_in_openai_gpt,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_openai import (
          TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFOpenAIGPTDoubleHeadsModel,
          TFOpenAIGPTForSequenceClassification,
          TFOpenAIGPTLMHeadModel,
          TFOpenAIGPTMainLayer,
          TFOpenAIGPTModel,
          TFOpenAIGPTPreTrainedModel,
      )

else:
   import sys

   A_	:	str				=				_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)