





'''simple docstring'''


from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

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 logging


if is_vision_available():
					import PIL

lowerCAmelCase_   :   Any       =					logging.get_logger(__name__)







def    _lowerCamelCase  (__lowerCamelCase  :     str     )   ->    List[List[ImageInput]]:
			if isinstance(__lowerCamelCase					,  (list, tuple)     ) and isinstance(videos[0]					,  (list, tuple)     ) and is_valid_image(videos[0][0]     ):
						return videos

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

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

			raise ValueError(f'''Could not make batched video from {videos}'''     )






class       UpperCamelCase__  (		__lowerCAmelCase     ):
	lowerCAmelCase__					:			Dict								=						["pixel_values"]







	def __init__(				self			:   Any , lowerCamelCase			:   bool = True , lowerCamelCase			:   Dict[str, int] = None , lowerCamelCase			:   PILImageResampling = PILImageResampling.BILINEAR , lowerCamelCase			:   bool = True , lowerCamelCase			:   Dict[str, int] = None , lowerCamelCase			:   bool = True , lowerCamelCase			:   Union[int, float] = 1 / 2_5_5 , lowerCamelCase			:   bool = True , lowerCamelCase			:   bool = True , lowerCamelCase			:   Optional[Union[float, List[float]]] = None , lowerCamelCase			:   Optional[Union[float, List[float]]] = None , **lowerCamelCase			:   Optional[int] , ):




				'''simple docstring'''
				super().__init__(**lowerCamelCase		)
				a__     = size if size is not None else {"shortest_edge": 2_5_6}
				a__     = get_size_dict(lowerCamelCase , default_to_square=lowerCamelCase		)
				a__     = crop_size if crop_size is not None else {"height": 2_2_4, "width": 2_2_4}
				a__     = get_size_dict(lowerCamelCase , param_name="crop_size"		)

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







	def 						__a   (				self			:   str , lowerCamelCase			:   np.ndarray , lowerCamelCase			:   Dict[str, int] , lowerCamelCase			:   PILImageResampling = PILImageResampling.BILINEAR , lowerCamelCase			:   Optional[Union[str, ChannelDimension]] = None , **lowerCamelCase			:   Union[str, Any] , ):




				'''simple docstring'''
				a__     = get_size_dict(lowerCamelCase , default_to_square=lowerCamelCase		)
				if "shortest_edge" in size:
							a__     = get_resize_output_image_size(lowerCamelCase , size["shortest_edge"] , default_to_square=lowerCamelCase		)
				elif "height" in size and "width" in size:
							a__     = (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 						__a   (				self			:   int , lowerCamelCase			:   np.ndarray , lowerCamelCase			:   Dict[str, int] , lowerCamelCase			:   Optional[Union[str, ChannelDimension]] = None , **lowerCamelCase			:   Tuple , ):




				'''simple docstring'''
				a__     = 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 						__a   (				self			:   Tuple , lowerCamelCase			:   np.ndarray , lowerCamelCase			:   Union[int, float] , lowerCamelCase			:   bool = True , lowerCamelCase			:   Optional[Union[str, ChannelDimension]] = None , **lowerCamelCase			:   List[str] , ):




				'''simple docstring'''
				a__     = image.astype(np.floataa		)
				if offset:
							a__     = image - (scale / 2)
				return rescale(lowerCamelCase , scale=lowerCamelCase , data_format=lowerCamelCase , **lowerCamelCase		)







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




				'''simple docstring'''
				return normalize(lowerCamelCase , mean=lowerCamelCase , std=lowerCamelCase , data_format=lowerCamelCase , **lowerCamelCase		)







	def 						__a   (				self			:   Dict , lowerCamelCase			:   ImageInput , lowerCamelCase			:   bool = None , lowerCamelCase			:   Dict[str, int] = None , lowerCamelCase			:   PILImageResampling = None , lowerCamelCase			:   bool = None , lowerCamelCase			:   Dict[str, int] = None , lowerCamelCase			:   bool = None , lowerCamelCase			:   float = None , lowerCamelCase			:   bool = None , lowerCamelCase			:   bool = None , lowerCamelCase			:   Optional[Union[float, List[float]]] = None , lowerCamelCase			:   Optional[Union[float, List[float]]] = None , lowerCamelCase			:   Optional[ChannelDimension] = ChannelDimension.FIRST , ):




				'''simple docstring'''
				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."		)

				if offset and not do_rescale:
							raise ValueError("For offset, do_rescale must also be set to True."		)

				# All transformations expect numpy arrays.
				a__     = to_numpy_array(lowerCamelCase		)

				if do_resize:
							a__     = self.resize(image=lowerCamelCase , size=lowerCamelCase , resample=lowerCamelCase		)

				if do_center_crop:
							a__     = self.center_crop(lowerCamelCase , size=lowerCamelCase		)

				if do_rescale:
							a__     = self.rescale(image=lowerCamelCase , scale=lowerCamelCase , offset=lowerCamelCase		)

				if do_normalize:
							a__     = self.normalize(image=lowerCamelCase , mean=lowerCamelCase , std=lowerCamelCase		)

				a__     = to_channel_dimension_format(lowerCamelCase , lowerCamelCase		)
				return image







	def 						__a   (				self			:   List[str] , lowerCamelCase			:   ImageInput , lowerCamelCase			:   bool = None , lowerCamelCase			:   Dict[str, int] = None , lowerCamelCase			:   PILImageResampling = None , lowerCamelCase			:   bool = None , lowerCamelCase			:   Dict[str, int] = None , lowerCamelCase			:   bool = None , lowerCamelCase			:   float = None , lowerCamelCase			:   bool = None , lowerCamelCase			:   bool = None , lowerCamelCase			:   Optional[Union[float, List[float]]] = None , lowerCamelCase			:   Optional[Union[float, List[float]]] = None , lowerCamelCase			:   Optional[Union[str, TensorType]] = None , lowerCamelCase			:   ChannelDimension = ChannelDimension.FIRST , **lowerCamelCase			:   List[Any] , ):




				'''simple docstring'''
				a__     = do_resize if do_resize is not None else self.do_resize
				a__     = resample if resample is not None else self.resample
				a__     = do_center_crop if do_center_crop is not None else self.do_center_crop
				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__     = offset if offset is not None else self.offset
				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__     = size if size is not None else self.size
				a__     = get_size_dict(lowerCamelCase , default_to_square=lowerCamelCase		)
				a__     = crop_size if crop_size is not None else self.crop_size
				a__     = 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."		)

				a__     = make_batched(lowerCamelCase		)

				a__     = [
				    [
				        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 , offset=lowerCamelCase , do_normalize=lowerCamelCase , image_mean=lowerCamelCase , image_std=lowerCamelCase , data_format=lowerCamelCase , )
				        for img in video
				    ]
				    for video in videos
				]

				a__     = {"pixel_values": videos}
				return BatchFeature(data=lowerCamelCase , tensor_type=lowerCamelCase		)










'''simple docstring'''


from manim import *






class       UpperCamelCase__  (		__lowerCAmelCase     ):







	def 						__a   (				self			:   List[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(*lowerCamelCase		).arrange(lowerCamelCase , buff=0		)
				a__     = VGroup(*lowerCamelCase		).arrange(lowerCamelCase , buff=0		)
				a__     = VGroup(lowerCamelCase , lowerCamelCase		).arrange(lowerCamelCase , buff=0		)
				a__     = Text("CPU" , font_size=2_4		)
				a__     = Group(lowerCamelCase , lowerCamelCase		).arrange(lowerCamelCase , buff=0.5 , aligned_edge=lowerCamelCase		)
				cpu.move_to([-2.5, -0.5, 0]		)
				self.add(lowerCamelCase		)

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

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

				a__     = Text("Model" , font_size=2_4		)
				a__     = Group(lowerCamelCase , lowerCamelCase		).arrange(lowerCamelCase , buff=0.5 , aligned_edge=lowerCamelCase		)
				model.move_to([3, -1.0, 0]		)
				self.add(lowerCamelCase		)

				a__     = []
				a__     = []
				a__     = []

				for i, rect in enumerate(lowerCamelCase		):
							rect.set_stroke(lowerCamelCase		)

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

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

				self.add(*lowerCamelCase , *lowerCamelCase , *lowerCamelCase		)

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

				a__     = Text("Loaded Checkpoint" , font_size=2_4		)
				a__     = Group(lowerCamelCase , lowerCamelCase		).arrange(lowerCamelCase , buff=0.5 , aligned_edge=lowerCamelCase		)
				checkpoint.move_to([3, 0.5, 0]		)

				self.add(lowerCamelCase		)

				a__     = []
				a__     = []

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

							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(lowerCamelCase		)
				self.add(*lowerCamelCase , *lowerCamelCase		)

				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=1_8 , )

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

				self.add(lowerCamelCase , lowerCamelCase		)

				a__     = MarkupText(
				    F'''<span fgcolor=\'{BLUE}\'>●</span> Checkpoint''' , font_size=1_8 , )

				blue_text.next_to(lowerCamelCase , DOWN * 2.4 , aligned_edge=key_text.get_left()		)
				self.add(lowerCamelCase		)

				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=2_4 , )
				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(*lowerCamelCase		).arrange(lowerCamelCase , buff=0		)
				a__     = VGroup(*lowerCamelCase		).arrange(lowerCamelCase , buff=0		)
				a__     = VGroup(lowerCamelCase , lowerCamelCase		).arrange(lowerCamelCase , buff=0		)
				a__     = Text("Disk" , font_size=2_4		)
				a__     = Group(lowerCamelCase , lowerCamelCase		).arrange(lowerCamelCase , buff=0.5 , aligned_edge=lowerCamelCase		)
				disk.move_to([-4.0, -1.25, 0]		)
				self.play(Write(lowerCamelCase , run_time=3		) , Write(lowerCamelCase , run_time=1		) , Create(lowerCamelCase , run_time=1		)		)

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

				self.play(FadeOut(lowerCamelCase		)		)

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

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

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

				self.wait()



