


from manim import *







class        UpperCamelCase__   (	__magic_name__   ):

					def   UpperCAmelCase__       (     self       :   Tuple       ):






										'''simple docstring'''






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

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

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

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

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

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

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

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

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

										lowercase_  							=			Text("""Loaded Checkpoint"""							,					font_size=24       )
										lowercase_  							=			Group(UpperCamelCase__							,					UpperCamelCase__       ).arrange(UpperCamelCase__							,					aligned_edge=UpperCamelCase__							,					buff=0.4       )
										checkpoint.move_to([3, 0.5, 0]       )

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

										lowercase_  							=			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(UpperCamelCase__							,					UpperCamelCase__       )

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

										blue_text.next_to(UpperCamelCase__							,					DOWN * 2.4							,					aligned_edge=key_text.get_left()       )

										lowercase_  							=			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(UpperCamelCase__       )							,					Write(UpperCamelCase__       )       )

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

										lowercase_  							=			[]
										lowercase_  							=			[]
										for i, rect in enumerate(UpperCamelCase__       ):
															lowercase_  							=			fill.copy().set_fill(UpperCamelCase__							,					opacity=0.7       )
															target.move_to(UpperCamelCase__       )
															first_animations.append(GrowFromCenter(UpperCamelCase__							,					run_time=1       )       )

															lowercase_  							=			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(UpperCamelCase__							,					run_time=1.5       )       )

										self.play(*UpperCamelCase__       )
										self.play(*UpperCamelCase__       )
										self.wait()






from typing import Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import get_image_size, pad, rescale, to_channel_dimension_format
from ...image_utils import ChannelDimension, ImageInput, make_list_of_images, to_numpy_array, valid_images
from ...utils import TensorType, logging


a					  =     logging.get_logger(__name__)







class        UpperCamelCase__   (	__magic_name__   ):
					__SCREAMING_SNAKE_CASE       :  str						=   ['pixel_values']

					def __init__(     self       :   List[Any]							,					UpperCamelCase__       :   bool = True							,					UpperCamelCase__       :   Union[int, float] = 1 / 255							,					UpperCamelCase__       :   bool = True							,					UpperCamelCase__       :   int = 8							,					**UpperCamelCase__       :   Optional[Any]							,					):






										'''simple docstring'''






										super().__init__(**UpperCamelCase__       )

										lowercase_  							=			do_rescale
										lowercase_  							=			rescale_factor
										lowercase_  							=			do_pad
										lowercase_  							=			pad_size

					def   UpperCAmelCase__       (     self       :   int							,					UpperCamelCase__       :   np.ndarray							,					UpperCamelCase__       :   float							,					UpperCamelCase__       :   Optional[Union[str, ChannelDimension]] = None							,					**UpperCamelCase__       :   Optional[Any]       ):






										'''simple docstring'''






										return rescale(UpperCamelCase__							,					scale=UpperCamelCase__							,					data_format=UpperCamelCase__							,					**UpperCamelCase__       )

					def   UpperCAmelCase__       (     self       :   List[Any]							,					UpperCamelCase__       :   np.ndarray							,					UpperCamelCase__       :   int							,					UpperCamelCase__       :   Optional[Union[str, ChannelDimension]] = None       ):






										'''simple docstring'''






										lowercase_							,					lowercase_  							=			get_image_size(UpperCamelCase__       )
										lowercase_  							=			(old_height // size + 1) * size - old_height
										lowercase_  							=			(old_width // size + 1) * size - old_width

										return pad(UpperCamelCase__							,					((0, pad_height), (0, pad_width))							,					mode="""symmetric"""							,					data_format=UpperCamelCase__       )







					def   UpperCAmelCase__       (     self       :   Optional[int]							,					UpperCamelCase__       :   ImageInput							,					UpperCamelCase__       :   Optional[bool] = None							,					UpperCamelCase__       :   Optional[float] = None							,					UpperCamelCase__       :   Optional[bool] = None							,					UpperCamelCase__       :   Optional[int] = None							,					UpperCamelCase__       :   Optional[Union[str, TensorType]] = None							,					UpperCamelCase__       :   Union[str, ChannelDimension] = ChannelDimension.FIRST							,					**UpperCamelCase__       :   Dict							,					):






										'''simple docstring'''






										lowercase_  							=			do_rescale if do_rescale is not None else self.do_rescale
										lowercase_  							=			rescale_factor if rescale_factor is not None else self.rescale_factor
										lowercase_  							=			do_pad if do_pad is not None else self.do_pad
										lowercase_  							=			pad_size if pad_size is not None else self.pad_size

										lowercase_  							=			make_list_of_images(UpperCamelCase__       )

										if not valid_images(UpperCamelCase__       ):
															raise ValueError(
															    """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
															    """torch.Tensor, tf.Tensor or jax.ndarray."""       )

										if do_rescale and rescale_factor is None:
															raise ValueError("""Rescale factor must be specified if do_rescale is True."""       )

										# All transformations expect numpy arrays.
										lowercase_  							=			[to_numpy_array(UpperCamelCase__       ) for image in images]

										if do_rescale:
															lowercase_  							=			[self.rescale(image=UpperCamelCase__							,					scale=UpperCamelCase__       ) for image in images]

										if do_pad:
															lowercase_  							=			[self.pad(UpperCamelCase__							,					size=UpperCamelCase__       ) for image in images]

										lowercase_  							=			[to_channel_dimension_format(UpperCamelCase__							,					UpperCamelCase__       ) for image in images]

										lowercase_  							=			{"""pixel_values""": images}
										return BatchFeature(data=UpperCamelCase__							,					tensor_type=UpperCamelCase__       )


