Added residual layer example. Fixed some bugs in the process.

This commit is contained in:
Alec Helbling
2023-02-05 12:26:36 -05:00
parent 2b21261db7
commit b1c838a45f
11 changed files with 382 additions and 18 deletions

38
tests/test_ff_residual.py Normal file
View File

@ -0,0 +1,38 @@
from manim import *
from manim_ml.neural_network import NeuralNetwork, FeedForwardLayer, MathOperationLayer
# Make the specific scene
config.pixel_height = 1200
config.pixel_width = 1900
config.frame_height = 6.0
config.frame_width = 6.0
class TestFeedForwardResidualNetwork(Scene):
def construct(self):
# Add the network
nn = NeuralNetwork({
"feed_forward_1": FeedForwardLayer(3),
"feed_forward_2": FeedForwardLayer(3, activation_function="ReLU"),
"feed_forward_3": FeedForwardLayer(3),
"sum_operation": MathOperationLayer("+", activation_function="ReLU"),
},
layer_spacing=0.38
)
self.add(nn)
# Make connections
input_blank_dot = Dot(
nn.input_layers_dict["feed_forward_1"].get_left() - np.array([0.65, 0.0, 0.0])
)
nn.add_connection(input_blank_dot, "feed_forward_1", arc_direction="straight")
nn.add_connection("feed_forward_1", "sum_operation")
output_blank_dot = Dot(
nn.input_layers_dict["sum_operation"].get_right() + np.array([0.65, 0.0, 0.0])
)
nn.add_connection("sum_operation", output_blank_dot, arc_direction="straight")
# Make forward pass animation
self.play(
nn.make_forward_pass_animation()
)