

'''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 							_snake_case	(    unittest.TestCase  ):
   def __init__(	self     : int       ,SCREAMING_SNAKE_CASE__     : Optional[int]       ,SCREAMING_SNAKE_CASE__     : List[str]=7       ,SCREAMING_SNAKE_CASE__     : int=3       ,SCREAMING_SNAKE_CASE__     : Dict=18       ,SCREAMING_SNAKE_CASE__     : Optional[Any]=30       ,SCREAMING_SNAKE_CASE__     : Optional[int]=400       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]=True       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]=None       ,SCREAMING_SNAKE_CASE__     : Optional[Any]=True       ,SCREAMING_SNAKE_CASE__     : List[str]=None       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]=True       ,SCREAMING_SNAKE_CASE__     : List[str]=[0.48_145_466, 0.4_578_275, 0.40_821_073]       ,SCREAMING_SNAKE_CASE__     : str=[0.26_862_954, 0.26_130_258, 0.27_577_711]       ,SCREAMING_SNAKE_CASE__     : int=True       ,):
     SCREAMING_SNAKE_CASE:str   =   parent
     SCREAMING_SNAKE_CASE:List[str]   =   batch_size
     SCREAMING_SNAKE_CASE:Optional[Any]   =   num_channels
     SCREAMING_SNAKE_CASE:Optional[Any]   =   image_size
     SCREAMING_SNAKE_CASE:List[str]   =   min_resolution
     SCREAMING_SNAKE_CASE:Optional[Any]   =   max_resolution
     SCREAMING_SNAKE_CASE:List[Any]   =   do_resize
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   size if size is not None else {"height": 18, "width": 18}
     SCREAMING_SNAKE_CASE:Any   =   do_center_crop
     SCREAMING_SNAKE_CASE:int   =   crop_size if crop_size is not None else {"height": 18, "width": 18}
     SCREAMING_SNAKE_CASE:List[str]   =   do_normalize
     SCREAMING_SNAKE_CASE:Optional[Any]   =   image_mean
     SCREAMING_SNAKE_CASE:int   =   image_std
     SCREAMING_SNAKE_CASE:int   =   do_convert_rgb







   def       __UpperCamelCase  (	self     : Dict							):
     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 							_snake_case	(    SCREAMING_SNAKE_CASE__		,					unittest.TestCase  ):
   _A    :       List[Any]      				=   OwlViTImageProcessor if is_vision_available() else None
   def       __UpperCamelCase  (	self     : Union[str, Any]							):
     SCREAMING_SNAKE_CASE:Optional[Any]   =   OwlViTImageProcessingTester(self							)
   @property
   def       __UpperCamelCase  (	self     : int							):
     return self.image_processor_tester.prepare_image_processor_dict()
   def       __UpperCamelCase  (	self     : List[str]							):
     SCREAMING_SNAKE_CASE:Tuple   =   self.image_processing_class(**self.image_processor_dict							)
     self.assertTrue(hasattr(_UpperCAmelCase       ,"do_resize"							)							)
     self.assertTrue(hasattr(_UpperCAmelCase       ,"size"							)							)
     self.assertTrue(hasattr(_UpperCAmelCase       ,"do_center_crop"							)							)
     self.assertTrue(hasattr(_UpperCAmelCase       ,"center_crop"							)							)
     self.assertTrue(hasattr(_UpperCAmelCase       ,"do_normalize"							)							)
     self.assertTrue(hasattr(_UpperCAmelCase       ,"image_mean"							)							)
     self.assertTrue(hasattr(_UpperCAmelCase       ,"image_std"							)							)
     self.assertTrue(hasattr(_UpperCAmelCase       ,"do_convert_rgb"							)							)
   def       __UpperCamelCase  (	self     : List[str]							):
     SCREAMING_SNAKE_CASE:Tuple   =   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}							)

     SCREAMING_SNAKE_CASE: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       __UpperCamelCase  (	self     : List[Any]							):
     # Initialize image_processing
     SCREAMING_SNAKE_CASE:str   =   self.image_processing_class(**self.image_processor_dict							)
     # create random PIL images
     SCREAMING_SNAKE_CASE:int   =   prepare_image_inputs(self.image_processor_tester       ,equal_resolution=_UpperCAmelCase							)

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

     # Test not batched input
     SCREAMING_SNAKE_CASE: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
     SCREAMING_SNAKE_CASE:Dict   =   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.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         )       ,)
   def       __UpperCamelCase  (	self     : int							):
     # Initialize image_processing
     SCREAMING_SNAKE_CASE:Tuple   =   self.image_processing_class(**self.image_processor_dict							)
     # create random numpy tensors
     SCREAMING_SNAKE_CASE:Tuple   =   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
     SCREAMING_SNAKE_CASE: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
     SCREAMING_SNAKE_CASE:Tuple   =   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.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         )       ,)







   def       __UpperCamelCase  (	self     : Union[str, Any]							):
     # Initialize image_processing
     SCREAMING_SNAKE_CASE:Tuple   =   self.image_processing_class(**self.image_processor_dict							)
     # create random PyTorch tensors
     SCREAMING_SNAKE_CASE:Any   =   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
     SCREAMING_SNAKE_CASE: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
     SCREAMING_SNAKE_CASE: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.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         )       ,)









'''simple docstring'''

import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import Mock, patch

import diffusers.utils.hub_utils





class 							_snake_case	(    unittest.TestCase  ):
   @patch("diffusers.utils.hub_utils.get_full_repo_name"							)
   def       __UpperCamelCase  (	self     : List[str]       ,SCREAMING_SNAKE_CASE__     : Mock							):
     SCREAMING_SNAKE_CASE:Optional[Any]   =   "full_repo_name"
     with TemporaryDirectory() as tmpdir:
       # Dummy args values
       SCREAMING_SNAKE_CASE:int   =   Mock()
       SCREAMING_SNAKE_CASE:int   =   tmpdir
       SCREAMING_SNAKE_CASE:Optional[Any]   =   0
       SCREAMING_SNAKE_CASE:Union[str, Any]   =   "hub_token"
       SCREAMING_SNAKE_CASE:str   =   "dataset_name"
       SCREAMING_SNAKE_CASE:Tuple   =   0.01
       SCREAMING_SNAKE_CASE:str   =   100_000
       SCREAMING_SNAKE_CASE:Optional[Any]   =   10_000
       SCREAMING_SNAKE_CASE:List[Any]   =   0.01
       SCREAMING_SNAKE_CASE:Union[str, Any]   =   0.02
       SCREAMING_SNAKE_CASE:Optional[Any]   =   0.03
       SCREAMING_SNAKE_CASE:Tuple   =   0.0_005
       SCREAMING_SNAKE_CASE:List[str]   =   0.000_001
       SCREAMING_SNAKE_CASE:Optional[int]   =   1
       SCREAMING_SNAKE_CASE:Optional[int]   =   10
       SCREAMING_SNAKE_CASE:Any   =   0.001
       SCREAMING_SNAKE_CASE:Optional[int]   =   0.1
       SCREAMING_SNAKE_CASE:Union[str, Any]   =   0.2
       SCREAMING_SNAKE_CASE:Optional[Any]   =   True

       # Model card mush be rendered and saved
       diffusers.utils.hub_utils.create_model_card(SCREAMING_SNAKE_CASE__       ,model_name="model_name"							)
       self.assertTrue((Path(SCREAMING_SNAKE_CASE__							) / "README.md").is_file()							)






