code: 
  
  
  
  
  """simple docstring"""
  
  
  
  from typing import Dict, List, Optional, Union
  
  import numpy as np
  
  from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
  from ...image_transforms import center_crop, normalize, rescale, resize, to_channel_dimension_format
  from ...image_utils import (
      IMAGENET_DEFAULT_MEAN,
      IMAGENET_DEFAULT_STD,
      ChannelDimension,
      ImageInput,
      PILImageResampling,
      get_image_size,
      make_list_of_images,
      to_numpy_array,
      valid_images,
  )
  from ...utils import TensorType, is_vision_available, logging
  
  
  if is_vision_available():
        import PIL
  
  
  SCREAMING_SNAKE_CASE       = logging.get_logger(__name__)
  
  
  
  
  class 			UpperCAmelCase_						(		A_							):
      lowercase__		      =   ['''pixel_values''']
  
  
  
  
      def __init__(					self		: Any			,				snake_case_		: bool = True			,				snake_case_		: Dict[str, int] = None			,				snake_case_		: bool = True			,				snake_case_		: Dict[str, int] = None			,				snake_case_		: PILImageResampling = PILImageResampling.BICUBIC			,				snake_case_		: bool = True			,				snake_case_		: Union[int, float] = 1 / 255			,				snake_case_		: bool = True			,				snake_case_		: Optional[Union[float, List[float]]] = None			,				snake_case_		: Optional[Union[float, List[float]]] = None			,				**snake_case_		: List[Any]			,				)   ->							None:
  
  
  
  
       '''simple docstring'''
  
       super().__init__(**snake_case_   )
       A__ =       crop_size if crop_size is not None else {"height": 256, "width": 256}
       A__ =       get_size_dict(snake_case_			,				param_name="crop_size"   )
       A__ =       size if size is not None else {"height": 224, "width": 224}
       A__ =       get_size_dict(snake_case_   )
  
       A__ =       do_center_crop
       A__ =       crop_size
       A__ =       do_resize
       A__ =       size
       A__ =       resample
       A__ =       do_rescale
       A__ =       rescale_factor
       A__ =       do_normalize
       A__ =       image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
       A__ =       image_std if image_std is not None else IMAGENET_DEFAULT_STD
  
  
  
  
      def 							__magic_name__							(					self		: Dict			,				snake_case_		: np.ndarray			,				snake_case_		: Dict[str, int]			,				snake_case_		: Optional[int] = None			,				snake_case_		: Optional[Union[str, ChannelDimension]] = None			,				**snake_case_		: Tuple			,				)   ->							np.ndarray:
  
  
  
  
       '''simple docstring'''
  
       A__ =       self.size if size is None else size
       A__ =       get_size_dict(snake_case_   )
       A__ =       get_size_dict(snake_case_			,				param_name="crop_size"   )
  
       A__,   A__ =       get_image_size(snake_case_   )
       A__ =       min(snake_case_			,				snake_case_   )
       A__ =       (size["height"] / crop_size["height"]) * min_dim
       A__ =       (size["width"] / crop_size["width"]) * min_dim
       return center_crop(snake_case_			,				size=(cropped_height, cropped_width)			,				data_format=snake_case_			,				**snake_case_   )
  
  
  
  
      def 							__magic_name__							(					self		: List[str]			,				snake_case_		: np.ndarray			,				snake_case_		: Dict[str, int]			,				snake_case_		: PILImageResampling = PIL.Image.BICUBIC			,				snake_case_		: Optional[Union[str, ChannelDimension]] = None			,				**snake_case_		: Tuple			,				)   ->							np.ndarray:
  
  
  
  
       '''simple docstring'''
  
       A__ =       get_size_dict(snake_case_   )
       if "height" not in size or "width" not in size:
        raise ValueError(F"""The size dictionary must contain the keys 'height' and 'width'. Got {size.keys()}"""   )
       return resize(
           snake_case_			,				size=(size["height"], size["width"])			,				resample=snake_case_			,				data_format=snake_case_			,				**snake_case_   )
  
  
  
  
      def 							__magic_name__							(					self		: Optional[Any]			,				snake_case_		: np.ndarray			,				snake_case_		: Union[int, float]			,				snake_case_		: Optional[Union[str, ChannelDimension]] = None			,				**snake_case_		: List[Any]			,				)   ->							Any:
  
  
  
  
       '''simple docstring'''
  
       return rescale(snake_case_			,				scale=snake_case_			,				data_format=snake_case_			,				**snake_case_   )
  
  
  
  
      def 							__magic_name__							(					self		: Any			,				snake_case_		: np.ndarray			,				snake_case_		: Union[float, List[float]]			,				snake_case_		: Union[float, List[float]]			,				snake_case_		: Optional[Union[str, ChannelDimension]] = None			,				**snake_case_		: Optional[int]			,				)   ->							np.ndarray:
  
  
  
  
       '''simple docstring'''
  
       return normalize(snake_case_			,				mean=snake_case_			,				std=snake_case_			,				data_format=snake_case_			,				**snake_case_   )
  
  
  
  
      def 							__magic_name__							(					self		: Union[str, Any]			,				snake_case_		: ImageInput			,				snake_case_		: Optional[bool] = None			,				snake_case_		: Optional[Dict[str, int]] = None			,				snake_case_		: Optional[bool] = None			,				snake_case_		: Optional[Dict[str, int]] = None			,				snake_case_		: PILImageResampling = None			,				snake_case_		: Optional[bool] = None			,				snake_case_		: Optional[float] = None			,				snake_case_		: Optional[bool] = None			,				snake_case_		: Optional[Union[float, List[float]]] = None			,				snake_case_		: Optional[Union[float, List[float]]] = None			,				snake_case_		: Optional[Union[str, TensorType]] = None			,				snake_case_		: ChannelDimension = ChannelDimension.FIRST			,				**snake_case_		: List[str]			,				)   ->							PIL.Image.Image:
  
  
  
  
       '''simple docstring'''
  
       A__ =       do_center_crop if do_center_crop is not None else self.do_center_crop
       A__ =       crop_size if crop_size is not None else self.crop_size
       A__ =       get_size_dict(snake_case_			,				param_name="crop_size"   )
       A__ =       do_resize if do_resize is not None else self.do_resize
       A__ =       size if size is not None else self.size
       A__ =       get_size_dict(snake_case_   )
       A__ =       resample if resample is not None else self.resample
       A__ =       do_rescale if do_rescale is not None else self.do_rescale
       A__ =       rescale_factor if rescale_factor is not None else self.rescale_factor
       A__ =       do_normalize if do_normalize is not None else self.do_normalize
       A__ =       image_mean if image_mean is not None else self.image_mean
       A__ =       image_std if image_std is not None else self.image_std
  
       A__ =       make_list_of_images(snake_case_   )
  
       if not valid_images(snake_case_   ):
        raise ValueError(
            "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
            "torch.Tensor, tf.Tensor or jax.ndarray."   )
  
       if do_center_crop and crop_size is None:
        raise ValueError("If `do_center_crop` is set to `True`, `crop_size` must be provided."   )
  
       if do_resize and size is None:
        raise ValueError("Size must be specified if do_resize is True."   )
  
       if do_rescale and rescale_factor is None:
        raise ValueError("Rescale factor must be specified if do_rescale is True."   )
  
       if do_normalize and (image_mean is None or image_std is None):
        raise ValueError("Image mean and image standard deviation must be specified if do_normalize is True."   )
  
       # All transformations expect numpy arrays.
       A__ =       [to_numpy_array(snake_case_   ) for image in images]
  
       if do_center_crop:
        A__ =       [self.center_crop(snake_case_			,				snake_case_			,				size=snake_case_   ) for image in images]
  
       if do_resize:
        A__ =       [self.resize(image=snake_case_			,				size=snake_case_			,				resample=snake_case_   ) for image in images]
  
       if do_rescale:
        A__ =       [self.rescale(image=snake_case_			,				scale=snake_case_   ) for image in images]
  
       if do_normalize:
        A__ =       [self.normalize(image=snake_case_			,				mean=snake_case_			,				std=snake_case_   ) for image in images]
  
       A__ =       [to_channel_dimension_format(snake_case_			,				snake_case_   ) for image in images]
  
       A__ =       {"pixel_values": images}
       return BatchFeature(data=snake_case_			,				tensor_type=snake_case_   )
  
  
  
  
  
  
style_context: 
  
  
  
  
  """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()
  
  
  
  
  
  