






"""simple docstring"""





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


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import BlipImageProcessor






class 					a						( unittest.TestCase		):






    def __init__(	self					:							int	,						__SCREAMING_SNAKE_CASE					:							List[Any]	,						__SCREAMING_SNAKE_CASE					:							str=7	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=3	,						__SCREAMING_SNAKE_CASE					:							Optional[Any]=18	,						__SCREAMING_SNAKE_CASE					:							Any=30	,						__SCREAMING_SNAKE_CASE					:							List[str]=400	,						__SCREAMING_SNAKE_CASE					:							Dict=True	,						__SCREAMING_SNAKE_CASE					:							List[str]=None	,						__SCREAMING_SNAKE_CASE					:							Tuple=True	,						__SCREAMING_SNAKE_CASE					:							List[str]=False	,						__SCREAMING_SNAKE_CASE					:							Any=[0.48_145_466, 0.4_578_275, 0.40_821_073]	,						__SCREAMING_SNAKE_CASE					:							Optional[Any]=[0.26_862_954, 0.26_130_258, 0.27_577_711]	,						__SCREAMING_SNAKE_CASE					:							Optional[Any]=True	,						)					->		int:
      lowerCamelCase_   					=						size if size is not None else {'height': 20, 'width': 20}
      lowerCamelCase_   					=						parent
      lowerCamelCase_   					=						batch_size
      lowerCamelCase_   					=						num_channels
      lowerCamelCase_   					=						image_size
      lowerCamelCase_   					=						min_resolution
      lowerCamelCase_   					=						max_resolution
      lowerCamelCase_   					=						do_resize
      lowerCamelCase_   					=						size
      lowerCamelCase_   					=						do_normalize
      lowerCamelCase_   					=						image_mean
      lowerCamelCase_   					=						image_std
      lowerCamelCase_   					=						do_pad
      lowerCamelCase_   					=						do_convert_rgb






    def        UpperCamelCase	(	self					:							Optional[int] )					->		List[Any]:
      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_normalize": self.do_normalize,
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_convert_rgb": self.do_convert_rgb,
          "do_pad": self.do_pad,
      }






    def        UpperCamelCase	(	self					:							Dict	,						__SCREAMING_SNAKE_CASE					:							Tuple=False	,						__SCREAMING_SNAKE_CASE					:							List[str]=False	,						__SCREAMING_SNAKE_CASE					:							Optional[Any]=False )					->		Any:
      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

      if equal_resolution:
        lowerCamelCase_   					=						[]
        for i in range(self.batch_size ):
          image_inputs.append(
              np.random.randint(
                  255	,						size=(self.num_channels, self.max_resolution, self.max_resolution)	,						dtype=np.uinta ) )
      else:
        lowerCamelCase_   					=						[]
        for i in range(self.batch_size ):
          lowerCamelCase_					,     lowerCamelCase_   					=						np.random.choice(np.arange(self.min_resolution	,						self.max_resolution )	,						2 )
          image_inputs.append(np.random.randint(255	,						size=(self.num_channels, width, height)	,						dtype=np.uinta ) )

      if not numpify and not torchify:
        # PIL expects the channel dimension as last dimension
        lowerCamelCase_   					=						[Image.fromarray(np.moveaxis(__SCREAMING_SNAKE_CASE	,						0	,						-1 ) ) for x in image_inputs]

      if torchify:
        lowerCamelCase_   					=						[torch.from_numpy(__SCREAMING_SNAKE_CASE ) for x in image_inputs]

      return image_inputs






@require_torch
@require_vision
class 					a						( __snake_case  ,				unittest.TestCase		):
    SCREAMING_SNAKE_CASE						:					Optional[Any]						=			BlipImageProcessor if is_vision_available() else None






    def        UpperCamelCase	(	self					:							Dict )					->		int:
      lowerCamelCase_   					=						BlipImageProcessingTester(self )






    @property
    def        UpperCamelCase	(	self					:							Dict )					->		Optional[Any]:
      return self.image_processor_tester.prepare_image_processor_dict()






    def        UpperCamelCase	(	self					:							Optional[int] )					->		Tuple:
      lowerCamelCase_   					=						self.image_processing_class(**self.image_processor_dict )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'do_resize' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'size' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'do_normalize' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'image_mean' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'image_std' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'do_convert_rgb' ) )






    def        UpperCamelCase	(	self					:							Union[str, Any] )					->		List[Any]:
      pass






    def        UpperCamelCase	(	self					:							int )					->		Any:
      # Initialize image_processor
      lowerCamelCase_   					=						self.image_processing_class(**self.image_processor_dict )
      # create random PIL images
      lowerCamelCase_   					=						self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE )
      for image in image_inputs:
        self.assertIsInstance(__SCREAMING_SNAKE_CASE	,						Image.Image )

      # Test not batched input
      lowerCamelCase_   					=						image_processor(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_   					=						image_processor(__SCREAMING_SNAKE_CASE	,						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        UpperCamelCase	(	self					:							Dict )					->		Optional[Any]:
      # Initialize image_processor
      lowerCamelCase_   					=						self.image_processing_class(**self.image_processor_dict )
      # create random numpy tensors
      lowerCamelCase_   					=						self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE	,						numpify=__SCREAMING_SNAKE_CASE )
      for image in image_inputs:
        self.assertIsInstance(__SCREAMING_SNAKE_CASE	,						np.ndarray )

      # Test not batched input
      lowerCamelCase_   					=						image_processor(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_   					=						image_processor(__SCREAMING_SNAKE_CASE	,						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        UpperCamelCase	(	self					:							List[str] )					->		Optional[int]:
      # Initialize image_processor
      lowerCamelCase_   					=						self.image_processing_class(**self.image_processor_dict )
      # create random PyTorch tensors
      lowerCamelCase_   					=						self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE	,						torchify=__SCREAMING_SNAKE_CASE )
      for image in image_inputs:
        self.assertIsInstance(__SCREAMING_SNAKE_CASE	,						torch.Tensor )

      # Test not batched input
      lowerCamelCase_   					=						image_processor(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_   					=						image_processor(__SCREAMING_SNAKE_CASE	,						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'],
          )	,						)






@require_torch
@require_vision
class 					a						( __snake_case  ,				unittest.TestCase		):
    SCREAMING_SNAKE_CASE						:					int						=			BlipImageProcessor if is_vision_available() else None






    def        UpperCamelCase	(	self					:							Optional[int] )					->		List[str]:
      lowerCamelCase_   					=						BlipImageProcessingTester(self	,						num_channels=4 )
      lowerCamelCase_   					=						3






    @property
    def        UpperCamelCase	(	self					:							Any )					->		Optional[int]:
      return self.image_processor_tester.prepare_image_processor_dict()






    def        UpperCamelCase	(	self					:							Tuple )					->		str:
      lowerCamelCase_   					=						self.image_processing_class(**self.image_processor_dict )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'do_resize' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'size' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'do_normalize' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'image_mean' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'image_std' ) )
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE	,						'do_convert_rgb' ) )






    def        UpperCamelCase	(	self					:							Any )					->		List[Any]:
      pass






    def        UpperCamelCase	(	self					:							List[Any] )					->		Any:
      # Initialize image_processor
      lowerCamelCase_   					=						self.image_processing_class(**self.image_processor_dict )
      # create random PIL images
      lowerCamelCase_   					=						self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE )
      for image in image_inputs:
        self.assertIsInstance(__SCREAMING_SNAKE_CASE	,						Image.Image )

      # Test not batched input
      lowerCamelCase_   					=						image_processor(image_inputs[0]	,						return_tensors='pt' ).pixel_values
      self.assertEqual(
          encoded_images.shape	,						(
              1,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.size['height'],
              self.image_processor_tester.size['width'],
          )	,						)

      # Test batched
      lowerCamelCase_   					=						image_processor(__SCREAMING_SNAKE_CASE	,						return_tensors='pt' ).pixel_values
      self.assertEqual(
          encoded_images.shape	,						(
              self.image_processor_tester.batch_size,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.size['height'],
              self.image_processor_tester.size['width'],
          )	,						)












"""simple docstring"""





from ...configuration_utils import PretrainedConfig
from ...utils import logging


_SCREAMING_SNAKE_CASE :    List[Any]    =						logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE :    str    =						{
    '''facebook/regnet-y-040''': '''https://huggingface.co/facebook/regnet-y-040/blob/main/config.json''',
}






class 					a						( __snake_case		):
    SCREAMING_SNAKE_CASE						:					str						=			"""regnet"""
    SCREAMING_SNAKE_CASE						:					List[Any]						=			["""x""", """y"""]






    def __init__(	self					:							int	,						__SCREAMING_SNAKE_CASE					:							Any=3	,						__SCREAMING_SNAKE_CASE					:							Any=32	,						__SCREAMING_SNAKE_CASE					:							List[str]=[128, 192, 512, 1088]	,						__SCREAMING_SNAKE_CASE					:							Union[str, Any]=[2, 6, 12, 2]	,						__SCREAMING_SNAKE_CASE					:							str=64	,						__SCREAMING_SNAKE_CASE					:							List[Any]="y"	,						__SCREAMING_SNAKE_CASE					:							Optional[int]="relu"	,						**__SCREAMING_SNAKE_CASE					:							Union[str, Any]	,						)					->		Union[str, Any]:
      super().__init__(**__SCREAMING_SNAKE_CASE )
      if layer_type not in self.layer_types:
        raise ValueError(F'''layer_type={layer_type} is not one of {",".join(self.layer_types )}''' )
      lowerCamelCase_   					=						num_channels
      lowerCamelCase_   					=						embedding_size
      lowerCamelCase_   					=						hidden_sizes
      lowerCamelCase_   					=						depths
      lowerCamelCase_   					=						groups_width
      lowerCamelCase_   					=						layer_type
      lowerCamelCase_   					=						hidden_act
      # always downsample in the first stage
      lowerCamelCase_   					=						True




