Skip to content

Commit

Permalink
Used Black to reformat the code in the repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
helblazer811 committed Jan 2, 2023
1 parent 334662e commit 3d6e807
Show file tree
Hide file tree
Showing 71 changed files with 1,705 additions and 1,139 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ manim_ml/media
media
pyproject.toml
setup.cfg
!examples/media
!examples/media
examples/media/videos
examples/media/text
examples/media/images
15 changes: 7 additions & 8 deletions examples/basic_neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
from manim_ml.neural_network.layers import FeedForwardLayer
from manim_ml.neural_network.neural_network import NeuralNetwork


class NeuralNetworkScene(Scene):
"""Test Scene for the Neural Network"""

def construct(self):
# Make the Layer object
layers = [
FeedForwardLayer(3),
FeedForwardLayer(5),
FeedForwardLayer(3)
]
layers = [FeedForwardLayer(3), FeedForwardLayer(5), FeedForwardLayer(3)]
nn = NeuralNetwork(layers)
nn.scale(2)
nn.move_to(ORIGIN)
# Make Animation
self.add(nn)
#self.play(Create(nn))
forward_propagation_animation = nn.make_forward_pass_animation(run_time=5, passing_flash=True)
# self.play(Create(nn))
forward_propagation_animation = nn.make_forward_pass_animation(
run_time=5, passing_flash=True
)

self.play(forward_propagation_animation)
self.play(forward_propagation_animation)
22 changes: 11 additions & 11 deletions examples/cnn/cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
config.frame_width = 7.0
ROOT_DIR = Path(__file__).parents[2]


def make_code_snippet():
code_str = """
# Make nn
Expand All @@ -31,32 +32,34 @@ def make_code_snippet():
"""

code = Code(
code = code_str,
code=code_str,
tab_width=4,
background_stroke_width=1,
background_stroke_color=WHITE,
insert_line_no=False,
style='monokai',
#background="window",
style="monokai",
# background="window",
language="py",
)
code.scale(0.50)

return code


class CombinedScene(ThreeDScene):
def construct(self):
image = Image.open(ROOT_DIR / 'assets/mnist/digit.jpeg')
image = Image.open(ROOT_DIR / "assets/mnist/digit.jpeg")
numpy_image = np.asarray(image)
# Make nn
nn = NeuralNetwork([
nn = NeuralNetwork(
[
ImageLayer(numpy_image, height=1.5),
Convolutional3DLayer(1, 7, 7, 3, 3, filter_spacing=0.32),
Convolutional3DLayer(3, 5, 5, 3, 3, filter_spacing=0.32),
Convolutional3DLayer(5, 3, 3, 1, 1, filter_spacing=0.18),
FeedForwardLayer(3),
FeedForwardLayer(3),
],
],
layer_spacing=0.25,
)
# Center the nn
Expand All @@ -71,10 +74,7 @@ def construct(self):
group.move_to(ORIGIN)
# Play animation
forward_pass = nn.make_forward_pass_animation(
corner_pulses=False,
all_filters_at_once=False
corner_pulses=False, all_filters_at_once=False
)
self.wait(1)
self.play(
forward_pass
)
self.play(forward_pass)
25 changes: 12 additions & 13 deletions examples/code_snippet/image_nn_code_snippet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
config.frame_height = 6.0
config.frame_width = 6.0

class ImageNeuralNetworkScene(Scene):

class ImageNeuralNetworkScene(Scene):
def make_code_snippet(self):
code_str = """
# Make image object
Expand All @@ -32,36 +32,36 @@ def make_code_snippet(self):
"""

code = Code(
code = code_str,
code=code_str,
tab_width=4,
background_stroke_width=1,
background_stroke_color=WHITE,
insert_line_no=False,
style='monokai',
#background="window",
style="monokai",
# background="window",
language="py",
)
code.scale(0.2)

return code

def construct(self):
image = Image.open('../../tests/images/image.jpeg')
image = Image.open("../../tests/images/image.jpeg")
numpy_image = np.asarray(image)
# Make nn
layers = [
ImageLayer(numpy_image, height=1.4),
FeedForwardLayer(3),
FeedForwardLayer(3),
FeedForwardLayer(5),
FeedForwardLayer(3),
FeedForwardLayer(6)
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.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)
Expand All @@ -71,15 +71,14 @@ def construct(self):
code_snippet.shift([-1.25, 0, 0])
self.add(code_snippet)
# Play animation
self.play(
nn.make_forward_pass_animation(run_time=10)
)
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
# Neural Network
nn_scene = NeuralNetworkScene()
nn_scene.render()
43 changes: 23 additions & 20 deletions examples/code_snippet/vae_code_landscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
config.frame_height = 6.0
config.frame_width = 6.0

class VAECodeSnippetScene(Scene):

class VAECodeSnippetScene(Scene):
def make_code_snippet(self):
code_str = """
# Make Neural Network
Expand All @@ -28,33 +28,38 @@ def make_code_snippet(self):
"""

code = Code(
code = code_str,
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',
style="one-dark",
language="py",
)

return code

def construct(self):
image = Image.open('../../tests/images/image.jpeg')
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)
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 = 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
Expand All @@ -73,13 +78,11 @@ def construct(self):
# code_snippet.shift([-1.25, 0, 0])
self.add(code_snippet)
# Play animation
self.play(
nn.make_forward_pass_animation(),
run_time=10
)

self.play(nn.make_forward_pass_animation(), run_time=10)


if __name__ == "__main__":
"""Render all scenes"""
# Neural Network
# Neural Network
nn_scene = VAECodeSnippetScene()
nn_scene.render()
48 changes: 25 additions & 23 deletions examples/code_snippet/vae_nn_code_snippet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
config.frame_height = 6.0
config.frame_width = 6.0

class VAECodeSnippetScene(Scene):

class VAECodeSnippetScene(Scene):
def make_code_snippet(self):
code_str = """
# Make image object
Expand All @@ -34,42 +34,47 @@ def make_code_snippet(self):
"""

code = Code(
code = code_str,
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',
style="one-dark",
language="py",
)
code.scale(0.2)

return code

def construct(self):
image = Image.open('../../tests/images/image.jpeg')
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)
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 = 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.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.rotate(PI / 2)
# nn.all_layers[-1].image_mobject.shift([0, -0.4, 0])
nn.shift([1.5, 0.0, 0])
self.add(nn)
Expand All @@ -79,14 +84,11 @@ def construct(self):
code_snippet.shift([-1.25, 0, 0])
self.add(code_snippet)
# Play animation
self.play(
nn.make_forward_pass_animation(),
run_time=10
)

self.play(nn.make_forward_pass_animation(), run_time=10)


if __name__ == "__main__":
"""Render all scenes"""
# Neural Network
# Neural Network
nn_scene = VAECodeSnippetScene()
nn_scene.render()
Loading

0 comments on commit 3d6e807

Please sign in to comment.