


from manim import *



class       a					(       _A      ):

     '''simple docstring'''





     def   lowerCamelCase_       (     self       :      Optional[int]    ):
         UpperCAmelCase_										=					Rectangle(height=0.5 ,   width=0.5    )
         UpperCAmelCase_										=					Rectangle(height=0.46 ,   width=0.46    ).set_stroke(width=0    )

         UpperCAmelCase_										=					[mem.copy() for i in range(6    )]
         UpperCAmelCase_										=					[mem.copy() for i in range(6    )]
         UpperCAmelCase_										=					VGroup(*__snake_case    ).arrange(__snake_case ,   buff=0    )
         UpperCAmelCase_										=					VGroup(*__snake_case    ).arrange(__snake_case ,   buff=0    )
         UpperCAmelCase_										=					VGroup(__snake_case ,   __snake_case    ).arrange(__snake_case ,   buff=0    )
         UpperCAmelCase_										=					Text('''CPU''' ,   font_size=24    )
         UpperCAmelCase_										=					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    )

         UpperCAmelCase_										=					[mem.copy() for i in range(1    )]
         UpperCAmelCase_										=					VGroup(*__snake_case    ).arrange(__snake_case ,   buff=0    )
         UpperCAmelCase_										=					Text('''GPU''' ,   font_size=24    )
         UpperCAmelCase_										=					Group(__snake_case ,   __snake_case    ).arrange(__snake_case ,   buff=0.5 ,   aligned_edge=__snake_case    )
         gpu.align_to(__snake_case ,   __snake_case    )
         gpu.set_x(gpu.get_x() - 1    )

         self.add(__snake_case    )

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

         UpperCAmelCase_										=					Text('''Model''' ,   font_size=24    )
         UpperCAmelCase_										=					Group(__snake_case ,   __snake_case    ).arrange(__snake_case ,   buff=0.5 ,   aligned_edge=__snake_case    )
         model.move_to([3, -1.0, 0]    )

         self.play(
             Create(__snake_case ,   run_time=1    ) ,   Create(__snake_case ,   run_time=1    ) ,   Create(__snake_case ,   run_time=1    ) ,   )

         UpperCAmelCase_										=					MarkupText(
             F'First, an empty model skeleton is loaded\ninto <span fgcolor=\'{YELLOW}\'>memory</span> without using much RAM.' ,   font_size=24 ,   )

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

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

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

         step_a.move_to([2, 2, 0]    )
         self.play(Write(__snake_case ,   run_time=2.5    ) ,   Write(__snake_case    ) ,   Write(__snake_case    )    )

         self.add(__snake_case    )

         UpperCAmelCase_										=					[]
         UpperCAmelCase_										=					[]
         UpperCAmelCase_										=					[]
         for i, rect in enumerate(__snake_case    ):
             UpperCAmelCase_										=					Rectangle(height=0.46 ,   width=0.46    ).set_stroke(width=0.0    ).set_fill(__snake_case ,   opacity=0.7    )
             cpu_target.move_to(__snake_case    )
             cpu_target.generate_target()
             UpperCAmelCase_										=					0.46 / 4
             UpperCAmelCase_										=					0.46 / 3

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

             first_animations.append(rect.animate(run_time=0.5    ).set_stroke(__snake_case    )    )
             second_animations.append(MoveToTarget(__snake_case ,   run_time=1.5    )    )

         self.play(*__snake_case    )
         self.play(*__snake_case    )

         self.wait()











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

     '''simple docstring'''





     def __init__(     self       :      Tuple ,   __snake_case       :      int ,   __snake_case       :      List[Any]=7 ,   __snake_case       :      Any=3 ,   __snake_case       :      Any=18 ,   __snake_case       :      str=30 ,   __snake_case       :      Any=4_00 ,   __snake_case       :      Optional[int]=True ,   __snake_case       :      str=None ,   __snake_case       :      Any=True ,   __snake_case       :      List[Any]=None ,   ):
         UpperCAmelCase_										=					size if size is not None else {'''shortest_edge''': 20}
         UpperCAmelCase_										=					crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
         UpperCAmelCase_										=					parent
         UpperCAmelCase_										=					batch_size
         UpperCAmelCase_										=					num_channels
         UpperCAmelCase_										=					image_size
         UpperCAmelCase_										=					min_resolution
         UpperCAmelCase_										=					max_resolution
         UpperCAmelCase_										=					do_resize
         UpperCAmelCase_										=					size
         UpperCAmelCase_										=					do_center_crop
         UpperCAmelCase_										=					crop_size




     def   lowerCamelCase_       (     self       :      Any    ):
         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       a					(       _A     ,       unittest.TestCase      ):

     '''simple docstring'''





     lowerCAmelCase    :	Union[str, Any]       		=  MobileNetVaImageProcessor if is_vision_available() else None
     def   lowerCamelCase_       (     self       :      Any    ):
         UpperCAmelCase_										=					MobileNetVaImageProcessingTester(self    )
     @property
     def   lowerCamelCase_       (     self       :      List[str]    ):
         return self.image_processor_tester.prepare_image_processor_dict()
     def   lowerCamelCase_       (     self       :      Optional[int]    ):
         UpperCAmelCase_										=					self.image_processing_class(**self.image_processor_dict    )
         self.assertTrue(hasattr(__snake_case ,   '''do_resize'''    )    )
         self.assertTrue(hasattr(__snake_case ,   '''size'''    )    )
         self.assertTrue(hasattr(__snake_case ,   '''do_center_crop'''    )    )
         self.assertTrue(hasattr(__snake_case ,   '''crop_size'''    )    )
     def   lowerCamelCase_       (     self       :      Dict    ):
         UpperCAmelCase_										=					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_										=					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   lowerCamelCase_       (     self       :      Optional[int]    ):
         pass
     def   lowerCamelCase_       (     self       :      Tuple    ):
         # Initialize image_processing
         UpperCAmelCase_										=					self.image_processing_class(**self.image_processor_dict    )
         # create random PIL images
         UpperCAmelCase_										=					prepare_image_inputs(self.image_processor_tester ,   equal_resolution=__snake_case    )
         for image in image_inputs:
             self.assertIsInstance(__snake_case ,   Image.Image    )

         # Test not batched input
         UpperCAmelCase_										=					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_										=					image_processing(__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.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             ) ,   )
     def   lowerCamelCase_       (     self       :      str    ):
         # Initialize image_processing
         UpperCAmelCase_										=					self.image_processing_class(**self.image_processor_dict    )
         # create random numpy tensors
         UpperCAmelCase_										=					prepare_image_inputs(self.image_processor_tester ,   equal_resolution=__snake_case ,   numpify=__snake_case    )
         for image in image_inputs:
             self.assertIsInstance(__snake_case ,   np.ndarray    )

         # Test not batched input
         UpperCAmelCase_										=					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_										=					image_processing(__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.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             ) ,   )




     def   lowerCamelCase_       (     self       :      int    ):
         # Initialize image_processing
         UpperCAmelCase_										=					self.image_processing_class(**self.image_processor_dict    )
         # create random PyTorch tensors
         UpperCAmelCase_										=					prepare_image_inputs(self.image_processor_tester ,   equal_resolution=__snake_case ,   torchify=__snake_case    )
         for image in image_inputs:
             self.assertIsInstance(__snake_case ,   torch.Tensor    )

         # Test not batched input
         UpperCAmelCase_										=					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_										=					image_processing(__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.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             ) ,   )





