



from manim import *



class     lowerCAmelCase_		(  lowerCamelCase__							):
       def  snake_case_	(      self	)					->		int:
          UpperCamelCase   :  Dict						     =     Rectangle(height=0.5,      width=0.5	)
          UpperCamelCase   :  Union[str, Any]						     =     Rectangle(height=0.46,      width=0.46	).set_stroke(width=0	)

          UpperCamelCase   :  Optional[Any]						     =     [mem.copy() for i in range(6	)]
          UpperCamelCase   :  Dict						     =     [mem.copy() for i in range(6	)]
          UpperCamelCase   :  List[Any]						     =     VGroup(*__snake_case	).arrange(__snake_case,      buff=0	)
          UpperCamelCase   :  int						     =     VGroup(*__snake_case	).arrange(__snake_case,      buff=0	)
          UpperCamelCase   :  Union[str, Any]						     =     VGroup(__snake_case,      __snake_case	).arrange(__snake_case,      buff=0	)
          UpperCamelCase   :  Any						     =     Text('CPU',      font_size=24	)
          UpperCamelCase   :  int						     =     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   :  int						     =     [mem.copy() for i in range(4	)]
          UpperCamelCase   :  str						     =     VGroup(*__snake_case	).arrange(__snake_case,      buff=0	)
          UpperCamelCase   :  List[Any]						     =     Text('GPU',      font_size=24	)
          UpperCamelCase   :  Optional[int]						     =     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	)

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

          UpperCamelCase   :  int						     =     Text('Model',      font_size=24	)
          UpperCamelCase   :  Dict						     =     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	)

          UpperCamelCase   :  Optional[Any]						     =     []
          for i, rect in enumerate(__snake_case	):
             rect.set_stroke(__snake_case	)
             # target = fill.copy().set_fill(YELLOW, opacity=0.7)
             # target.move_to(rect)
             # self.add(target)

             UpperCamelCase   :  Optional[int]						     =     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(cpu_targs[0],      direction=__snake_case,      buff=0.0	)
             else:
                cpu_target.next_to(cpu_targs[i - 1],      direction=__snake_case,      buff=0.0	)
             self.add(__snake_case	)
             cpu_targs.append(__snake_case	)

          UpperCamelCase   :  List[Any]						     =     [mem.copy() for i in range(6	)]
          UpperCamelCase   :  Optional[int]						     =     VGroup(*__snake_case	).arrange(__snake_case,      buff=0	)

          UpperCamelCase   :  Tuple						     =     Text('Loaded Checkpoint',      font_size=24	)
          UpperCamelCase   :  str						     =     Group(__snake_case,      __snake_case	).arrange(__snake_case,      aligned_edge=__snake_case,      buff=0.4	)
          checkpoint.move_to([3, 0.5, 0]	)

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

          UpperCamelCase   :  Union[str, Any]						     =     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	)

          UpperCamelCase   :  Tuple						     =     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()	)

          UpperCamelCase   :  Optional[int]						     =     MarkupText(
              F"""Next, a <i><span fgcolor=\"{BLUE}\">second</span></i> model is loaded into memory,\nwith the weights of a <span fgcolor=\"{BLUE}\">single shard</span>.""",      font_size=24,      )
          step_a.move_to([2, 2, 0]	)
          self.play(Write(__snake_case	),      Write(__snake_case	)	)

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

          UpperCamelCase   :  List[str]						     =     []
          UpperCamelCase   :  Dict						     =     []
          for i, rect in enumerate(__snake_case	):
             UpperCamelCase   :  Optional[int]						     =     fill.copy().set_fill(__snake_case,      opacity=0.7	)
             target.move_to(__snake_case	)
             first_animations.append(GrowFromCenter(__snake_case,      run_time=1	)	)

             UpperCamelCase   :  List[Any]						     =     target.copy()
             cpu_target.generate_target()
             if i < 5:
                cpu_target.target.move_to(cpu_left_col_base[i + 1]	)
             else:
                cpu_target.target.move_to(cpu_right_col_base[i - 5]	)
             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 ViTImageProcessor



class     lowerCAmelCase_		(  unittest.TestCase							):
       def __init__(      self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_=13,      SCREAMING_SNAKE_CASE_=3,      SCREAMING_SNAKE_CASE_=224,      SCREAMING_SNAKE_CASE_=30,      SCREAMING_SNAKE_CASE_=400,      SCREAMING_SNAKE_CASE_=True,      SCREAMING_SNAKE_CASE_=None,      SCREAMING_SNAKE_CASE_=True,      SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5],      SCREAMING_SNAKE_CASE_=[0.5, 0.5, 0.5],      )					->		List[str]:
          UpperCamelCase   :  Optional[int]						     =     size if size is not None else {'height': 18, 'width': 18}
          UpperCamelCase   :  List[Any]						     =     parent
          UpperCamelCase   :  List[Any]						     =     batch_size
          UpperCamelCase   :  int						     =     num_channels
          UpperCamelCase   :  int						     =     image_size
          UpperCamelCase   :  List[Any]						     =     min_resolution
          UpperCamelCase   :  int						     =     max_resolution
          UpperCamelCase   :  Any						     =     do_resize
          UpperCamelCase   :  Optional[int]						     =     size
          UpperCamelCase   :  List[str]						     =     do_normalize
          UpperCamelCase   :  Optional[Any]						     =     image_mean
          UpperCamelCase   :  Tuple						     =     image_std






       def  snake_case_	(      self	)					->		List[Any]:
          return {
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_normalize": self.do_normalize,
              "do_resize": self.do_resize,
              "size": self.size,
          }






@require_torch
@require_vision
class     lowerCAmelCase_		(  a__	,   unittest.TestCase							):
       UpperCAmelCase__    : Optional[Any]       					=  ViTImageProcessor if is_vision_available() else None
       def  snake_case_	(      self	)					->		Any:
          UpperCamelCase   :  Dict						     =     EfficientFormerImageProcessorTester(self	)
       @property
       def  snake_case_	(      self	)					->		List[Any]:
          return self.image_proc_tester.prepare_image_processor_dict()
       def  snake_case_	(      self	)					->		Optional[int]:
          UpperCamelCase   :  Optional[int]						     =     self.image_processing_class(**self.image_processor_dict	)
          self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      'image_mean'	)	)
          self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      'image_std'	)	)
          self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      'do_normalize'	)	)
          self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      'do_resize'	)	)
          self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,      'size'	)	)
       def  snake_case_	(      self	)					->		Any:
          pass
       def  snake_case_	(      self	)					->		int:
          # Initialize image_processor
          UpperCamelCase   :  Union[str, Any]						     =     self.image_processing_class(**self.image_processor_dict	)
          # create random PIL images
          UpperCamelCase   :  List[str]						     =     prepare_image_inputs(self.image_proc_tester,      equal_resolution=SCREAMING_SNAKE_CASE_	)
          for image in image_inputs:
             self.assertIsInstance(SCREAMING_SNAKE_CASE_,      Image.Image	)

          # Test not batched input
          UpperCamelCase   :  str						     =     image_processor(image_inputs[0],      return_tensors='pt'	).pixel_values
          self.assertEqual(
              encoded_images.shape,      (
                  1,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size['height'],
                  self.image_proc_tester.size['width'],
              ),      )

          # Test batched
          UpperCamelCase   :  Optional[Any]						     =     image_processor(SCREAMING_SNAKE_CASE_,      return_tensors='pt'	).pixel_values
          self.assertEqual(
              encoded_images.shape,      (
                  self.image_proc_tester.batch_size,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size['height'],
                  self.image_proc_tester.size['width'],
              ),      )
       def  snake_case_	(      self	)					->		str:
          # Initialize image_processor
          UpperCamelCase   :  List[str]						     =     self.image_processing_class(**self.image_processor_dict	)
          # create random numpy tensors
          UpperCamelCase   :  Union[str, Any]						     =     prepare_image_inputs(self.image_proc_tester,      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
          UpperCamelCase   :  Dict						     =     image_processor(image_inputs[0],      return_tensors='pt'	).pixel_values
          self.assertEqual(
              encoded_images.shape,      (
                  1,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size['height'],
                  self.image_proc_tester.size['width'],
              ),      )

          # Test batched
          UpperCamelCase   :  Dict						     =     image_processor(SCREAMING_SNAKE_CASE_,      return_tensors='pt'	).pixel_values
          self.assertEqual(
              encoded_images.shape,      (
                  self.image_proc_tester.batch_size,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size['height'],
                  self.image_proc_tester.size['width'],
              ),      )






       def  snake_case_	(      self	)					->		Tuple:
          # Initialize image_processor
          UpperCamelCase   :  Any						     =     self.image_processing_class(**self.image_processor_dict	)
          # create random PyTorch tensors
          UpperCamelCase   :  int						     =     prepare_image_inputs(self.image_proc_tester,      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
          UpperCamelCase   :  Optional[int]						     =     image_processor(image_inputs[0],      return_tensors='pt'	).pixel_values
          self.assertEqual(
              encoded_images.shape,      (
                  1,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size['height'],
                  self.image_proc_tester.size['width'],
              ),      )

          # Test batched
          UpperCamelCase   :  int						     =     image_processor(SCREAMING_SNAKE_CASE_,      return_tensors='pt'	).pixel_values
          self.assertEqual(
              encoded_images.shape,      (
                  self.image_proc_tester.batch_size,
                  self.image_proc_tester.num_channels,
                  self.image_proc_tester.size['height'],
                  self.image_proc_tester.size['width'],
              ),      )



