





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 MobileNetVaImageProcessor






class     lowercase__       (	unittest.TestCase				):

   '''simple docstring'''


   def __init__(    self,		__magic_name__,		__magic_name__=7,		__magic_name__=3,		__magic_name__=18,		__magic_name__=30,		__magic_name__=400,		__magic_name__=True,		__magic_name__=None,		__magic_name__=True,		__magic_name__=None,		) ->      Optional[Any]:






       """simple docstring"""
       UpperCamelCase__							:				Dict          =      size if size is not None else {'''shortest_edge''': 20}
       UpperCamelCase__							:				int          =      crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
       UpperCamelCase__							:				List[Any]          =      parent
       UpperCamelCase__							:				str          =      batch_size
       UpperCamelCase__							:				List[str]          =      num_channels
       UpperCamelCase__							:				Optional[int]          =      image_size
       UpperCamelCase__							:				Union[str, Any]          =      min_resolution
       UpperCamelCase__							:				Union[str, Any]          =      max_resolution
       UpperCamelCase__							:				Any          =      do_resize
       UpperCamelCase__							:				Dict          =      size
       UpperCamelCase__							:				List[str]          =      do_center_crop
       UpperCamelCase__							:				Any          =      crop_size




   def       UpperCamelCase__  (    self							) ->      Optional[int]:






       """simple docstring"""
       return {
           "do_resize": self.do_resize,
           "size": self.size,
           "do_center_crop": self.do_center_crop,
           "crop_size": self.crop_size,
       }






@require_torch
@require_vision
class     lowercase__       (	__lowerCamelCase			,				unittest.TestCase				):

   '''simple docstring'''


   a						:							Union[str, Any]   		=		MobileNetVaImageProcessor if is_vision_available() else None




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      MobileNetVaImageProcessingTester(self							)




   @property
   def       UpperCamelCase__  (    self							) ->      Optional[Any]:






       """simple docstring"""
       return self.image_processor_tester.prepare_image_processor_dict()




   def       UpperCamelCase__  (    self							) ->      List[Any]:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      self.image_processing_class(**self.image_processor_dict							)
       self.assertTrue(hasattr(__magic_name__,		'''do_resize'''							)							)
       self.assertTrue(hasattr(__magic_name__,		'''size'''							)							)
       self.assertTrue(hasattr(__magic_name__,		'''do_center_crop'''							)							)
       self.assertTrue(hasattr(__magic_name__,		'''crop_size'''							)							)




   def       UpperCamelCase__  (    self							) ->      Any:






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.image_processing_class.from_dict(self.image_processor_dict							)
       self.assertEqual(image_processor.size,		{'''shortest_edge''': 20}							)
       self.assertEqual(image_processor.crop_size,		{'''height''': 18, '''width''': 18}							)

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




   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       pass




   def       UpperCamelCase__  (    self							) ->      Union[str, Any]:






       """simple docstring"""
       # Initialize image_processing
       UpperCamelCase__							:				Dict          =      self.image_processing_class(**self.image_processor_dict							)
       # create random PIL images
       UpperCamelCase__							:				Optional[int]          =      prepare_image_inputs(self.image_processor_tester,		equal_resolution=__magic_name__							)
       for image in image_inputs:
           self.assertIsInstance(__magic_name__,		Image.Image							)

       # Test not batched input
       UpperCamelCase__							:				Dict          =      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.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           ),		)

       # Test batched
       UpperCamelCase__							:				Tuple          =      image_processing(__magic_name__,		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.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           ),		)




   def       UpperCamelCase__  (    self							) ->      Any:






       """simple docstring"""
       # Initialize image_processing
       UpperCamelCase__							:				Dict          =      self.image_processing_class(**self.image_processor_dict							)
       # create random numpy tensors
       UpperCamelCase__							:				int          =      prepare_image_inputs(self.image_processor_tester,		equal_resolution=__magic_name__,		numpify=__magic_name__							)
       for image in image_inputs:
           self.assertIsInstance(__magic_name__,		np.ndarray							)

       # 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.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           ),		)

       # Test batched
       UpperCamelCase__							:				str          =      image_processing(__magic_name__,		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.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           ),		)




   def       UpperCamelCase__  (    self							) ->      List[str]:






       """simple docstring"""
       # Initialize image_processing
       UpperCamelCase__							:				List[Any]          =      self.image_processing_class(**self.image_processor_dict							)
       # create random PyTorch tensors
       UpperCamelCase__							:				Optional[int]          =      prepare_image_inputs(self.image_processor_tester,		equal_resolution=__magic_name__,		torchify=__magic_name__							)
       for image in image_inputs:
           self.assertIsInstance(__magic_name__,		torch.Tensor							)

       # Test not batched input
       UpperCamelCase__							:				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.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           ),		)

       # Test batched
       UpperCamelCase__							:				List[Any]          =      image_processing(__magic_name__,		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.crop_size['''height'''],
               self.image_processor_tester.crop_size['''width'''],
           ),		)








from typing import TYPE_CHECKING

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


UpperCAmelCase_     							= {
    'configuration_convbert': ['CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ConvBertConfig', 'ConvBertOnnxConfig'],
    'tokenization_convbert': ['ConvBertTokenizer'],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_     							= ['ConvBertTokenizerFast']

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_     							= [
      'CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
      'ConvBertForMaskedLM',
      'ConvBertForMultipleChoice',
      'ConvBertForQuestionAnswering',
      'ConvBertForSequenceClassification',
      'ConvBertForTokenClassification',
      'ConvBertLayer',
      'ConvBertModel',
      'ConvBertPreTrainedModel',
      'load_tf_weights_in_convbert',
  ]


try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase_     							= [
      'TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
      'TFConvBertForMaskedLM',
      'TFConvBertForMultipleChoice',
      'TFConvBertForQuestionAnswering',
      'TFConvBertForSequenceClassification',
      'TFConvBertForTokenClassification',
      'TFConvBertLayer',
      'TFConvBertModel',
      'TFConvBertPreTrainedModel',
  ]


if TYPE_CHECKING:
  from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
  from .tokenization_convbert import ConvBertTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_convbert_fast import ConvBertTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_convbert import (
        CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        ConvBertForMaskedLM,
        ConvBertForMultipleChoice,
        ConvBertForQuestionAnswering,
        ConvBertForSequenceClassification,
        ConvBertForTokenClassification,
        ConvBertLayer,
        ConvBertModel,
        ConvBertPreTrainedModel,
        load_tf_weights_in_convbert,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_convbert import (
        TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFConvBertForMaskedLM,
        TFConvBertForMultipleChoice,
        TFConvBertForQuestionAnswering,
        TFConvBertForSequenceClassification,
        TFConvBertForTokenClassification,
        TFConvBertLayer,
        TFConvBertModel,
        TFConvBertPreTrainedModel,
    )


else:
  import sys

  UpperCAmelCase_     							= _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

