


"""simple docstring"""







from manim import *






class    __A       ( lowerCamelCase__    ):






	"""simple docstring"""




	def    SCREAMING_SNAKE_CASE							(	self		)      ->  Dict:
					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(*lowercase_		).arrange(lowercase_				,					buff=0		)
					a					=VGroup(*lowercase_		).arrange(lowercase_				,					buff=0		)
					a					=VGroup(lowercase_				,					lowercase_		).arrange(lowercase_				,					buff=0		)
					a					=Text('''CPU'''				,					font_size=24		)
					a					=Group(lowercase_				,					lowercase_		).arrange(lowercase_				,					buff=0.5				,					aligned_edge=lowercase_		)
					cpu.move_to([-2.5, -0.5, 0]		)
					self.add(lowercase_		)

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

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

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

					a					=[]
					a					=[]

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

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

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

					self.add(*lowercase_				,					*lowercase_		)

					a					=[meta_mem.copy() for i in range(6		)]
					a					=[meta_mem.copy() for i in range(6		)]
					a					=VGroup(*lowercase_		).arrange(lowercase_				,					buff=0		)
					a					=VGroup(*lowercase_		).arrange(lowercase_				,					buff=0		)
					a					=VGroup(lowercase_				,					lowercase_		).arrange(lowercase_				,					buff=0		)
					a					=Text('''Disk'''				,					font_size=24		)
					a					=Group(lowercase_				,					lowercase_		).arrange(lowercase_				,					buff=0.5				,					aligned_edge=lowercase_		)
					disk.move_to([-4.0, -1.25, 0]		)
					self.add(lowercase_				,					lowercase_		)

					a					=[]

					for i in range(6		):
									a					=fill.copy().set_fill(lowercase_				,					opacity=0.8		)
									target.move_to(disk_left_col_base[i]		).scale(0.5		)
									cpu_disk_arr.append(lowercase_		)

					self.add(*lowercase_		)

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

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

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

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

					for i in range(6		):
									a					=cpu_disk_arr[i]
									a					=rect.copy().set_fill(lowercase_				,					opacity=0.8		).scale(2.0		)
									cpa.generate_target()
									cpa.target.move_to(model_base[i]		)

									if i == 0:
													rect.set_fill(lowercase_				,					opacity=0.8		)
													rect.generate_target()
													rect.target.move_to(cpu_left_col_base[0]		).scale(2.0		)

													self.remove(
													    *lowercase_				,					*lowercase_				,					)

									else:
													rect.generate_target()
													rect.target.move_to(cpu_left_col_base[i]		).scale(2.0		)
									self.play(MoveToTarget(lowercase_		)				,					MoveToTarget(lowercase_		)				,					model_base[i].animate.set_stroke(lowercase_		)		)
					self.play(FadeOut(lowercase_		)		)

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

					a					=[]
					a					=[]
					for i in range(6		):
									a					=Arrow(start=lowercase_				,					end=lowercase_				,					color=lowercase_				,					buff=0.5		)
									a.next_to(model_base[i].get_left()				,					lowercase_				,					buff=0.2		)
									arrows.append(lowercase_		)
									animations.append(Write(lowercase_		)		)
					self.play(*lowercase_		)
					self.wait()



"""simple docstring"""







from cva import destroyAllWindows, imread, imshow, waitKey
def _A		(		lowercase ,					lowercase	):







    """simple docstring"""
    a	,   a					=img.shape[0], img.shape[1]

    def to_grayscale(lowercase ,					lowercase ,					lowercase	):
        return 0.2126 * red + 0.587 * green + 0.114 * blue

    def normalize(lowercase	):
        return min(lowercase ,					2_55	)

    for i in range(lowercase	):
        for j in range(lowercase	):
            a					=int(to_grayscale(*img[i][j]	)	)
            a					=[
                normalize(lowercase	),
                normalize(greyscale + factor	),
                normalize(greyscale + 2 * factor	),
            ]

    return img


if __name__ == "__main__":
       # read original image
       lowerCamelCase_     :     Any    		=						{
           percentage: imread("""image_data/lena.jpg""", 1) for percentage in (1_0, 2_0, 3_0, 4_0)
       }

       for percentage, img in images.items():
              make_sepia(img, percentage)

       for percentage, img in images.items():
              imshow(F'Original image with sepia (factor: {percentage})', img)

       waitKey(0)
       destroyAllWindows()