mirror of
https://github.com/helblazer811/ManimML.git
synced 2025-05-23 05:25:56 +08:00
Updated examples
This commit is contained in:
@ -1,26 +1,30 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from manim_ml.neural_network.layers.convolutional import ConvolutionalLayer
|
from manim_ml.neural_network.layers.convolutional3d import Convolutional3DLayer
|
||||||
from manim_ml.neural_network.layers.feed_forward import FeedForwardLayer
|
from manim_ml.neural_network.layers.feed_forward import FeedForwardLayer
|
||||||
from manim_ml.neural_network.layers.image import ImageLayer
|
from manim_ml.neural_network.layers.image import ImageLayer
|
||||||
from manim_ml.neural_network.neural_network import NeuralNetwork
|
from manim_ml.neural_network.neural_network import NeuralNetwork
|
||||||
|
|
||||||
|
# Make the specific scene
|
||||||
|
config.pixel_height = 1200
|
||||||
|
config.pixel_width = 1900
|
||||||
|
config.frame_height = 7.0
|
||||||
|
config.frame_width = 7.0
|
||||||
|
|
||||||
def make_code_snippet():
|
def make_code_snippet():
|
||||||
code_str = """
|
code_str = """
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork([
|
||||||
ImageLayer(numpy_image),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
ConvolutionalLayer(3, 3, 3),
|
Convolutional3DLayer(1, 7, 7, 3, 3),
|
||||||
ConvolutionalLayer(5, 2, 2),
|
Convolutional3DLayer(3, 5, 5, 3, 3),
|
||||||
ConvolutionalLayer(10, 2, 1),
|
Convolutional3DLayer(5, 3, 3, 1, 1),
|
||||||
FeedForwardLayer(3),
|
FeedForwardLayer(3),
|
||||||
FeedForwardLayer(1)
|
FeedForwardLayer(3),
|
||||||
], layer_spacing=0.2)
|
])
|
||||||
# Center the nn
|
|
||||||
self.play(Create(nn))
|
|
||||||
# Play animation
|
# Play animation
|
||||||
self.play(nn.make_forward_pass_animation(run_time=5))
|
self.play(nn.make_forward_pass_animation())
|
||||||
"""
|
"""
|
||||||
|
|
||||||
code = Code(
|
code = Code(
|
||||||
@ -33,40 +37,41 @@ def make_code_snippet():
|
|||||||
#background="window",
|
#background="window",
|
||||||
language="py",
|
language="py",
|
||||||
)
|
)
|
||||||
code.scale(0.6)
|
code.scale(0.50)
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
class CombinedScene(ThreeDScene):
|
||||||
# Make the specific scene
|
|
||||||
config.pixel_height = 1200
|
|
||||||
config.pixel_width = 1900
|
|
||||||
config.frame_height = 12.0
|
|
||||||
config.frame_width = 12.0
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene, Scene):
|
|
||||||
def construct(self):
|
def construct(self):
|
||||||
image = Image.open('../../assets/mnist/digit.jpeg')
|
image = Image.open('../../assets/mnist/digit.jpeg')
|
||||||
numpy_image = np.asarray(image)
|
numpy_image = np.asarray(image)
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork([
|
||||||
ImageLayer(numpy_image, height=3.5),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
ConvolutionalLayer(3, 3, 3, filter_spacing=0.2),
|
Convolutional3DLayer(1, 7, 7, 3, 3, filter_spacing=0.32),
|
||||||
ConvolutionalLayer(5, 2, 2, filter_spacing=0.2),
|
Convolutional3DLayer(3, 5, 5, 3, 3, filter_spacing=0.32),
|
||||||
ConvolutionalLayer(10, 2, 1, filter_spacing=0.2),
|
Convolutional3DLayer(5, 3, 3, 1, 1, filter_spacing=0.18),
|
||||||
FeedForwardLayer(3, rectangle_stroke_width=4, node_stroke_width=4).scale(2),
|
FeedForwardLayer(3),
|
||||||
FeedForwardLayer(1, rectangle_stroke_width=4, node_stroke_width=4).scale(2)
|
FeedForwardLayer(3),
|
||||||
], layer_spacing=0.2)
|
],
|
||||||
nn.scale(0.9)
|
layer_spacing=0.25,
|
||||||
|
)
|
||||||
|
# Center the nn
|
||||||
nn.move_to(ORIGIN)
|
nn.move_to(ORIGIN)
|
||||||
nn.shift(UP*1.8)
|
self.add(nn)
|
||||||
# Make code snippet
|
# Make code snippet
|
||||||
code = make_code_snippet()
|
code = make_code_snippet()
|
||||||
code.shift(DOWN*1.8)
|
code.next_to(nn, DOWN)
|
||||||
# Center the nn
|
|
||||||
self.play(Create(nn))
|
|
||||||
self.add(code)
|
self.add(code)
|
||||||
|
# Group it all
|
||||||
|
group = Group(nn, code)
|
||||||
|
group.move_to(ORIGIN)
|
||||||
# Play animation
|
# Play animation
|
||||||
# self.set_camera_orientation(phi=280* DEGREES, theta=-20*DEGREES, gamma=90 * DEGREES)
|
forward_pass = nn.make_forward_pass_animation(
|
||||||
# self.begin_ambient_camera_rotation()
|
corner_pulses=False,
|
||||||
self.play(nn.make_forward_pass_animation(run_time=5))
|
all_filters_at_once=False
|
||||||
|
)
|
||||||
|
self.wait(1)
|
||||||
|
self.play(
|
||||||
|
forward_pass
|
||||||
|
)
|
||||||
|
@ -45,7 +45,7 @@ class ThreeDLayer(ABC):
|
|||||||
three_d_x_rotation = 90 * DEGREES #-90 * DEGREES
|
three_d_x_rotation = 90 * DEGREES #-90 * DEGREES
|
||||||
three_d_y_rotation = 0 * DEGREES # -10 * DEGREES
|
three_d_y_rotation = 0 * DEGREES # -10 * DEGREES
|
||||||
rotation_angle = 60 * DEGREES
|
rotation_angle = 60 * DEGREES
|
||||||
rotation_axis = [0.1, 0.9, 0]
|
rotation_axis = [0.0, 0.9, 0.0]
|
||||||
|
|
||||||
class ConnectiveLayer(VGroupNeuralNetworkLayer):
|
class ConnectiveLayer(VGroupNeuralNetworkLayer):
|
||||||
"""Forward pass animation for a given pair of layers"""
|
"""Forward pass animation for a given pair of layers"""
|
||||||
|
Reference in New Issue
Block a user