
"""simple docstring"""




import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
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 DetrImageProcessor



class 			lowerCAmelCase_		(unittest.TestCase						):


				"""simple docstring"""



				def __init__(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__=7     , SCREAMING_SNAKE_CASE__=3     , SCREAMING_SNAKE_CASE__=30     , SCREAMING_SNAKE_CASE__=4_00     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=None     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=1 / 2_55     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=[0.5, 0.5, 0.5]     , SCREAMING_SNAKE_CASE__=[0.5, 0.5, 0.5]     , SCREAMING_SNAKE_CASE__=True     , )      ->	Union[str, Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: int     =     size if size is not None else {"""shortest_edge""": 18, """longest_edge""": 13_33}
											SCREAMING_SNAKE_CASE__		: Dict     =     parent
											SCREAMING_SNAKE_CASE__		: Dict     =     batch_size
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     num_channels
											SCREAMING_SNAKE_CASE__		: Dict     =     min_resolution
											SCREAMING_SNAKE_CASE__		: Any     =     max_resolution
											SCREAMING_SNAKE_CASE__		: int     =     do_resize
											SCREAMING_SNAKE_CASE__		: int     =     size
											SCREAMING_SNAKE_CASE__		: Tuple     =     do_rescale
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     rescale_factor
											SCREAMING_SNAKE_CASE__		: Tuple     =     do_normalize
											SCREAMING_SNAKE_CASE__		: str     =     image_mean
											SCREAMING_SNAKE_CASE__		: Any     =     image_std
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     do_pad



				def 			__magic_name__					(self					)      ->	Dict:



											"""simple docstring"""




											return {
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "do_rescale": self.do_rescale,
											    "rescale_factor": self.rescale_factor,
											    "do_normalize": self.do_normalize,
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											    "do_pad": self.do_pad,
											}



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__=False					)      ->	int:



											"""simple docstring"""




											if not batched:
																		SCREAMING_SNAKE_CASE__		: List[str]     =     image_inputs[0]
																		if isinstance(SCREAMING_SNAKE_CASE__     , Image.Image					):
																									SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: List[Any]     =     image.size
																		else:
																									SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: List[str]     =     image.shape[1], image.shape[2]
																		if w < h:
																									SCREAMING_SNAKE_CASE__		: Any     =     int(self.size["""shortest_edge"""] * h / w					)
																									SCREAMING_SNAKE_CASE__		: List[Any]     =     self.size["""shortest_edge"""]
																		elif w > h:
																									SCREAMING_SNAKE_CASE__		: Tuple     =     self.size["""shortest_edge"""]
																									SCREAMING_SNAKE_CASE__		: Optional[int]     =     int(self.size["""shortest_edge"""] * w / h					)
																		else:
																									SCREAMING_SNAKE_CASE__		: Tuple     =     self.size["""shortest_edge"""]
																									SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     self.size["""shortest_edge"""]

											else:
																		SCREAMING_SNAKE_CASE__		: Optional[Any]     =     []
																		for image in image_inputs:
																									SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: Dict     =     self.get_expected_values([image]					)
																									expected_values.append((expected_height, expected_width)					)
																		SCREAMING_SNAKE_CASE__		: List[str]     =     max(SCREAMING_SNAKE_CASE__     , key=lambda SCREAMING_SNAKE_CASE__					: item[0]					)[0]
																		SCREAMING_SNAKE_CASE__		: Dict     =     max(SCREAMING_SNAKE_CASE__     , key=lambda SCREAMING_SNAKE_CASE__					: item[1]					)[1]

											return expected_height, expected_width






@require_torch
@require_vision
class 			lowerCAmelCase_		(a__				,      unittest.TestCase						):


				"""simple docstring"""



				__UpperCamelCase   :		Union[str, Any]       =     DetrImageProcessor if is_vision_available() else None



				def 			__magic_name__					(self					)      ->	List[Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Dict     =     DetrImageProcessingTester(self					)



				@property
				def 			__magic_name__					(self					)      ->	Any:



											"""simple docstring"""




											return self.image_processor_tester.prepare_image_processor_dict()



				def 			__magic_name__					(self					)      ->	Optional[int]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     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_rescale"""					)					)
											self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__     , """rescale_factor"""					)					)
											self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__     , """do_resize"""					)					)
											self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__     , """size"""					)					)
											self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__     , """do_pad"""					)					)



				def 			__magic_name__					(self					)      ->	Tuple:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: List[str]     =     self.image_processing_class.from_dict(self.image_processor_dict					)
											self.assertEqual(image_processor.size     , {"""shortest_edge""": 18, """longest_edge""": 13_33}					)
											self.assertEqual(image_processor.do_pad     , SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: List[str]     =     self.image_processing_class.from_dict(
											    self.image_processor_dict     , size=42     , max_size=84     , pad_and_return_pixel_mask=SCREAMING_SNAKE_CASE__					)
											self.assertEqual(image_processor.size     , {"""shortest_edge""": 42, """longest_edge""": 84}					)
											self.assertEqual(image_processor.do_pad     , SCREAMING_SNAKE_CASE__					)



				def 			__magic_name__					(self					)      ->	Any:



											"""simple docstring"""




											pass



				def 			__magic_name__					(self					)      ->	List[str]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Any     =     self.image_processing_class(**self.image_processor_dict					)
											# create random PIL images
											SCREAMING_SNAKE_CASE__		: Any     =     prepare_image_inputs(self.image_processor_tester     , equal_resolution=SCREAMING_SNAKE_CASE__					)
											for image in image_inputs:
																		self.assertIsInstance(SCREAMING_SNAKE_CASE__     , Image.Image					)

											# Test not batched input
											SCREAMING_SNAKE_CASE__		: int     =     image_processing(image_inputs[0]     , return_tensors="""pt"""					).pixel_values

											SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: Any     =     self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__					)

											self.assertEqual(
											    encoded_images.shape     , (1, self.image_processor_tester.num_channels, expected_height, expected_width)     , )

											# Test batched
											SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: List[str]     =     self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__     , batched=SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     image_processing(SCREAMING_SNAKE_CASE__     , return_tensors="""pt"""					).pixel_values
											self.assertEqual(
											    encoded_images.shape     , (
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        expected_height,
											        expected_width,
											    )     , )



				def 			__magic_name__					(self					)      ->	List[str]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Tuple     =     self.image_processing_class(**self.image_processor_dict					)
											# create random numpy tensors
											SCREAMING_SNAKE_CASE__		: List[str]     =     prepare_image_inputs(self.image_processor_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
											SCREAMING_SNAKE_CASE__		: str     =     image_processing(image_inputs[0]     , return_tensors="""pt"""					).pixel_values

											SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: int     =     self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__					)

											self.assertEqual(
											    encoded_images.shape     , (1, self.image_processor_tester.num_channels, expected_height, expected_width)     , )

											# Test batched
											SCREAMING_SNAKE_CASE__		: Tuple     =     image_processing(SCREAMING_SNAKE_CASE__     , return_tensors="""pt"""					).pixel_values

											SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__     , batched=SCREAMING_SNAKE_CASE__					)

											self.assertEqual(
											    encoded_images.shape     , (
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        expected_height,
											        expected_width,
											    )     , )



				def 			__magic_name__					(self					)      ->	Dict:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: List[Any]     =     self.image_processing_class(**self.image_processor_dict					)
											# create random PyTorch tensors
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     prepare_image_inputs(self.image_processor_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
											SCREAMING_SNAKE_CASE__		: str     =     image_processing(image_inputs[0]     , return_tensors="""pt"""					).pixel_values

											SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: Any     =     self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__					)

											self.assertEqual(
											    encoded_images.shape     , (1, self.image_processor_tester.num_channels, expected_height, expected_width)     , )

											# Test batched
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     image_processing(SCREAMING_SNAKE_CASE__     , return_tensors="""pt"""					).pixel_values

											SCREAMING_SNAKE_CASE__   ,   SCREAMING_SNAKE_CASE__		: Any     =     self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__     , batched=SCREAMING_SNAKE_CASE__					)

											self.assertEqual(
											    encoded_images.shape     , (
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        expected_height,
											        expected_width,
											    )     , )



				@slow
				def 			__magic_name__					(self					)      ->	str:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: int     =     Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""					)
											with open("""./tests/fixtures/tests_samples/COCO/coco_annotations.txt"""     , """r"""					) as f:
																		SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     json.loads(f.read()					)

											SCREAMING_SNAKE_CASE__		: int     =     {"""image_id""": 3_97_69, """annotations""": target}

											# encode them
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     DetrImageProcessor.from_pretrained("""facebook/detr-resnet-50"""					)
											SCREAMING_SNAKE_CASE__		: Any     =     image_processing(images=SCREAMING_SNAKE_CASE__     , annotations=SCREAMING_SNAKE_CASE__     , return_tensors="""pt"""					)

											# verify pixel values
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     torch.Size([1, 3, 8_00, 10_66]					)
											self.assertEqual(encoding["""pixel_values"""].shape     , SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: List[Any]     =     torch.tensor([0.2796, 0.3138, 0.3481]					)
											self.assertTrue(torch.allclose(encoding["""pixel_values"""][0, 0, 0, :3]     , SCREAMING_SNAKE_CASE__     , atol=1E-4					)					)

											# verify area
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     torch.tensor([5887.9600, 11250.2061, 489353.8438, 837122.7500, 147967.5156, 165732.3438]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""area"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify boxes
											SCREAMING_SNAKE_CASE__		: str     =     torch.Size([6, 4]					)
											self.assertEqual(encoding["""labels"""][0]["""boxes"""].shape     , SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Tuple     =     torch.tensor([0.5503, 0.2765, 0.0604, 0.2215]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""boxes"""][0]     , SCREAMING_SNAKE_CASE__     , atol=1E-3					)					)
											# verify image_id
											SCREAMING_SNAKE_CASE__		: Tuple     =     torch.tensor([3_97_69]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""image_id"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify is_crowd
											SCREAMING_SNAKE_CASE__		: int     =     torch.tensor([0, 0, 0, 0, 0, 0]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""iscrowd"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify class_labels
											SCREAMING_SNAKE_CASE__		: str     =     torch.tensor([75, 75, 63, 65, 17, 17]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""class_labels"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify orig_size
											SCREAMING_SNAKE_CASE__		: Tuple     =     torch.tensor([4_80, 6_40]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""orig_size"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify size
											SCREAMING_SNAKE_CASE__		: str     =     torch.tensor([8_00, 10_66]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""size"""]     , SCREAMING_SNAKE_CASE__					)					)



				@slow
				def 			__magic_name__					(self					)      ->	Tuple:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Any     =     Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""					)
											with open("""./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt"""     , """r"""					) as f:
																		SCREAMING_SNAKE_CASE__		: Optional[int]     =     json.loads(f.read()					)

											SCREAMING_SNAKE_CASE__		: str     =     {"""file_name""": """000000039769.png""", """image_id""": 3_97_69, """segments_info""": target}

											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     pathlib.Path("""./tests/fixtures/tests_samples/COCO/coco_panoptic"""					)

											# encode them
											SCREAMING_SNAKE_CASE__		: int     =     DetrImageProcessor.from_pretrained("""facebook/detr-resnet-50-panoptic"""					)
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     image_processing(images=SCREAMING_SNAKE_CASE__     , annotations=SCREAMING_SNAKE_CASE__     , masks_path=SCREAMING_SNAKE_CASE__     , return_tensors="""pt"""					)

											# verify pixel values
											SCREAMING_SNAKE_CASE__		: List[Any]     =     torch.Size([1, 3, 8_00, 10_66]					)
											self.assertEqual(encoding["""pixel_values"""].shape     , SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     torch.tensor([0.2796, 0.3138, 0.3481]					)
											self.assertTrue(torch.allclose(encoding["""pixel_values"""][0, 0, 0, :3]     , SCREAMING_SNAKE_CASE__     , atol=1E-4					)					)

											# verify area
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     torch.tensor([147979.6875, 165527.0469, 484638.5938, 11292.9375, 5879.6562, 7634.1147]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""area"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify boxes
											SCREAMING_SNAKE_CASE__		: Any     =     torch.Size([6, 4]					)
											self.assertEqual(encoding["""labels"""][0]["""boxes"""].shape     , SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[str]     =     torch.tensor([0.2625, 0.5437, 0.4688, 0.8625]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""boxes"""][0]     , SCREAMING_SNAKE_CASE__     , atol=1E-3					)					)
											# verify image_id
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     torch.tensor([3_97_69]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""image_id"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify is_crowd
											SCREAMING_SNAKE_CASE__		: str     =     torch.tensor([0, 0, 0, 0, 0, 0]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""iscrowd"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify class_labels
											SCREAMING_SNAKE_CASE__		: List[Any]     =     torch.tensor([17, 17, 63, 75, 75, 93]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""class_labels"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify masks
											SCREAMING_SNAKE_CASE__		: Tuple     =     82_28_73
											self.assertEqual(encoding["""labels"""][0]["""masks"""].sum().item()     , SCREAMING_SNAKE_CASE__					)
											# verify orig_size
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     torch.tensor([4_80, 6_40]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""orig_size"""]     , SCREAMING_SNAKE_CASE__					)					)
											# verify size
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     torch.tensor([8_00, 10_66]					)
											self.assertTrue(torch.allclose(encoding["""labels"""][0]["""size"""]     , SCREAMING_SNAKE_CASE__					)					)






"""simple docstring"""




from manim import *



class 			lowerCAmelCase_		(a__						):


				"""simple docstring"""



				def 			__magic_name__					(self					)      ->	Any:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Dict     =     Rectangle(height=0.5     , width=0.5					)
											SCREAMING_SNAKE_CASE__		: Dict     =     Rectangle(height=0.46     , width=0.46					).set_stroke(width=0					)

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     Rectangle(height=0.25     , width=0.25					)

											SCREAMING_SNAKE_CASE__		: Any     =     [mem.copy() for i in range(6					)]
											SCREAMING_SNAKE_CASE__		: int     =     [mem.copy() for i in range(6					)]
											SCREAMING_SNAKE_CASE__		: Any     =     VGroup(*SCREAMING_SNAKE_CASE__					).arrange(SCREAMING_SNAKE_CASE__     , buff=0					)
											SCREAMING_SNAKE_CASE__		: Any     =     VGroup(*SCREAMING_SNAKE_CASE__					).arrange(SCREAMING_SNAKE_CASE__     , buff=0					)
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     VGroup(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					).arrange(SCREAMING_SNAKE_CASE__     , buff=0					)
											SCREAMING_SNAKE_CASE__		: List[str]     =     Text("""CPU"""     , font_size=24					)
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     Group(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					).arrange(SCREAMING_SNAKE_CASE__     , buff=0.5     , aligned_edge=SCREAMING_SNAKE_CASE__					)
											cpu.move_to([-2.5, -0.5, 0]					)
											self.add(SCREAMING_SNAKE_CASE__					)

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

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

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

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     []
											SCREAMING_SNAKE_CASE__		: Any     =     []

											for i, rect in enumerate(SCREAMING_SNAKE_CASE__					):
																		SCREAMING_SNAKE_CASE__		: List[str]     =     fill.copy().set_fill(SCREAMING_SNAKE_CASE__     , opacity=0.8					)
																		target.move_to(SCREAMING_SNAKE_CASE__					)
																		model_arr.append(SCREAMING_SNAKE_CASE__					)

																		SCREAMING_SNAKE_CASE__		: List[str]     =     Rectangle(height=0.46     , width=0.46					).set_stroke(width=0.0					).set_fill(SCREAMING_SNAKE_CASE__     , opacity=0.8					)
																		cpu_target.move_to(cpu_left_col_base[i]					)
																		model_cpu_arr.append(SCREAMING_SNAKE_CASE__					)

											self.add(*SCREAMING_SNAKE_CASE__     , *SCREAMING_SNAKE_CASE__					)

											SCREAMING_SNAKE_CASE__		: Tuple     =     [meta_mem.copy() for i in range(6					)]
											SCREAMING_SNAKE_CASE__		: List[str]     =     [meta_mem.copy() for i in range(6					)]
											SCREAMING_SNAKE_CASE__		: Any     =     VGroup(*SCREAMING_SNAKE_CASE__					).arrange(SCREAMING_SNAKE_CASE__     , buff=0					)
											SCREAMING_SNAKE_CASE__		: int     =     VGroup(*SCREAMING_SNAKE_CASE__					).arrange(SCREAMING_SNAKE_CASE__     , buff=0					)
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     VGroup(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					).arrange(SCREAMING_SNAKE_CASE__     , buff=0					)
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     Text("""Disk"""     , font_size=24					)
											SCREAMING_SNAKE_CASE__		: Any     =     Group(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					).arrange(SCREAMING_SNAKE_CASE__     , buff=0.5     , aligned_edge=SCREAMING_SNAKE_CASE__					)
											disk.move_to([-4, -1.25, 0]					)
											self.add(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					)

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

											SCREAMING_SNAKE_CASE__		: List[str]     =     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(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					)

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

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

											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     MarkupText(
											    F'''Now watch as an input is passed through the model\nand how the memory is utilized and handled.'''     , font_size=24     , )
											step_a.move_to([2, 2, 0]					)

											self.play(Write(SCREAMING_SNAKE_CASE__					)					)

											SCREAMING_SNAKE_CASE__		: Dict     =     Square(0.3					)
											input.set_fill(SCREAMING_SNAKE_CASE__     , opacity=1.0					)
											input.set_stroke(width=0.0					)
											input.next_to(model_base[0]     , SCREAMING_SNAKE_CASE__     , buff=0.5					)

											self.play(Write(SCREAMING_SNAKE_CASE__					)					)

											input.generate_target()
											input.target.next_to(model_arr[0]     , direction=SCREAMING_SNAKE_CASE__     , buff=0.02					)
											self.play(MoveToTarget(SCREAMING_SNAKE_CASE__					)					)

											self.play(FadeOut(SCREAMING_SNAKE_CASE__					)					)

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     Arrow(start=SCREAMING_SNAKE_CASE__     , end=SCREAMING_SNAKE_CASE__     , color=SCREAMING_SNAKE_CASE__     , buff=0.5					)
											a.next_to(model_arr[0].get_left()     , SCREAMING_SNAKE_CASE__     , buff=0.2					)

											model_cpu_arr[0].generate_target()
											model_cpu_arr[0].target.move_to(gpu_rect[0]					)

											SCREAMING_SNAKE_CASE__		: Tuple     =     MarkupText(
											    F'''As the input reaches a layer, the hook triggers\nand weights are moved from the CPU\nto the GPU and back.'''     , font_size=24     , )
											step_a.move_to([2, 2, 0]					)

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

											SCREAMING_SNAKE_CASE__		: Tuple     =     {"""run_time""": 1, """fade_in""": True, """fade_out""": True, """buff""": 0.02}

											self.play(
											    Write(SCREAMING_SNAKE_CASE__					)     , Circumscribe(model_arr[0]     , color=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)     , Circumscribe(model_cpu_arr[0]     , color=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)     , Circumscribe(gpu_rect[0]     , color=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)     , )
											self.play(MoveToTarget(model_cpu_arr[0]					)					)

											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     a.copy()
											for i in range(6					):
																		a_c.next_to(model_arr[i].get_right() + 0.02     , SCREAMING_SNAKE_CASE__     , buff=0.2					)

																		input.generate_target()
																		input.target.move_to(model_arr[i].get_right() + 0.02					)

																		SCREAMING_SNAKE_CASE__		: Optional[Any]     =     AnimationGroup(
																		    FadeOut(SCREAMING_SNAKE_CASE__     , run_time=0.5					)     , MoveToTarget(SCREAMING_SNAKE_CASE__     , run_time=0.5					)     , FadeIn(SCREAMING_SNAKE_CASE__     , run_time=0.5					)     , lag_ratio=0.2					)

																		self.play(SCREAMING_SNAKE_CASE__					)

																		model_cpu_arr[i].generate_target()
																		model_cpu_arr[i].target.move_to(cpu_left_col_base[i]					)

																		if i < 5:
																									model_cpu_arr[i + 1].generate_target()
																									model_cpu_arr[i + 1].target.move_to(gpu_rect[0]					)
																									if i >= 1:
																																SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     0.7

																									self.play(
																									    Circumscribe(model_arr[i]     , **SCREAMING_SNAKE_CASE__					)     , Circumscribe(cpu_left_col_base[i]     , **SCREAMING_SNAKE_CASE__					)     , Circumscribe(cpu_left_col_base[i + 1]     , color=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)     , Circumscribe(gpu_rect[0]     , color=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)     , Circumscribe(model_arr[i + 1]     , color=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)     , )
																									if i < 1:
																																self.play(
																																    MoveToTarget(model_cpu_arr[i]					)     , MoveToTarget(model_cpu_arr[i + 1]					)     , )
																									else:
																																self.play(
																																    MoveToTarget(model_cpu_arr[i]     , run_time=0.7					)     , MoveToTarget(model_cpu_arr[i + 1]     , run_time=0.7					)     , )
																		else:
																									model_cpu_arr[i].generate_target()
																									model_cpu_arr[i].target.move_to(cpu_left_col_base[-1]					)
																									input.generate_target()
																									input.target.next_to(model_arr[-1].get_right()     , RIGHT + 0.02     , buff=0.2					)

																									self.play(
																									    Circumscribe(model_arr[-1]     , color=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)     , Circumscribe(cpu_left_col_base[-1]     , color=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)     , Circumscribe(gpu_rect[0]     , color=SCREAMING_SNAKE_CASE__     , **SCREAMING_SNAKE_CASE__					)     , )

																									self.play(MoveToTarget(model_cpu_arr[i]					)					)

																		SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     a_c
																		SCREAMING_SNAKE_CASE__		: Optional[Any]     =     a_c.copy()

											input.generate_target()
											input.target.next_to(model_base[-1]     , RIGHT + 0.02     , buff=0.5					)
											self.play(
											    FadeOut(SCREAMING_SNAKE_CASE__					)     , FadeOut(SCREAMING_SNAKE_CASE__     , run_time=0.5					)     , )

											SCREAMING_SNAKE_CASE__		: Dict     =     MarkupText(F'''Inference on a model too large for GPU memory\nis successfully completed.'''     , font_size=24					)
											step_a.move_to([2, 2, 0]					)

											self.play(Write(SCREAMING_SNAKE_CASE__     , run_time=3					)     , MoveToTarget(SCREAMING_SNAKE_CASE__					)					)

											self.wait()




