
"""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,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
							import PIL


__magic_name__       =			logging.get_logger(__name__)



def 						_lowerCAmelCase				(				UpperCamelCase_				):
		if isinstance(UpperCamelCase_  ,				(list, tuple)				) and isinstance(videos[0]  ,				(list, tuple)				) and is_valid_image(videos[0][0]				):
				return videos

		elif isinstance(UpperCamelCase_  ,				(list, tuple)				) and is_valid_image(videos[0]				):
				return [videos]

		elif is_valid_image(UpperCamelCase_				):
				return [[videos]]

		raise ValueError(f"Could not make batched video from {videos}"				)
class 						SCREAMING_SNAKE_CASE_ (						__a ):




		"""simple docstring"""





		__lowercase							:  List[str]						   =		['''pixel_values''']




		def __init__(     self							,  lowerCAmelCase__ = True							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = PILImageResampling.BILINEAR							,  lowerCAmelCase__ = True							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = True							,  lowerCAmelCase__ = 1 / 2_5_5							,  lowerCAmelCase__ = True							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  **lowerCAmelCase__							,  ):
				super().__init__(**lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = size if size is not None else {"""shortest_edge""": 2_2_4}
				__SCREAMING_SNAKE_CASE            = get_size_dict(lowerCAmelCase__							,  default_to_square=lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = crop_size if crop_size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
				__SCREAMING_SNAKE_CASE            = get_size_dict(lowerCAmelCase__							,  param_name="""crop_size""")

				__SCREAMING_SNAKE_CASE            = do_resize
				__SCREAMING_SNAKE_CASE            = size
				__SCREAMING_SNAKE_CASE            = do_center_crop
				__SCREAMING_SNAKE_CASE            = crop_size
				__SCREAMING_SNAKE_CASE            = resample
				__SCREAMING_SNAKE_CASE            = do_rescale
				__SCREAMING_SNAKE_CASE            = rescale_factor
				__SCREAMING_SNAKE_CASE            = do_normalize
				__SCREAMING_SNAKE_CASE            = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
				__SCREAMING_SNAKE_CASE            = image_std if image_std is not None else IMAGENET_STANDARD_STD




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__ = PILImageResampling.BILINEAR							,  lowerCAmelCase__ = None							,  **lowerCAmelCase__							,  ):
				__SCREAMING_SNAKE_CASE            = get_size_dict(lowerCAmelCase__							,  default_to_square=lowerCAmelCase__)
				if "shortest_edge" in size:
						__SCREAMING_SNAKE_CASE            = get_resize_output_image_size(lowerCAmelCase__							,  size["""shortest_edge"""]							,  default_to_square=lowerCAmelCase__)
				elif "height" in size and "width" in size:
						__SCREAMING_SNAKE_CASE            = (size["""height"""], size["""width"""])
				else:
						raise ValueError(f"Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}")
				return resize(lowerCAmelCase__							,  size=lowerCAmelCase__							,  resample=lowerCAmelCase__							,  data_format=lowerCAmelCase__							,  **lowerCAmelCase__)




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__ = None							,  **lowerCAmelCase__							,  ):
				__SCREAMING_SNAKE_CASE            = get_size_dict(lowerCAmelCase__)
				if "height" not in size or "width" not in size:
						raise ValueError(f"Size must have 'height' and 'width' as keys. Got {size.keys()}")
				return center_crop(lowerCAmelCase__							,  size=(size["""height"""], size["""width"""])							,  data_format=lowerCAmelCase__							,  **lowerCAmelCase__)




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__ = None							,  **lowerCAmelCase__							,  ):
				return rescale(lowerCAmelCase__							,  scale=lowerCAmelCase__							,  data_format=lowerCAmelCase__							,  **lowerCAmelCase__)




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__ = None							,  **lowerCAmelCase__							,  ):
				return normalize(lowerCAmelCase__							,  mean=lowerCAmelCase__							,  std=lowerCAmelCase__							,  data_format=lowerCAmelCase__							,  **lowerCAmelCase__)




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = ChannelDimension.FIRST							,  ):
				if do_resize and size is None or resample is None:
						raise ValueError("""Size and resample must be specified if do_resize is True.""")

				if do_center_crop and crop_size is None:
						raise ValueError("""Crop size must be specified if do_center_crop 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 std must be specified if do_normalize is True.""")

				# All transformations expect numpy arrays.
				__SCREAMING_SNAKE_CASE            = to_numpy_array(lowerCAmelCase__)

				if do_resize:
						__SCREAMING_SNAKE_CASE            = self.resize(image=lowerCAmelCase__							,  size=lowerCAmelCase__							,  resample=lowerCAmelCase__)

				if do_center_crop:
						__SCREAMING_SNAKE_CASE            = self.center_crop(lowerCAmelCase__							,  size=lowerCAmelCase__)

				if do_rescale:
						__SCREAMING_SNAKE_CASE            = self.rescale(image=lowerCAmelCase__							,  scale=lowerCAmelCase__)

				if do_normalize:
						__SCREAMING_SNAKE_CASE            = self.normalize(image=lowerCAmelCase__							,  mean=lowerCAmelCase__							,  std=lowerCAmelCase__)

				__SCREAMING_SNAKE_CASE            = to_channel_dimension_format(lowerCAmelCase__							,  lowerCAmelCase__)
				return image




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = ChannelDimension.FIRST							,  **lowerCAmelCase__							,  ):
				__SCREAMING_SNAKE_CASE            = do_resize if do_resize is not None else self.do_resize
				__SCREAMING_SNAKE_CASE            = resample if resample is not None else self.resample
				__SCREAMING_SNAKE_CASE            = do_center_crop if do_center_crop is not None else self.do_center_crop
				__SCREAMING_SNAKE_CASE            = do_rescale if do_rescale is not None else self.do_rescale
				__SCREAMING_SNAKE_CASE            = rescale_factor if rescale_factor is not None else self.rescale_factor
				__SCREAMING_SNAKE_CASE            = do_normalize if do_normalize is not None else self.do_normalize
				__SCREAMING_SNAKE_CASE            = image_mean if image_mean is not None else self.image_mean
				__SCREAMING_SNAKE_CASE            = image_std if image_std is not None else self.image_std

				__SCREAMING_SNAKE_CASE            = size if size is not None else self.size
				__SCREAMING_SNAKE_CASE            = get_size_dict(lowerCAmelCase__							,  default_to_square=lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = crop_size if crop_size is not None else self.crop_size
				__SCREAMING_SNAKE_CASE            = get_size_dict(lowerCAmelCase__							,  param_name="""crop_size""")

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

				__SCREAMING_SNAKE_CASE            = make_batched(lowerCAmelCase__)

				__SCREAMING_SNAKE_CASE            = [
				    [
				        self._preprocess_image(
				            image=lowerCAmelCase__							,  do_resize=lowerCAmelCase__							,  size=lowerCAmelCase__							,  resample=lowerCAmelCase__							,  do_center_crop=lowerCAmelCase__							,  crop_size=lowerCAmelCase__							,  do_rescale=lowerCAmelCase__							,  rescale_factor=lowerCAmelCase__							,  do_normalize=lowerCAmelCase__							,  image_mean=lowerCAmelCase__							,  image_std=lowerCAmelCase__							,  data_format=lowerCAmelCase__							,  )
				        for img in video
				    ]
				    for video in videos
				]

				__SCREAMING_SNAKE_CASE            = {"""pixel_values""": videos}
				return BatchFeature(data=lowerCAmelCase__							,  tensor_type=lowerCAmelCase__)







from manim import *






class 	__magic_name__    (			lowerCAmelCase_      ):





			def 		__magic_name__    (		self					)   -> Any:




						'''simple docstring'''
						__a        =Rectangle(height=0.5					,  width=0.5					)
						__a        =Rectangle(height=0.25					,  width=0.25					)
						__a        =Rectangle(height=0.46					,  width=0.46					).set_stroke(width=0					)

						__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        =[]
						__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					,  *__snake_case					)

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

						__a        =Text('Loaded Checkpoint'					,  font_size=24					)
						__a        =Group(__snake_case					,  __snake_case					).arrange(__snake_case					,  buff=0.5					,  aligned_edge=__snake_case					)
						checkpoint.move_to([3, 0.5, 0]					)

						self.add(__snake_case					)

						__a        =[]
						__a        =[]

						for i, rect in enumerate(__snake_case					):
									__a        =fill.copy().set_fill(__snake_case					,  opacity=0.7					)
									target.move_to(__snake_case					)
									ckpt_arr.append(__snake_case					)

									__a        =target.copy()
									if i < 5:
												cpu_target.move_to(cpu_left_col_base[i + 1]					)
									else:
												cpu_target.move_to(cpu_right_col_base[i - 5]					)
									ckpt_cpu_arr.append(__snake_case					)
						self.add(*__snake_case					,  *__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'Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device.'					,  font_size=24					,  )
						step_a.move_to([2, 2, 0]					)

						__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.play(Write(__snake_case					,  run_time=3					)					,  Write(__snake_case					,  run_time=1					)					,  Create(__snake_case					,  run_time=1					)					)

						__a        =[]
						for i, rect in enumerate(__snake_case					):
									__a        =rect.copy()
									target.generate_target()
									target.target.move_to(disk_left_col_base[i]					).scale(0.5					)
									animations.append(MoveToTarget(__snake_case					,  run_time=1.5					)					)
						self.play(*__snake_case					)

						self.play(FadeOut(__snake_case					)					)

						__a        =MarkupText(f'Then, the checkpoint is removed from memory\nthrough garbage collection.'					,  font_size=24					)
						step_a.move_to([2, 2, 0]					)

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

						self.play(
						    FadeOut(__snake_case					,  __snake_case					,  *__snake_case					,  *__snake_case					)					,  )

						self.wait()






