



'''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, prepare_image_inputs


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import OwlViTImageProcessor



class 							lowercase (						unittest.TestCase       ):


 """simple docstring"""


 def __init__(							self						,a_						,a_=7						,a_=3						,a_=18						,a_=30						,a_=400						,a_=True						,a_=None						,a_=True						,a_=None						,a_=True						,a_=[0.4814_5466, 0.457_8275, 0.4082_1073]						,a_=[0.2686_2954, 0.2613_0258, 0.2757_7711]						,a_=True						,)	->     Optional[Any]:
        _UpperCAmelCase						:		List[str]      =				parent
        _UpperCAmelCase						:		int      =				batch_size
        _UpperCAmelCase						:		Dict      =				num_channels
        _UpperCAmelCase						:		str      =				image_size
        _UpperCAmelCase						:		int      =				min_resolution
        _UpperCAmelCase						:		int      =				max_resolution
        _UpperCAmelCase						:		Tuple      =				do_resize
        _UpperCAmelCase						:		Union[str, Any]      =				size if size is not None else {"""height""": 18, """width""": 18}
        _UpperCAmelCase						:		Union[str, Any]      =				do_center_crop
        _UpperCAmelCase						:		Optional[int]      =				crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
        _UpperCAmelCase						:		List[Any]      =				do_normalize
        _UpperCAmelCase						:		Dict      =				image_mean
        _UpperCAmelCase						:		List[Any]      =				image_std
        _UpperCAmelCase						:		Any      =				do_convert_rgb







 def _snake_case				(							self							)	->     Tuple:
        return {
            "do_resize": self.do_resize,
            "size": self.size,
            "do_center_crop": self.do_center_crop,
            "crop_size": self.crop_size,
            "do_normalize": self.do_normalize,
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_convert_rgb": self.do_convert_rgb,
        }







@require_torch
@require_vision
class 							lowercase (						_lowerCamelCase      ,      unittest.TestCase       ):


 """simple docstring"""


 UpperCAmelCase					=						OwlViTImageProcessor if is_vision_available() else None







 def _snake_case				(							self							)	->     Tuple:
        _UpperCAmelCase						:		List[Any]      =				OwlViTImageProcessingTester(self							)







 @property
 def _snake_case				(							self							)	->     Tuple:
        return self.image_processor_tester.prepare_image_processor_dict()







 def _snake_case				(							self							)	->     Optional[Any]:
        _UpperCAmelCase						:		List[str]      =				self.image_processing_class(**self.image_processor_dict							)
        self.assertTrue(hasattr(a_						,"""do_resize"""							)							)
        self.assertTrue(hasattr(a_						,"""size"""							)							)
        self.assertTrue(hasattr(a_						,"""do_center_crop"""							)							)
        self.assertTrue(hasattr(a_						,"""center_crop"""							)							)
        self.assertTrue(hasattr(a_						,"""do_normalize"""							)							)
        self.assertTrue(hasattr(a_						,"""image_mean"""							)							)
        self.assertTrue(hasattr(a_						,"""image_std"""							)							)
        self.assertTrue(hasattr(a_						,"""do_convert_rgb"""							)							)







 def _snake_case				(							self							)	->     Dict:
        _UpperCAmelCase						:		List[str]      =				self.image_processing_class.from_dict(self.image_processor_dict							)
        self.assertEqual(image_processor.size						,{"""height""": 18, """width""": 18}							)
        self.assertEqual(image_processor.crop_size						,{"""height""": 18, """width""": 18}							)

        _UpperCAmelCase						:		Dict      =				self.image_processing_class.from_dict(self.image_processor_dict						,size=42						,crop_size=84							)
        self.assertEqual(image_processor.size						,{"""height""": 42, """width""": 42}							)
        self.assertEqual(image_processor.crop_size						,{"""height""": 84, """width""": 84}							)







 def _snake_case				(							self							)	->     Any:
        # Initialize image_processing
        _UpperCAmelCase						:		Tuple      =				self.image_processing_class(**self.image_processor_dict							)
        # create random PIL images
        _UpperCAmelCase						:		List[Any]      =				prepare_image_inputs(self.image_processor_tester						,equal_resolution=a_							)

        for image in image_inputs:
               self.assertIsInstance(a_						,Image.Image							)

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

        # Test batched
        _UpperCAmelCase						:		Optional[Any]      =				image_processing(a_						,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 _snake_case				(							self							)	->     Dict:
        # Initialize image_processing
        _UpperCAmelCase						:		str      =				self.image_processing_class(**self.image_processor_dict							)
        # create random numpy tensors
        _UpperCAmelCase						:		str      =				prepare_image_inputs(self.image_processor_tester						,equal_resolution=a_						,numpify=a_							)
        for image in image_inputs:
               self.assertIsInstance(a_						,np.ndarray							)

        # Test not batched input
        _UpperCAmelCase						:		str      =				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						:		Union[str, Any]      =				image_processing(a_						,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 _snake_case				(							self							)	->     Optional[int]:
        # Initialize image_processing
        _UpperCAmelCase						:		Optional[Any]      =				self.image_processing_class(**self.image_processor_dict							)
        # create random PyTorch tensors
        _UpperCAmelCase						:		List[Any]      =				prepare_image_inputs(self.image_processor_tester						,equal_resolution=a_						,torchify=a_							)
        for image in image_inputs:
               self.assertIsInstance(a_						,torch.Tensor							)

        # Test not batched input
        _UpperCAmelCase						:		List[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						:		Tuple      =				image_processing(a_						,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"""],
            )						,)








'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


A_							:				List[Any]						=			{
    """configuration_deta""": ["""DETA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """DetaConfig"""],
}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_							:				Optional[int]						=			["""DetaImageProcessor"""]

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A_							:				Optional[Any]						=			[
       """DETA_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """DetaForObjectDetection""",
       """DetaModel""",
       """DetaPreTrainedModel""",
   ]


if TYPE_CHECKING:
   from .configuration_deta import DETA_PRETRAINED_CONFIG_ARCHIVE_MAP, DetaConfig

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .image_processing_deta import DetaImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_deta import (
          DETA_PRETRAINED_MODEL_ARCHIVE_LIST,
          DetaForObjectDetection,
          DetaModel,
          DetaPreTrainedModel,
      )

else:
   import sys

   A_							:				List[Any]						=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



