forked from helblazer811/ManimML
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update readme and setup code to be pushed to pip repository.
- Loading branch information
1 parent
313d1aa
commit 334662e
Showing
11 changed files
with
341 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from manim import * | ||
from manim_ml.neural_network.layers import FeedForwardLayer, ImageLayer | ||
from manim_ml.neural_network.neural_network import NeuralNetwork | ||
from PIL import Image | ||
import numpy as np | ||
|
||
config.pixel_height = 720 | ||
config.pixel_width = 1280 | ||
config.frame_height = 6.0 | ||
config.frame_width = 6.0 | ||
|
||
class ImageNeuralNetworkScene(Scene): | ||
|
||
def make_code_snippet(self): | ||
code_str = """ | ||
# Make image object | ||
image = Image.open('images/image.jpeg') | ||
numpy_image = np.asarray(image) | ||
# Make Neural Network | ||
layers = [ | ||
ImageLayer(numpy_image, height=1.4), | ||
FeedForwardLayer(3), | ||
FeedForwardLayer(5), | ||
FeedForwardLayer(3) | ||
] | ||
nn = NeuralNetwork(layers) | ||
self.add(nn) | ||
# Play animation | ||
self.play( | ||
nn.make_forward_pass_animation() | ||
) | ||
""" | ||
|
||
code = Code( | ||
code = code_str, | ||
tab_width=4, | ||
background_stroke_width=1, | ||
background_stroke_color=WHITE, | ||
insert_line_no=False, | ||
style='monokai', | ||
#background="window", | ||
language="py", | ||
) | ||
code.scale(0.2) | ||
|
||
return code | ||
|
||
def construct(self): | ||
image = Image.open('../../tests/images/image.jpeg') | ||
numpy_image = np.asarray(image) | ||
# Make nn | ||
layers = [ | ||
ImageLayer(numpy_image, height=1.4), | ||
FeedForwardLayer(3), | ||
FeedForwardLayer(5), | ||
FeedForwardLayer(3), | ||
FeedForwardLayer(6) | ||
] | ||
nn = NeuralNetwork(layers) | ||
nn.scale(0.9) | ||
# Center the nn | ||
nn.move_to(ORIGIN) | ||
nn.rotate(-PI/2) | ||
nn.layers[0].image_mobject.rotate(PI/2) | ||
nn.layers[0].image_mobject.shift([0, -0.4, 0]) | ||
nn.shift([1.5, 0.3, 0]) | ||
self.add(nn) | ||
# Make code snippet | ||
code_snippet = self.make_code_snippet() | ||
code_snippet.scale(1.9) | ||
code_snippet.shift([-1.25, 0, 0]) | ||
self.add(code_snippet) | ||
# Play animation | ||
self.play( | ||
nn.make_forward_pass_animation(run_time=10) | ||
) | ||
|
||
if __name__ == "__main__": | ||
"""Render all scenes""" | ||
# Feed Forward Neural Network | ||
ffnn_scene = FeedForwardNeuralNetworkScene() | ||
ffnn_scene.render() | ||
# Neural Network | ||
nn_scene = NeuralNetworkScene() | ||
nn_scene.render() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from manim import * | ||
from manim_ml.neural_network.layers import FeedForwardLayer, ImageLayer, EmbeddingLayer | ||
from manim_ml.neural_network.neural_network import NeuralNetwork | ||
from PIL import Image | ||
import numpy as np | ||
|
||
config.pixel_height = 720 | ||
config.pixel_width = 720 | ||
config.frame_height = 6.0 | ||
config.frame_width = 6.0 | ||
|
||
class VAECodeSnippetScene(Scene): | ||
|
||
def make_code_snippet(self): | ||
code_str = """ | ||
# Make Neural Network | ||
nn = NeuralNetwork([ | ||
ImageLayer(numpy_image, height=1.2), | ||
FeedForwardLayer(5), | ||
FeedForwardLayer(3), | ||
EmbeddingLayer(), | ||
FeedForwardLayer(3), | ||
FeedForwardLayer(5), | ||
ImageLayer(numpy_image, height=1.2), | ||
], layer_spacing=0.1) | ||
# Play animation | ||
self.play(nn.make_forward_pass_animation()) | ||
""" | ||
|
||
code = Code( | ||
code = code_str, | ||
tab_width=4, | ||
background_stroke_width=1, | ||
# background_stroke_color=WHITE, | ||
insert_line_no=False, | ||
background="window", | ||
# font="Monospace", | ||
style='one-dark', | ||
language="py", | ||
) | ||
|
||
return code | ||
|
||
def construct(self): | ||
image = Image.open('../../tests/images/image.jpeg') | ||
numpy_image = np.asarray(image) | ||
embedding_layer = EmbeddingLayer(dist_theme="ellipse", point_radius=0.04).scale(1.0) | ||
# Make nn | ||
nn = NeuralNetwork([ | ||
ImageLayer(numpy_image, height=1.2), | ||
FeedForwardLayer(5), | ||
FeedForwardLayer(3), | ||
embedding_layer, | ||
FeedForwardLayer(3), | ||
FeedForwardLayer(5), | ||
ImageLayer(numpy_image, height=1.2), | ||
], layer_spacing=0.1) | ||
|
||
nn.scale(1.1) | ||
# Center the nn | ||
nn.move_to(ORIGIN) | ||
# nn.rotate(-PI/2) | ||
# nn.all_layers[0].image_mobject.rotate(PI/2) | ||
# nn.all_layers[0].image_mobject.shift([0, -0.4, 0]) | ||
# nn.all_layers[-1].image_mobject.rotate(PI/2) | ||
# nn.all_layers[-1].image_mobject.shift([0, -0.4, 0]) | ||
nn.shift([0, -1.4, 0]) | ||
self.add(nn) | ||
# Make code snippet | ||
code_snippet = self.make_code_snippet() | ||
code_snippet.scale(0.52) | ||
code_snippet.shift([0, 1.25, 0]) | ||
# code_snippet.shift([-1.25, 0, 0]) | ||
self.add(code_snippet) | ||
# Play animation | ||
self.play( | ||
nn.make_forward_pass_animation(), | ||
run_time=10 | ||
) | ||
|
||
if __name__ == "__main__": | ||
"""Render all scenes""" | ||
# Neural Network | ||
nn_scene = VAECodeSnippetScene() | ||
nn_scene.render() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from manim import * | ||
from manim_ml.neural_network.layers import FeedForwardLayer, ImageLayer, EmbeddingLayer | ||
from manim_ml.neural_network.neural_network import NeuralNetwork | ||
from PIL import Image | ||
import numpy as np | ||
|
||
config.pixel_height = 720 | ||
config.pixel_width = 1280 | ||
config.frame_height = 6.0 | ||
config.frame_width = 6.0 | ||
|
||
class VAECodeSnippetScene(Scene): | ||
|
||
def make_code_snippet(self): | ||
code_str = """ | ||
# Make image object | ||
image = Image.open('images/image.jpeg') | ||
numpy_image = np.asarray(image) | ||
# Make Neural Network | ||
nn = NeuralNetwork([ | ||
ImageLayer(numpy_image, height=1.2), | ||
FeedForwardLayer(5), | ||
FeedForwardLayer(3), | ||
EmbeddingLayer(), | ||
FeedForwardLayer(3), | ||
FeedForwardLayer(5), | ||
ImageLayer(numpy_image, height=1.2), | ||
], layer_spacing=0.1) | ||
self.add(nn) | ||
# Play animation | ||
self.play( | ||
nn.make_forward_pass_animation() | ||
) | ||
""" | ||
|
||
code = Code( | ||
code = code_str, | ||
tab_width=4, | ||
background_stroke_width=1, | ||
# background_stroke_color=WHITE, | ||
insert_line_no=False, | ||
background="window", | ||
# font="Monospace", | ||
style='one-dark', | ||
language="py", | ||
) | ||
code.scale(0.2) | ||
|
||
return code | ||
|
||
def construct(self): | ||
image = Image.open('../../tests/images/image.jpeg') | ||
numpy_image = np.asarray(image) | ||
embedding_layer = EmbeddingLayer(dist_theme="ellipse", point_radius=0.04).scale(1.0) | ||
# Make nn | ||
nn = NeuralNetwork([ | ||
ImageLayer(numpy_image, height=1.0), | ||
FeedForwardLayer(5), | ||
FeedForwardLayer(3), | ||
embedding_layer, | ||
FeedForwardLayer(3), | ||
FeedForwardLayer(5), | ||
ImageLayer(numpy_image, height=1.0), | ||
], layer_spacing=0.1) | ||
|
||
nn.scale(0.65) | ||
# Center the nn | ||
nn.move_to(ORIGIN) | ||
nn.rotate(-PI/2) | ||
nn.all_layers[0].image_mobject.rotate(PI/2) | ||
# nn.all_layers[0].image_mobject.shift([0, -0.4, 0]) | ||
nn.all_layers[-1].image_mobject.rotate(PI/2) | ||
# nn.all_layers[-1].image_mobject.shift([0, -0.4, 0]) | ||
nn.shift([1.5, 0.0, 0]) | ||
self.add(nn) | ||
# Make code snippet | ||
code_snippet = self.make_code_snippet() | ||
code_snippet.scale(1.9) | ||
code_snippet.shift([-1.25, 0, 0]) | ||
self.add(code_snippet) | ||
# Play animation | ||
self.play( | ||
nn.make_forward_pass_animation(), | ||
run_time=10 | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
"""Render all scenes""" | ||
# Neural Network | ||
nn_scene = VAECodeSnippetScene() | ||
nn_scene.render() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
Logo for Manim Machine Learning | ||
""" | ||
from manim import * | ||
from manim_ml.neural_network.neural_network import FeedForwardNeuralNetwork | ||
|
||
config.pixel_height = 500 | ||
config.pixel_width = 500 | ||
config.frame_height = 4.0 | ||
config.frame_width = 4.0 | ||
|
||
class ManimMLLogo(Scene): | ||
|
||
def construct(self): | ||
self.text = Text("ManimML") | ||
self.text.scale(1.0) | ||
self.neural_network = FeedForwardNeuralNetwork([3, 5, 3, 6, 3], layer_spacing=0.3, node_color=BLUE) | ||
self.neural_network.scale(1.0) | ||
self.neural_network.move_to(self.text.get_bottom()) | ||
self.neural_network.shift(1.25 * DOWN) | ||
self.logo_group = Group(self.text, self.neural_network) | ||
self.logo_group.scale(1.0) | ||
self.logo_group.move_to(ORIGIN) | ||
self.play(Write(self.text)) | ||
self.play(Create(self.neural_network)) | ||
# self.surrounding_rectangle = SurroundingRectangle(self.logo_group, buff=0.3, color=BLUE) | ||
underline = Underline(self.text, color=BLUE) | ||
animation_group = AnimationGroup( | ||
self.neural_network.make_forward_pass_animation(run_time=5), | ||
Create(underline), | ||
# Create(self.surrounding_rectangle) | ||
) | ||
# self.surrounding_rectangle = SurroundingRectangle(self.logo_group, buff=0.3, color=BLUE) | ||
underline = Underline(self.text, color=BLUE) | ||
animation_group = AnimationGroup( | ||
self.neural_network.make_forward_pass_animation(run_time=5), | ||
Create(underline), | ||
# Create(self.surrounding_rectangle) | ||
) | ||
self.play(animation_group) | ||
self.wait(5) |
Oops, something went wrong.