


"""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 			UpperCAmelCase_						(		unittest.TestCase							):




    def __init__(					self		: Any			,				snake_case_		: Any			,				snake_case_		: str=7			,				snake_case_		: Any=3			,				snake_case_		: Optional[Any]=18			,				snake_case_		: Any=30			,				snake_case_		: List[Any]=400			,				snake_case_		: str=True			,				snake_case_		: Any=None			,				snake_case_		: Dict=True			,				snake_case_		: Optional[Any]=None			,				snake_case_		: Optional[Any]=True			,				snake_case_		: List[str]=[0.4814_5466, 0.457_8275, 0.4082_1073]			,				snake_case_		: Union[str, Any]=[0.2686_2954, 0.2613_0258, 0.2757_7711]			,				snake_case_		: List[str]=True			,				)   ->							Dict:




     '''simple docstring'''

     A__ =       parent
     A__ =       batch_size
     A__ =       num_channels
     A__ =       image_size
     A__ =       min_resolution
     A__ =       max_resolution
     A__ =       do_resize
     A__ =       size if size is not None else {"height": 18, "width": 18}
     A__ =       do_center_crop
     A__ =       crop_size if crop_size is not None else {"height": 18, "width": 18}
     A__ =       do_normalize
     A__ =       image_mean
     A__ =       image_std
     A__ =       do_convert_rgb




    def 							__magic_name__							(					self		: List[str]   )   ->							Tuple:




     '''simple docstring'''

     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 			UpperCAmelCase_						(		UpperCAmelCase_,     unittest.TestCase							):
    lowercase__		      =   OwlViTImageProcessor if is_vision_available() else None




    def 							__magic_name__							(					self		: List[Any]   )   ->							Optional[Any]:




     '''simple docstring'''

     A__ =       OwlViTImageProcessingTester(self   )




    @property
    def 							__magic_name__							(					self		: Union[str, Any]   )   ->							Union[str, Any]:




     '''simple docstring'''

     return self.image_processor_tester.prepare_image_processor_dict()




    def 							__magic_name__							(					self		: Dict   )   ->							Dict:




     '''simple docstring'''

     A__ =       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 							__magic_name__							(					self		: Tuple   )   ->							Dict:




     '''simple docstring'''

     A__ =       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}   )

     A__ =       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 							__magic_name__							(					self		: Union[str, Any]   )   ->							int:




     '''simple docstring'''

     A__ =       self.image_processing_class(**self.image_processor_dict   )
     # create random PIL images
     A__ =       prepare_image_inputs(self.image_processor_tester			,				equal_resolution=__UpperCamelCase   )

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

     # Test not batched input
     A__ =       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
     A__ =       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 							__magic_name__							(					self		: int   )   ->							Optional[int]:




     '''simple docstring'''

     A__ =       self.image_processing_class(**self.image_processor_dict   )
     # create random numpy tensors
     A__ =       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
     A__ =       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
     A__ =       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 							__magic_name__							(					self		: Dict   )   ->							Any:




     '''simple docstring'''

     A__ =       self.image_processing_class(**self.image_processor_dict   )
     # create random PyTorch tensors
     A__ =       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
     A__ =       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
     A__ =       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"""



from manim import *




class 			UpperCAmelCase_						(		A_							):




    def 							__magic_name__							(					self		: Any   )   ->							Optional[int]:




     '''simple docstring'''

     A__ =       Rectangle(height=0.5			,				width=0.5   )
     A__ =       Rectangle(height=0.46			,				width=0.46   ).set_stroke(width=0   )
     A__ =       Rectangle(height=0.25			,				width=0.25   )

     A__ =       [mem.copy() for i in range(6   )]
     A__ =       [mem.copy() for i in range(6   )]
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       VGroup(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       Text("CPU"			,				font_size=24   )
     A__ =       Group(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0.5			,				aligned_edge=snake_case_   )
     cpu.move_to([-2.5, -0.5, 0]   )
     self.add(snake_case_   )

     A__ =       [mem.copy() for i in range(4   )]
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       Text("GPU"			,				font_size=24   )
     A__ =       Group(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0.5			,				aligned_edge=snake_case_   )
     gpu.move_to([-1, -1, 0]   )
     self.add(snake_case_   )

     A__ =       [mem.copy() for i in range(6   )]
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )

     A__ =       Text("Model"			,				font_size=24   )
     A__ =       Group(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0.5			,				aligned_edge=snake_case_   )
     model.move_to([3, -1.0, 0]   )
     self.add(snake_case_   )

     A__ =       []
     A__ =       []

     for i, rect in enumerate(snake_case_   ):
      rect.set_stroke(snake_case_   )

      A__ =       Rectangle(height=0.46 / 4			,				width=0.46 / 3   ).set_stroke(width=0.0   ).set_fill(snake_case_			,				opacity=0.7   )

      if i == 0:
       cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT   )			,				buff=0.02			,				direction=snake_case_   )
       cpu_target.set_x(cpu_target.get_x() + 0.1   )
      elif i == 3:
       cpu_target.next_to(model_cpu_arr[0]			,				direction=snake_case_			,				buff=0.0   )
      else:
       cpu_target.next_to(model_cpu_arr[i - 1]			,				direction=snake_case_			,				buff=0.0   )
      self.add(snake_case_   )
      model_cpu_arr.append(snake_case_   )

     self.add(*snake_case_			,				*snake_case_   )

     A__ =       [meta_mem.copy() for i in range(6   )]
     A__ =       [meta_mem.copy() for i in range(6   )]
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       VGroup(*snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       VGroup(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0   )
     A__ =       Text("Disk"			,				font_size=24   )
     A__ =       Group(snake_case_			,				snake_case_   ).arrange(snake_case_			,				buff=0.5			,				aligned_edge=snake_case_   )
     disk.move_to([-4.0, -1.25, 0]   )
     self.add(snake_case_			,				snake_case_   )

     A__ =       []

     for i in range(6   ):
      A__ =       fill.copy().set_fill(snake_case_			,				opacity=0.8   )
      target.move_to(disk_left_col_base[i]   ).scale(0.5   )
      cpu_disk_arr.append(snake_case_   )

     self.add(*snake_case_   )

     A__ =       Square(side_length=2.2   )
     key.move_to([-5, 2, 0]   )

     A__ =       MarkupText(
         F"""<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"""			,				font_size=18			,				)

     key_text.move_to([-5, 2.4, 0]   )

     self.add(snake_case_			,				snake_case_   )

     A__ =       MarkupText(
         F"""<span fgcolor='{BLUE}'>●</span> Checkpoint"""			,				font_size=18			,				)

     blue_text.next_to(snake_case_			,				DOWN * 2.4			,				aligned_edge=key_text.get_left()   )
     self.add(snake_case_   )

     A__ =       MarkupText(F"""The offloaded weights are all sent to the CPU."""			,				font_size=24   )
     step_a.move_to([2, 2, 0]   )

     self.play(Write(snake_case_			,				run_time=3   )   )

     for i in range(6   ):
      A__ =       cpu_disk_arr[i]
      A__ =       rect.copy().set_fill(snake_case_			,				opacity=0.8   ).scale(2.0   )
      cpa.generate_target()
      cpa.target.move_to(model_base[i]   )

      if i == 0:
       rect.set_fill(snake_case_			,				opacity=0.8   )
       rect.generate_target()
       rect.target.move_to(cpu_left_col_base[0]   ).scale(2.0   )

       self.remove(
           *snake_case_			,				*snake_case_			,				)

      else:
       rect.generate_target()
       rect.target.move_to(cpu_left_col_base[i]   ).scale(2.0   )
      self.play(MoveToTarget(snake_case_   )			,				MoveToTarget(snake_case_   )			,				model_base[i].animate.set_stroke(snake_case_   )   )
     self.play(FadeOut(snake_case_   )   )

     A__ =       MarkupText(
         F"""Finally, hooks are added to each weight in the model\nto transfer the weights from CPU to GPU\n\t\tand back when needed."""			,				font_size=24			,				)
     step_a.move_to([2, 2, 0]   )

     self.play(Write(snake_case_			,				run_time=3   )   )

     A__ =       []
     A__ =       []
     for i in range(6   ):
      A__ =       Arrow(start=snake_case_			,				end=snake_case_			,				color=snake_case_			,				buff=0.5   )
      a.next_to(model_base[i].get_left()			,				snake_case_			,				buff=0.2   )
      arrows.append(snake_case_   )
      animations.append(Write(snake_case_   )   )
     self.play(*snake_case_   )
     self.wait()





