mirror of
https://github.com/helblazer811/ManimML.git
synced 2025-05-17 18:55:54 +08:00
Refactored makefile, moved around files to more appropriate places, deleted unused files,
reformatted code.
This commit is contained in:
21
Makefile
21
Makefile
@ -1,18 +1,9 @@
|
|||||||
setup:
|
setup:
|
||||||
conda activate manim
|
conda activate manim; \
|
||||||
export PROJECT_ROOT=$(pwd)
|
export PROJECT_ROOT=$(pwd)
|
||||||
video:
|
|
||||||
manim -pqh src/variational_autoencoder.py VAEScene --media_dir media
|
|
||||||
cp media/videos/vae/720p60/VAEScene.mp4 examples
|
|
||||||
train:
|
|
||||||
cd src/autoencoder_models
|
|
||||||
python vanilla_autoencoder.py
|
|
||||||
python variational_autoencoder.py
|
|
||||||
generate_visualizations:
|
|
||||||
cd src/autoencoder_models
|
|
||||||
python generate_images.py
|
|
||||||
python generate_interpolation.py
|
|
||||||
python generate_disentanglement.py
|
|
||||||
checkstyle:
|
checkstyle:
|
||||||
pycodestyle src
|
black .; \
|
||||||
pydocstyle src
|
pydocstyle .
|
||||||
|
publish_pip:
|
||||||
|
python3 -m build; \
|
||||||
|
python3 -m twine upload --repository pypi dist/*
|
@ -8,11 +8,7 @@ class NeuralNetworkScene(Scene):
|
|||||||
|
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make the Layer object
|
# Make the Layer object
|
||||||
layers = [
|
layers = [FeedForwardLayer(3), FeedForwardLayer(5), FeedForwardLayer(3)]
|
||||||
FeedForwardLayer(3),
|
|
||||||
FeedForwardLayer(5),
|
|
||||||
FeedForwardLayer(3)
|
|
||||||
]
|
|
||||||
nn = NeuralNetwork(layers)
|
nn = NeuralNetwork(layers)
|
||||||
nn.scale(2)
|
nn.scale(2)
|
||||||
nn.move_to(ORIGIN)
|
nn.move_to(ORIGIN)
|
||||||
|
@ -15,6 +15,7 @@ config.frame_height = 7.0
|
|||||||
config.frame_width = 7.0
|
config.frame_width = 7.0
|
||||||
ROOT_DIR = Path(__file__).parents[2]
|
ROOT_DIR = Path(__file__).parents[2]
|
||||||
|
|
||||||
|
|
||||||
def make_code_snippet():
|
def make_code_snippet():
|
||||||
code_str = """
|
code_str = """
|
||||||
# Make the neural network
|
# Make the neural network
|
||||||
@ -42,6 +43,7 @@ def make_code_snippet():
|
|||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
image = Image.open(ROOT_DIR / "assets/mnist/digit.jpeg")
|
image = Image.open(ROOT_DIR / "assets/mnist/digit.jpeg")
|
||||||
@ -72,4 +74,4 @@ class CombinedScene(ThreeDScene):
|
|||||||
# Play animation
|
# Play animation
|
||||||
forward_pass = nn.make_forward_pass_animation()
|
forward_pass = nn.make_forward_pass_animation()
|
||||||
self.wait(1)
|
self.wait(1)
|
||||||
self.play(forward_pass)
|
self.play(forward_pass)
|
||||||
|
@ -15,6 +15,7 @@ config.frame_height = 7.0
|
|||||||
config.frame_width = 7.0
|
config.frame_width = 7.0
|
||||||
ROOT_DIR = Path(__file__).parents[2]
|
ROOT_DIR = Path(__file__).parents[2]
|
||||||
|
|
||||||
|
|
||||||
def make_code_snippet():
|
def make_code_snippet():
|
||||||
code_str = """
|
code_str = """
|
||||||
# Make nn
|
# Make nn
|
||||||
@ -44,6 +45,7 @@ def make_code_snippet():
|
|||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
image = Image.open(ROOT_DIR / "assets/mnist/digit.jpeg")
|
image = Image.open(ROOT_DIR / "assets/mnist/digit.jpeg")
|
||||||
|
@ -14,6 +14,7 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
|
|
||||||
def make_code_snippet():
|
def make_code_snippet():
|
||||||
code_str = """
|
code_str = """
|
||||||
# Make the neural network
|
# Make the neural network
|
||||||
@ -42,12 +43,14 @@ def make_code_snippet():
|
|||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
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=1.5),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
Convolutional2DLayer(1, 8, filter_spacing=0.32),
|
Convolutional2DLayer(1, 8, filter_spacing=0.32),
|
||||||
MaxPooling2DLayer(kernel_size=2),
|
MaxPooling2DLayer(kernel_size=2),
|
||||||
@ -67,4 +70,4 @@ class CombinedScene(ThreeDScene):
|
|||||||
# Play animation
|
# Play animation
|
||||||
forward_pass = nn.make_forward_pass_animation()
|
forward_pass = nn.make_forward_pass_animation()
|
||||||
self.wait(1)
|
self.wait(1)
|
||||||
self.play(forward_pass)
|
self.play(forward_pass)
|
||||||
|
@ -15,6 +15,7 @@ config.frame_height = 7.0
|
|||||||
config.frame_width = 7.0
|
config.frame_width = 7.0
|
||||||
ROOT_DIR = Path(__file__).parents[2]
|
ROOT_DIR = Path(__file__).parents[2]
|
||||||
|
|
||||||
|
|
||||||
def make_code_snippet():
|
def make_code_snippet():
|
||||||
code_str = """
|
code_str = """
|
||||||
# Make nn
|
# Make nn
|
||||||
|
@ -15,6 +15,7 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
|
|
||||||
def make_code_snippet():
|
def make_code_snippet():
|
||||||
code_str = """
|
code_str = """
|
||||||
# Make nn
|
# Make nn
|
||||||
@ -43,27 +44,28 @@ def make_code_snippet():
|
|||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
|
||||||
|
|
||||||
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
image = Image.open(ROOT_DIR / "assets/mnist/digit.jpeg")
|
image = Image.open(ROOT_DIR / "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=1.5),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
Convolutional2DLayer(
|
Convolutional2DLayer(
|
||||||
num_feature_maps=1,
|
num_feature_maps=1,
|
||||||
feature_map_size=6,
|
feature_map_size=6,
|
||||||
padding=1,
|
padding=1,
|
||||||
padding_dashed=True
|
padding_dashed=True,
|
||||||
),
|
),
|
||||||
Convolutional2DLayer(
|
Convolutional2DLayer(
|
||||||
num_feature_maps=3,
|
num_feature_maps=3,
|
||||||
feature_map_size=6,
|
feature_map_size=6,
|
||||||
filter_size=3,
|
filter_size=3,
|
||||||
padding=0,
|
padding=0,
|
||||||
padding_dashed=False
|
padding_dashed=False,
|
||||||
),
|
),
|
||||||
FeedForwardLayer(3),
|
FeedForwardLayer(3),
|
||||||
FeedForwardLayer(1),
|
FeedForwardLayer(1),
|
||||||
|
@ -9,6 +9,7 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
|
|
||||||
def make_code_snippet():
|
def make_code_snippet():
|
||||||
code_str = """
|
code_str = """
|
||||||
# Make the neural network
|
# Make the neural network
|
||||||
@ -37,13 +38,14 @@ def make_code_snippet():
|
|||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
class ConvScene(ThreeDScene):
|
|
||||||
|
|
||||||
|
class ConvScene(ThreeDScene):
|
||||||
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)
|
||||||
|
|
||||||
nn = NeuralNetwork({
|
nn = NeuralNetwork(
|
||||||
|
{
|
||||||
"layer1": Convolutional2DLayer(1, 5, padding=1),
|
"layer1": Convolutional2DLayer(1, 5, padding=1),
|
||||||
"layer2": Convolutional2DLayer(1, 5, 3, padding=1),
|
"layer2": Convolutional2DLayer(1, 5, 3, padding=1),
|
||||||
"layer3": Convolutional2DLayer(1, 5, 3, padding=1),
|
"layer3": Convolutional2DLayer(1, 5, 3, padding=1),
|
||||||
@ -60,7 +62,4 @@ class ConvScene(ThreeDScene):
|
|||||||
self.add(code)
|
self.add(code)
|
||||||
Group(code, nn).move_to(ORIGIN)
|
Group(code, nn).move_to(ORIGIN)
|
||||||
|
|
||||||
self.play(
|
self.play(nn.make_forward_pass_animation(), run_time=8)
|
||||||
nn.make_forward_pass_animation(),
|
|
||||||
run_time=8
|
|
||||||
)
|
|
||||||
|
@ -18,12 +18,14 @@ config.frame_width = 20.0
|
|||||||
|
|
||||||
ROOT_DIR = Path(__file__).parents[2]
|
ROOT_DIR = Path(__file__).parents[2]
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
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)
|
numpy_image = np.asarray(image)
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
ImageLayer(numpy_image, height=4.5),
|
ImageLayer(numpy_image, height=4.5),
|
||||||
Convolutional2DLayer(1, 28),
|
Convolutional2DLayer(1, 28),
|
||||||
Convolutional2DLayer(6, 28, 5),
|
Convolutional2DLayer(6, 28, 5),
|
||||||
|
@ -13,7 +13,7 @@ from manim_ml.neural_network.layers import FeedForwardLayer, EmbeddingLayer
|
|||||||
from manim_ml.neural_network.layers.util import get_connective_layer
|
from manim_ml.neural_network.layers.util import get_connective_layer
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from manim_ml.probability import GaussianDistribution
|
from manim_ml.utils.mobjects.probability import GaussianDistribution
|
||||||
|
|
||||||
# Make the specific scene
|
# Make the specific scene
|
||||||
config.pixel_height = 1200
|
config.pixel_height = 1200
|
||||||
|
@ -8,14 +8,17 @@ config.pixel_width = 1200
|
|||||||
config.frame_height = 4.0
|
config.frame_height = 4.0
|
||||||
config.frame_width = 4.0
|
config.frame_width = 4.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
FeedForwardLayer(num_nodes=3),
|
[
|
||||||
FeedForwardLayer(num_nodes=5),
|
FeedForwardLayer(num_nodes=3),
|
||||||
FeedForwardLayer(num_nodes=3)
|
FeedForwardLayer(num_nodes=5),
|
||||||
])
|
FeedForwardLayer(num_nodes=3),
|
||||||
|
]
|
||||||
|
)
|
||||||
self.add(nn)
|
self.add(nn)
|
||||||
# Center the nn
|
# Center the nn
|
||||||
nn.move_to(ORIGIN)
|
nn.move_to(ORIGIN)
|
||||||
|
@ -10,12 +10,16 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32, activation_function="ReLU"),
|
Convolutional2DLayer(
|
||||||
|
3, 5, 3, filter_spacing=0.32, activation_function="ReLU"
|
||||||
|
),
|
||||||
FeedForwardLayer(3, activation_function="Sigmoid"),
|
FeedForwardLayer(3, activation_function="Sigmoid"),
|
||||||
],
|
],
|
||||||
layer_spacing=0.25,
|
layer_spacing=0.25,
|
||||||
@ -26,4 +30,4 @@ class CombinedScene(ThreeDScene):
|
|||||||
# Play animation
|
# Play animation
|
||||||
forward_pass = nn.make_forward_pass_animation()
|
forward_pass = nn.make_forward_pass_animation()
|
||||||
self.play(ChangeSpeed(forward_pass, speedinfo={}), run_time=10)
|
self.play(ChangeSpeed(forward_pass, speedinfo={}), run_time=10)
|
||||||
self.wait(1)
|
self.wait(1)
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
|
|
||||||
from manim_ml.neural_network import Convolutional2DLayer, FeedForwardLayer, NeuralNetwork
|
from manim_ml.neural_network import (
|
||||||
|
Convolutional2DLayer,
|
||||||
|
FeedForwardLayer,
|
||||||
|
NeuralNetwork,
|
||||||
|
)
|
||||||
|
|
||||||
# Make the specific scene
|
# Make the specific scene
|
||||||
config.pixel_height = 700
|
config.pixel_height = 700
|
||||||
@ -8,10 +12,12 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 7.0
|
config.frame_height = 7.0
|
||||||
config.frame_width = 7.0
|
config.frame_width = 7.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
||||||
|
@ -2,7 +2,12 @@ from manim import *
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from manim_ml.neural_network import Convolutional2DLayer, FeedForwardLayer, NeuralNetwork, ImageLayer
|
from manim_ml.neural_network import (
|
||||||
|
Convolutional2DLayer,
|
||||||
|
FeedForwardLayer,
|
||||||
|
NeuralNetwork,
|
||||||
|
ImageLayer,
|
||||||
|
)
|
||||||
|
|
||||||
# Make the specific scene
|
# Make the specific scene
|
||||||
config.pixel_height = 700
|
config.pixel_height = 700
|
||||||
@ -10,13 +15,15 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 7.0
|
config.frame_height = 7.0
|
||||||
config.frame_width = 7.0
|
config.frame_width = 7.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
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=1.5),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
|
|
||||||
from manim_ml.neural_network import Convolutional2DLayer, FeedForwardLayer, NeuralNetwork
|
from manim_ml.neural_network import (
|
||||||
|
Convolutional2DLayer,
|
||||||
|
FeedForwardLayer,
|
||||||
|
NeuralNetwork,
|
||||||
|
)
|
||||||
|
|
||||||
# Make the specific scene
|
# Make the specific scene
|
||||||
config.pixel_height = 700
|
config.pixel_height = 700
|
||||||
@ -8,10 +12,12 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 7.0
|
config.frame_height = 7.0
|
||||||
config.frame_width = 7.0
|
config.frame_width = 7.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
|
|
||||||
from manim_ml.neural_network import Convolutional2DLayer, FeedForwardLayer, NeuralNetwork
|
from manim_ml.neural_network import (
|
||||||
|
Convolutional2DLayer,
|
||||||
|
FeedForwardLayer,
|
||||||
|
NeuralNetwork,
|
||||||
|
)
|
||||||
|
|
||||||
# Make the specific scene
|
# Make the specific scene
|
||||||
config.pixel_height = 700
|
config.pixel_height = 700
|
||||||
@ -8,10 +12,12 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 7.0
|
config.frame_height = 7.0
|
||||||
config.frame_width = 7.0
|
config.frame_width = 7.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
|
|
||||||
from manim_ml.neural_network import Convolutional2DLayer, FeedForwardLayer, NeuralNetwork
|
from manim_ml.neural_network import (
|
||||||
|
Convolutional2DLayer,
|
||||||
|
FeedForwardLayer,
|
||||||
|
NeuralNetwork,
|
||||||
|
)
|
||||||
|
|
||||||
# Make the specific scene
|
# Make the specific scene
|
||||||
config.pixel_height = 700
|
config.pixel_height = 700
|
||||||
@ -8,10 +12,12 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 7.0
|
config.frame_height = 7.0
|
||||||
config.frame_width = 7.0
|
config.frame_width = 7.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
||||||
|
@ -12,11 +12,12 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
class MaxPoolingScene(ThreeDScene):
|
|
||||||
|
|
||||||
|
class MaxPoolingScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
Convolutional2DLayer(1, 8),
|
Convolutional2DLayer(1, 8),
|
||||||
Convolutional2DLayer(3, 6, 3),
|
Convolutional2DLayer(3, 6, 3),
|
||||||
MaxPooling2DLayer(kernel_size=2),
|
MaxPooling2DLayer(kernel_size=2),
|
||||||
@ -30,4 +31,4 @@ class MaxPoolingScene(ThreeDScene):
|
|||||||
# Play animation
|
# Play animation
|
||||||
forward_pass = nn.make_forward_pass_animation()
|
forward_pass = nn.make_forward_pass_animation()
|
||||||
self.play(ChangeSpeed(forward_pass, speedinfo={}), run_time=10)
|
self.play(ChangeSpeed(forward_pass, speedinfo={}), run_time=10)
|
||||||
self.wait(1)
|
self.wait(1)
|
||||||
|
@ -9,11 +9,12 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 5.0
|
config.frame_height = 5.0
|
||||||
config.frame_width = 5.0
|
config.frame_width = 5.0
|
||||||
|
|
||||||
|
|
||||||
class DropoutNeuralNetworkScene(Scene):
|
class DropoutNeuralNetworkScene(Scene):
|
||||||
|
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
FeedForwardLayer(3, rectangle_color=BLUE),
|
FeedForwardLayer(3, rectangle_color=BLUE),
|
||||||
FeedForwardLayer(5, rectangle_color=BLUE),
|
FeedForwardLayer(5, rectangle_color=BLUE),
|
||||||
FeedForwardLayer(3, rectangle_color=BLUE),
|
FeedForwardLayer(3, rectangle_color=BLUE),
|
||||||
@ -31,4 +32,4 @@ class DropoutNeuralNetworkScene(Scene):
|
|||||||
nn, dropout_rate=0.25, do_forward_pass=True
|
nn, dropout_rate=0.25, do_forward_pass=True
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.wait(1)
|
self.wait(1)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from manim_ml.neural_network.layers.convolutional_2d import Convolutional2DLayer
|
from manim_ml.neural_network.layers.convolutional_2d import Convolutional2DLayer
|
||||||
@ -6,11 +6,12 @@ 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
|
||||||
|
|
||||||
class ConvolutionalNetworkScene(Scene):
|
|
||||||
|
|
||||||
|
class ConvolutionalNetworkScene(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
|
||||||
@ -22,4 +23,4 @@ class ConvolutionalNetworkScene(Scene):
|
|||||||
# Center the nn
|
# Center the nn
|
||||||
nn.move_to(ORIGIN)
|
nn.move_to(ORIGIN)
|
||||||
self.add(nn)
|
self.add(nn)
|
||||||
self.play(nn.make_forward_pass_animation())
|
self.play(nn.make_forward_pass_animation())
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
|
|
||||||
# Import modules here
|
# Import modules here
|
||||||
|
|
||||||
class BasicScene(ThreeDScene):
|
|
||||||
|
|
||||||
|
class BasicScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Your code goes here
|
# Your code goes here
|
||||||
text = Text("Your first scene!")
|
text = Text("Your first scene!")
|
||||||
self.add(text)
|
self.add(text)
|
||||||
|
@ -7,7 +7,7 @@ import scipy
|
|||||||
import scipy.stats
|
import scipy.stats
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from manim_ml.probability import GaussianDistribution
|
from manim_ml.utils.mobjects.probability import GaussianDistribution
|
||||||
|
|
||||||
|
|
||||||
def gaussian_proposal(x, sigma=0.2):
|
def gaussian_proposal(x, sigma=0.2):
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
"""
|
|
||||||
Animated flow charts.
|
|
||||||
"""
|
|
||||||
from manim import *
|
|
||||||
|
|
||||||
|
|
||||||
class FlowGraph(VGroup):
|
|
||||||
"""Graph container"""
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class FlowNode(VGroup):
|
|
||||||
"""Node in the FlowGraph"""
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class DataNode(FlowNode):
|
|
||||||
"""Node that outputs data"""
|
|
||||||
|
|
||||||
pass
|
|
@ -1,13 +0,0 @@
|
|||||||
from manim import *
|
|
||||||
|
|
||||||
|
|
||||||
class LazyAnimation(Animation):
|
|
||||||
def __init__(self, animation_function):
|
|
||||||
self.animation_function = animation_function
|
|
||||||
super.__init__()
|
|
||||||
|
|
||||||
def begin(self):
|
|
||||||
update_func_anim = UpdateFromFunc(self.neural_network, create_new_connective)
|
|
||||||
self.add
|
|
||||||
|
|
||||||
super.begin()
|
|
@ -1,3 +0,0 @@
|
|||||||
"""
|
|
||||||
Visaulization of a latent Manifold
|
|
||||||
"""
|
|
@ -1,23 +1,41 @@
|
|||||||
from manim_ml.neural_network.neural_network import NeuralNetwork
|
from manim_ml.neural_network.neural_network import NeuralNetwork
|
||||||
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.convolutional_2d_to_convolutional_2d import Convolutional2DToConvolutional2D
|
from manim_ml.neural_network.layers.convolutional_2d_to_convolutional_2d import (
|
||||||
from manim_ml.neural_network.layers.convolutional_2d_to_feed_forward import Convolutional2DToFeedForward
|
Convolutional2DToConvolutional2D,
|
||||||
from manim_ml.neural_network.layers.convolutional_2d_to_max_pooling_2d import Convolutional2DToMaxPooling2D
|
)
|
||||||
|
from manim_ml.neural_network.layers.convolutional_2d_to_feed_forward import (
|
||||||
|
Convolutional2DToFeedForward,
|
||||||
|
)
|
||||||
|
from manim_ml.neural_network.layers.convolutional_2d_to_max_pooling_2d import (
|
||||||
|
Convolutional2DToMaxPooling2D,
|
||||||
|
)
|
||||||
from manim_ml.neural_network.layers.convolutional_2d import Convolutional2DLayer
|
from manim_ml.neural_network.layers.convolutional_2d import Convolutional2DLayer
|
||||||
from manim_ml.neural_network.layers.embedding_to_feed_forward import EmbeddingToFeedForward
|
from manim_ml.neural_network.layers.embedding_to_feed_forward import (
|
||||||
|
EmbeddingToFeedForward,
|
||||||
|
)
|
||||||
from manim_ml.neural_network.layers.embedding import EmbeddingLayer
|
from manim_ml.neural_network.layers.embedding import EmbeddingLayer
|
||||||
from manim_ml.neural_network.layers.feed_forward_to_embedding import FeedForwardToEmbedding
|
from manim_ml.neural_network.layers.feed_forward_to_embedding import (
|
||||||
from manim_ml.neural_network.layers.feed_forward_to_feed_forward import FeedForwardToFeedForward
|
FeedForwardToEmbedding,
|
||||||
|
)
|
||||||
|
from manim_ml.neural_network.layers.feed_forward_to_feed_forward import (
|
||||||
|
FeedForwardToFeedForward,
|
||||||
|
)
|
||||||
from manim_ml.neural_network.layers.feed_forward_to_image import FeedForwardToImage
|
from manim_ml.neural_network.layers.feed_forward_to_image import FeedForwardToImage
|
||||||
from manim_ml.neural_network.layers.feed_forward_to_vector import FeedForwardToVector
|
from manim_ml.neural_network.layers.feed_forward_to_vector import FeedForwardToVector
|
||||||
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_to_convolutional_2d import ImageToConvolutional2DLayer
|
from manim_ml.neural_network.layers.image_to_convolutional_2d import (
|
||||||
|
ImageToConvolutional2DLayer,
|
||||||
|
)
|
||||||
from manim_ml.neural_network.layers.image_to_feed_forward import ImageToFeedForward
|
from manim_ml.neural_network.layers.image_to_feed_forward import ImageToFeedForward
|
||||||
from manim_ml.neural_network.layers.image import ImageLayer
|
from manim_ml.neural_network.layers.image import ImageLayer
|
||||||
from manim_ml.neural_network.layers.max_pooling_2d_to_convolutional_2d import MaxPooling2DToConvolutional2D
|
from manim_ml.neural_network.layers.max_pooling_2d_to_convolutional_2d import (
|
||||||
|
MaxPooling2DToConvolutional2D,
|
||||||
|
)
|
||||||
from manim_ml.neural_network.layers.max_pooling_2d import MaxPooling2DLayer
|
from manim_ml.neural_network.layers.max_pooling_2d import MaxPooling2DLayer
|
||||||
from manim_ml.neural_network.layers.paired_query_to_feed_forward import PairedQueryToFeedForward
|
from manim_ml.neural_network.layers.paired_query_to_feed_forward import (
|
||||||
|
PairedQueryToFeedForward,
|
||||||
|
)
|
||||||
from manim_ml.neural_network.layers.paired_query import PairedQueryLayer
|
from manim_ml.neural_network.layers.paired_query import PairedQueryLayer
|
||||||
from manim_ml.neural_network.layers.triplet_to_feed_forward import TripletToFeedForward
|
from manim_ml.neural_network.layers.triplet_to_feed_forward import TripletToFeedForward
|
||||||
from manim_ml.neural_network.layers.triplet import TripletLayer
|
from manim_ml.neural_network.layers.triplet import TripletLayer
|
||||||
from manim_ml.neural_network.layers.vector import VectorLayer
|
from manim_ml.neural_network.layers.vector import VectorLayer
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
from manim_ml.neural_network.activation_functions.relu import ReLUFunction
|
from manim_ml.neural_network.activation_functions.relu import ReLUFunction
|
||||||
from manim_ml.neural_network.activation_functions.sigmoid import SigmoidFunction
|
from manim_ml.neural_network.activation_functions.sigmoid import SigmoidFunction
|
||||||
|
|
||||||
name_to_activation_function_map = {
|
name_to_activation_function_map = {"ReLU": ReLUFunction, "Sigmoid": SigmoidFunction}
|
||||||
"ReLU": ReLUFunction,
|
|
||||||
"Sigmoid": SigmoidFunction
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_activation_function_by_name(name):
|
def get_activation_function_by_name(name):
|
||||||
assert name in name_to_activation_function_map.keys(), \
|
assert (
|
||||||
f"Unrecognized activation function {name}"
|
name in name_to_activation_function_map.keys()
|
||||||
|
), f"Unrecognized activation function {name}"
|
||||||
|
|
||||||
return name_to_activation_function_map[name]
|
return name_to_activation_function_map[name]
|
||||||
|
@ -4,6 +4,7 @@ import random
|
|||||||
|
|
||||||
import manim_ml.neural_network.activation_functions.relu as relu
|
import manim_ml.neural_network.activation_functions.relu as relu
|
||||||
|
|
||||||
|
|
||||||
class ActivationFunction(ABC, VGroup):
|
class ActivationFunction(ABC, VGroup):
|
||||||
"""Abstract parent class for defining activation functions"""
|
"""Abstract parent class for defining activation functions"""
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from manim_ml.neural_network.activation_functions.activation_function import (
|
|||||||
ActivationFunction,
|
ActivationFunction,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SigmoidFunction(ActivationFunction):
|
class SigmoidFunction(ActivationFunction):
|
||||||
"""Sigmoid Activation Function"""
|
"""Sigmoid Activation Function"""
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from manim_ml.neural_network.layers.feed_forward import FeedForwardLayer
|
from manim_ml.neural_network.layers.feed_forward import FeedForwardLayer
|
||||||
|
|
||||||
|
|
||||||
class FeedForwardNeuralNetwork(NeuralNetwork):
|
class FeedForwardNeuralNetwork(NeuralNetwork):
|
||||||
"""NeuralNetwork with just feed forward layers"""
|
"""NeuralNetwork with just feed forward layers"""
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@ from manim_ml.neural_network.layers.image_to_convolutional_2d import (
|
|||||||
from manim_ml.neural_network.layers.max_pooling_2d_to_convolutional_2d import (
|
from manim_ml.neural_network.layers.max_pooling_2d_to_convolutional_2d import (
|
||||||
MaxPooling2DToConvolutional2D,
|
MaxPooling2DToConvolutional2D,
|
||||||
)
|
)
|
||||||
from manim_ml.neural_network.layers.max_pooling_2d_to_feed_forward import MaxPooling2DToFeedForward
|
from manim_ml.neural_network.layers.max_pooling_2d_to_feed_forward import (
|
||||||
|
MaxPooling2DToFeedForward,
|
||||||
|
)
|
||||||
from .convolutional_2d_to_convolutional_2d import Convolutional2DToConvolutional2D
|
from .convolutional_2d_to_convolutional_2d import Convolutional2DToConvolutional2D
|
||||||
from .convolutional_2d import Convolutional2DLayer
|
from .convolutional_2d import Convolutional2DLayer
|
||||||
from .feed_forward_to_vector import FeedForwardToVector
|
from .feed_forward_to_vector import FeedForwardToVector
|
||||||
|
@ -10,7 +10,8 @@ from manim_ml.neural_network.layers.parent_layers import (
|
|||||||
ThreeDLayer,
|
ThreeDLayer,
|
||||||
VGroupNeuralNetworkLayer,
|
VGroupNeuralNetworkLayer,
|
||||||
)
|
)
|
||||||
from manim_ml.gridded_rectangle import GriddedRectangle
|
from manim_ml.utils.mobjects.gridded_rectangle import GriddedRectangle
|
||||||
|
|
||||||
|
|
||||||
class FeatureMap(VGroup):
|
class FeatureMap(VGroup):
|
||||||
"""Class for making a feature map"""
|
"""Class for making a feature map"""
|
||||||
@ -25,7 +26,7 @@ class FeatureMap(VGroup):
|
|||||||
padding=(0, 0),
|
padding=(0, 0),
|
||||||
stroke_width=2.0,
|
stroke_width=2.0,
|
||||||
show_grid_lines=False,
|
show_grid_lines=False,
|
||||||
padding_dashed=False
|
padding_dashed=False,
|
||||||
):
|
):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.color = color
|
self.color = color
|
||||||
@ -40,8 +41,12 @@ class FeatureMap(VGroup):
|
|||||||
# Check if we have non-zero padding
|
# Check if we have non-zero padding
|
||||||
if padding[0] > 0 or padding[1] > 0:
|
if padding[0] > 0 or padding[1] > 0:
|
||||||
# Make the exterior rectangle dashed
|
# Make the exterior rectangle dashed
|
||||||
width_with_padding = (self.feature_map_size[0] + self.padding[0] * 2) * self.cell_width
|
width_with_padding = (
|
||||||
height_with_padding = (self.feature_map_size[1] + self.padding[1] * 2) * self.cell_width
|
self.feature_map_size[0] + self.padding[0] * 2
|
||||||
|
) * self.cell_width
|
||||||
|
height_with_padding = (
|
||||||
|
self.feature_map_size[1] + self.padding[1] * 2
|
||||||
|
) * self.cell_width
|
||||||
self.untransformed_width = width_with_padding
|
self.untransformed_width = width_with_padding
|
||||||
self.untransformed_height = height_with_padding
|
self.untransformed_height = height_with_padding
|
||||||
|
|
||||||
@ -58,7 +63,7 @@ class FeatureMap(VGroup):
|
|||||||
grid_stroke_width=self.stroke_width / 2,
|
grid_stroke_width=self.stroke_width / 2,
|
||||||
grid_stroke_color=self.color,
|
grid_stroke_color=self.color,
|
||||||
show_grid_lines=self.show_grid_lines,
|
show_grid_lines=self.show_grid_lines,
|
||||||
dotted_lines=self.padding_dashed
|
dotted_lines=self.padding_dashed,
|
||||||
)
|
)
|
||||||
self.add(self.exterior_rectangle)
|
self.add(self.exterior_rectangle)
|
||||||
# Add an interior rectangle with no fill color
|
# Add an interior rectangle with no fill color
|
||||||
@ -67,13 +72,13 @@ class FeatureMap(VGroup):
|
|||||||
fill_opacity=0.0,
|
fill_opacity=0.0,
|
||||||
width=self.feature_map_size[0] * self.cell_width,
|
width=self.feature_map_size[0] * self.cell_width,
|
||||||
height=self.feature_map_size[1] * self.cell_width,
|
height=self.feature_map_size[1] * self.cell_width,
|
||||||
stroke_width=self.stroke_width
|
stroke_width=self.stroke_width,
|
||||||
)
|
)
|
||||||
self.add(self.interior_rectangle)
|
self.add(self.interior_rectangle)
|
||||||
else:
|
else:
|
||||||
# Just make an exterior rectangle with no dashes.
|
# Just make an exterior rectangle with no dashes.
|
||||||
self.untransformed_height = self.feature_map_size[1] * self.cell_width,
|
self.untransformed_height = (self.feature_map_size[1] * self.cell_width,)
|
||||||
self.untransformed_width = self.feature_map_size[0] * self.cell_width,
|
self.untransformed_width = (self.feature_map_size[0] * self.cell_width,)
|
||||||
# Make the exterior rectangle
|
# Make the exterior rectangle
|
||||||
self.exterior_rectangle = GriddedRectangle(
|
self.exterior_rectangle = GriddedRectangle(
|
||||||
color=self.color,
|
color=self.color,
|
||||||
@ -96,6 +101,7 @@ class FeatureMap(VGroup):
|
|||||||
# Sort points through clockwise rotation of a vector in the xy plane
|
# Sort points through clockwise rotation of a vector in the xy plane
|
||||||
return self.exterior_rectangle.get_corners_dict()
|
return self.exterior_rectangle.get_corners_dict()
|
||||||
|
|
||||||
|
|
||||||
class Convolutional2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
|
class Convolutional2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
|
||||||
"""Handles rendering a convolutional layer for a nn"""
|
"""Handles rendering a convolutional layer for a nn"""
|
||||||
|
|
||||||
@ -215,7 +221,7 @@ class Convolutional2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
|
|||||||
fill_color=self.color,
|
fill_color=self.color,
|
||||||
fill_opacity=self.fill_opacity,
|
fill_opacity=self.fill_opacity,
|
||||||
padding=self.padding,
|
padding=self.padding,
|
||||||
padding_dashed=self.padding_dashed
|
padding_dashed=self.padding_dashed,
|
||||||
)
|
)
|
||||||
# Move the feature map
|
# Move the feature map
|
||||||
feature_map.move_to([0, 0, filter_index * self.filter_spacing])
|
feature_map.move_to([0, 0, filter_index * self.filter_spacing])
|
||||||
@ -231,9 +237,7 @@ class Convolutional2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
|
|||||||
ApplyMethod(self.feature_maps.set_color, self.color),
|
ApplyMethod(self.feature_maps.set_color, self.color),
|
||||||
)
|
)
|
||||||
|
|
||||||
def make_forward_pass_animation(
|
def make_forward_pass_animation(self, run_time=5, layer_args={}, **kwargs):
|
||||||
self, run_time=5, layer_args={}, **kwargs
|
|
||||||
):
|
|
||||||
"""Convolution forward pass animation"""
|
"""Convolution forward pass animation"""
|
||||||
# Note: most of this animation is done in the Convolution3DToConvolution3D layer
|
# Note: most of this animation is done in the Convolution3DToConvolution3D layer
|
||||||
if not self.activation_function is None:
|
if not self.activation_function is None:
|
||||||
|
@ -3,10 +3,11 @@ import numpy as np
|
|||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.neural_network.layers.convolutional_2d import Convolutional2DLayer
|
from manim_ml.neural_network.layers.convolutional_2d import Convolutional2DLayer
|
||||||
from manim_ml.neural_network.layers.parent_layers import ConnectiveLayer, ThreeDLayer
|
from manim_ml.neural_network.layers.parent_layers import ConnectiveLayer, ThreeDLayer
|
||||||
from manim_ml.gridded_rectangle import GriddedRectangle
|
from manim_ml.utils.mobjects.gridded_rectangle import GriddedRectangle
|
||||||
|
|
||||||
from manim.utils.space_ops import rotation_matrix
|
from manim.utils.space_ops import rotation_matrix
|
||||||
|
|
||||||
|
|
||||||
def get_rotated_shift_vectors(input_layer, normalized=False):
|
def get_rotated_shift_vectors(input_layer, normalized=False):
|
||||||
"""Rotates the shift vectors"""
|
"""Rotates the shift vectors"""
|
||||||
# Make base shift vectors
|
# Make base shift vectors
|
||||||
@ -24,6 +25,7 @@ def get_rotated_shift_vectors(input_layer, normalized=False):
|
|||||||
|
|
||||||
return right_shift, down_shift
|
return right_shift, down_shift
|
||||||
|
|
||||||
|
|
||||||
class Filters(VGroup):
|
class Filters(VGroup):
|
||||||
"""Group for showing a collection of filters connecting two layers"""
|
"""Group for showing a collection of filters connecting two layers"""
|
||||||
|
|
||||||
@ -144,7 +146,7 @@ class Filters(VGroup):
|
|||||||
)
|
)
|
||||||
# Shift based on the amount of output layer padding
|
# Shift based on the amount of output layer padding
|
||||||
rectangle.shift(
|
rectangle.shift(
|
||||||
self.output_layer.padding[0] * right_shift,
|
self.output_layer.padding[0] * right_shift,
|
||||||
)
|
)
|
||||||
rectangle.shift(
|
rectangle.shift(
|
||||||
self.output_layer.padding[1] * down_shift,
|
self.output_layer.padding[1] * down_shift,
|
||||||
@ -446,10 +448,7 @@ class Convolutional2DToConvolutional2D(ConnectiveLayer, ThreeDLayer):
|
|||||||
# Do last row move right
|
# Do last row move right
|
||||||
for x_move in range(num_x_moves):
|
for x_move in range(num_x_moves):
|
||||||
# Shift right
|
# Shift right
|
||||||
shift_animation = ApplyMethod(
|
shift_animation = ApplyMethod(filters.shift, self.stride * right_shift)
|
||||||
filters.shift,
|
|
||||||
self.stride * right_shift
|
|
||||||
)
|
|
||||||
# shift_animation = self.animate.shift(right_shift)
|
# shift_animation = self.animate.shift(right_shift)
|
||||||
animations.append(shift_animation)
|
animations.append(shift_animation)
|
||||||
# Remove the filters
|
# Remove the filters
|
||||||
@ -460,18 +459,14 @@ class Convolutional2DToConvolutional2D(ConnectiveLayer, ThreeDLayer):
|
|||||||
# Change the output feature map colors
|
# Change the output feature map colors
|
||||||
change_color_animations = []
|
change_color_animations = []
|
||||||
change_color_animations.append(
|
change_color_animations.append(
|
||||||
ApplyMethod(
|
ApplyMethod(feature_map.set_color, original_feature_map_color)
|
||||||
feature_map.set_color,
|
|
||||||
original_feature_map_color
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
# Change the input feature map colors
|
# Change the input feature map colors
|
||||||
input_feature_maps = self.input_layer.feature_maps
|
input_feature_maps = self.input_layer.feature_maps
|
||||||
for input_feature_map in input_feature_maps:
|
for input_feature_map in input_feature_maps:
|
||||||
change_color_animations.append(
|
change_color_animations.append(
|
||||||
ApplyMethod(
|
ApplyMethod(
|
||||||
input_feature_map.set_color,
|
input_feature_map.set_color, original_feature_map_color
|
||||||
original_feature_map_color
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# Combine the animations
|
# Combine the animations
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import random
|
import random
|
||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.gridded_rectangle import GriddedRectangle
|
from manim_ml.utils.mobjects.gridded_rectangle import GriddedRectangle
|
||||||
from manim_ml.neural_network.layers.convolutional_2d_to_convolutional_2d import (
|
from manim_ml.neural_network.layers.convolutional_2d_to_convolutional_2d import (
|
||||||
get_rotated_shift_vectors,
|
get_rotated_shift_vectors,
|
||||||
)
|
)
|
||||||
@ -10,6 +10,7 @@ from manim_ml.neural_network.layers.parent_layers import ConnectiveLayer, ThreeD
|
|||||||
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.convolutional_2d import Convolutional2DLayer
|
from manim_ml.neural_network.layers.convolutional_2d import Convolutional2DLayer
|
||||||
|
|
||||||
|
|
||||||
class Uncreate(Create):
|
class Uncreate(Create):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -27,6 +28,7 @@ class Uncreate(Create):
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Convolutional2DToMaxPooling2D(ConnectiveLayer, ThreeDLayer):
|
class Convolutional2DToMaxPooling2D(ConnectiveLayer, ThreeDLayer):
|
||||||
"""Feed Forward to Embedding Layer"""
|
"""Feed Forward to Embedding Layer"""
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ class Convolutional2DToMaxPooling2D(ConnectiveLayer, ThreeDLayer):
|
|||||||
input_layer: Convolutional2DLayer,
|
input_layer: Convolutional2DLayer,
|
||||||
output_layer: MaxPooling2DLayer,
|
output_layer: MaxPooling2DLayer,
|
||||||
active_color=ORANGE,
|
active_color=ORANGE,
|
||||||
**kwargs
|
**kwargs,
|
||||||
):
|
):
|
||||||
super().__init__(input_layer, output_layer, **kwargs)
|
super().__init__(input_layer, output_layer, **kwargs)
|
||||||
self.active_color = active_color
|
self.active_color = active_color
|
||||||
@ -47,7 +49,7 @@ class Convolutional2DToMaxPooling2D(ConnectiveLayer, ThreeDLayer):
|
|||||||
self,
|
self,
|
||||||
input_layer: "NeuralNetworkLayer",
|
input_layer: "NeuralNetworkLayer",
|
||||||
output_layer: "NeuralNetworkLayer",
|
output_layer: "NeuralNetworkLayer",
|
||||||
**kwargs
|
**kwargs,
|
||||||
):
|
):
|
||||||
return super().construct_layer(input_layer, output_layer, **kwargs)
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
@ -94,7 +96,7 @@ class Convolutional2DToMaxPooling2D(ConnectiveLayer, ThreeDLayer):
|
|||||||
width=cell_width,
|
width=cell_width,
|
||||||
fill_opacity=0.7,
|
fill_opacity=0.7,
|
||||||
stroke_width=0.0,
|
stroke_width=0.0,
|
||||||
z_index=10
|
z_index=10,
|
||||||
)
|
)
|
||||||
# Move to the correct location
|
# Move to the correct location
|
||||||
kernel_shift_vector = [
|
kernel_shift_vector = [
|
||||||
@ -119,10 +121,7 @@ class Convolutional2DToMaxPooling2D(ConnectiveLayer, ThreeDLayer):
|
|||||||
highlighted_cells.append(cell_rectangle)
|
highlighted_cells.append(cell_rectangle)
|
||||||
# Rotate the gridded rectangles so they match the angle
|
# Rotate the gridded rectangles so they match the angle
|
||||||
# of the conv maps
|
# of the conv maps
|
||||||
gridded_rectangle_group = VGroup(
|
gridded_rectangle_group = VGroup(gridded_rectangle, *highlighted_cells)
|
||||||
gridded_rectangle,
|
|
||||||
*highlighted_cells
|
|
||||||
)
|
|
||||||
gridded_rectangle_group.rotate(
|
gridded_rectangle_group.rotate(
|
||||||
ThreeDLayer.rotation_angle,
|
ThreeDLayer.rotation_angle,
|
||||||
about_point=gridded_rectangle.get_center(),
|
about_point=gridded_rectangle.get_center(),
|
||||||
@ -137,26 +136,20 @@ class Convolutional2DToMaxPooling2D(ConnectiveLayer, ThreeDLayer):
|
|||||||
create_rectangle = Create(
|
create_rectangle = Create(
|
||||||
gridded_rectangle,
|
gridded_rectangle,
|
||||||
)
|
)
|
||||||
create_gridded_rectangle_animations.append(
|
create_gridded_rectangle_animations.append(create_rectangle)
|
||||||
create_rectangle
|
|
||||||
)
|
|
||||||
# 4. Create and fade out highlighted cells
|
# 4. Create and fade out highlighted cells
|
||||||
create_group = AnimationGroup(
|
create_group = AnimationGroup(
|
||||||
*[Create(highlighted_cell) for highlighted_cell in highlighted_cells],
|
*[Create(highlighted_cell) for highlighted_cell in highlighted_cells],
|
||||||
lag_ratio=1.0
|
lag_ratio=1.0,
|
||||||
)
|
)
|
||||||
uncreate_group = AnimationGroup(
|
uncreate_group = AnimationGroup(
|
||||||
*[Uncreate(highlighted_cell) for highlighted_cell in highlighted_cells],
|
*[Uncreate(highlighted_cell) for highlighted_cell in highlighted_cells],
|
||||||
lag_ratio=0.0
|
lag_ratio=0.0,
|
||||||
)
|
)
|
||||||
create_and_remove_cell_animation = Succession(
|
create_and_remove_cell_animation = Succession(
|
||||||
create_group,
|
create_group, Wait(1.0), uncreate_group
|
||||||
Wait(1.0),
|
|
||||||
uncreate_group
|
|
||||||
)
|
|
||||||
create_and_remove_cell_animations.append(
|
|
||||||
create_and_remove_cell_animation
|
|
||||||
)
|
)
|
||||||
|
create_and_remove_cell_animations.append(create_and_remove_cell_animation)
|
||||||
# 5. Move and resize the gridded rectangle to the output
|
# 5. Move and resize the gridded rectangle to the output
|
||||||
# feature maps.
|
# feature maps.
|
||||||
output_gridded_rectangle = GriddedRectangle(
|
output_gridded_rectangle = GriddedRectangle(
|
||||||
@ -178,9 +171,10 @@ class Convolutional2DToMaxPooling2D(ConnectiveLayer, ThreeDLayer):
|
|||||||
self.output_layer.feature_maps[feature_map_index].copy()
|
self.output_layer.feature_maps[feature_map_index].copy()
|
||||||
)
|
)
|
||||||
transform_rectangle = ReplacementTransform(
|
transform_rectangle = ReplacementTransform(
|
||||||
gridded_rectangle, output_gridded_rectangle,
|
gridded_rectangle,
|
||||||
|
output_gridded_rectangle,
|
||||||
introducer=True,
|
introducer=True,
|
||||||
remover=True
|
remover=True,
|
||||||
)
|
)
|
||||||
transform_gridded_rectangle_animations.append(
|
transform_gridded_rectangle_animations.append(
|
||||||
transform_rectangle,
|
transform_rectangle,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.probability import GaussianDistribution
|
from manim_ml.utils.mobjects.probability import GaussianDistribution
|
||||||
from manim_ml.neural_network.layers.parent_layers import VGroupNeuralNetworkLayer
|
from manim_ml.neural_network.layers.parent_layers import VGroupNeuralNetworkLayer
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
|
|
||||||
from manim_ml.neural_network.activation_functions import get_activation_function_by_name
|
from manim_ml.neural_network.activation_functions import get_activation_function_by_name
|
||||||
from manim_ml.neural_network.activation_functions.activation_function import ActivationFunction
|
from manim_ml.neural_network.activation_functions.activation_function import (
|
||||||
|
ActivationFunction,
|
||||||
|
)
|
||||||
from manim_ml.neural_network.layers.parent_layers import VGroupNeuralNetworkLayer
|
from manim_ml.neural_network.layers.parent_layers import VGroupNeuralNetworkLayer
|
||||||
|
|
||||||
|
|
||||||
class FeedForwardLayer(VGroupNeuralNetworkLayer):
|
class FeedForwardLayer(VGroupNeuralNetworkLayer):
|
||||||
"""Handles rendering a layer for a neural network"""
|
"""Handles rendering a layer for a neural network"""
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from manim_ml.image import GrayscaleImageMobject
|
from manim_ml.utils.mobjects.image import GrayscaleImageMobject
|
||||||
from manim_ml.neural_network.layers.parent_layers import NeuralNetworkLayer
|
from manim_ml.neural_network.layers.parent_layers import NeuralNetworkLayer
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
@ -7,7 +7,7 @@ from manim_ml.neural_network.layers.parent_layers import (
|
|||||||
ThreeDLayer,
|
ThreeDLayer,
|
||||||
VGroupNeuralNetworkLayer,
|
VGroupNeuralNetworkLayer,
|
||||||
)
|
)
|
||||||
from manim_ml.gridded_rectangle import GriddedRectangle
|
from manim_ml.utils.mobjects.gridded_rectangle import GriddedRectangle
|
||||||
|
|
||||||
|
|
||||||
class ImageToConvolutional2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
|
class ImageToConvolutional2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.gridded_rectangle import GriddedRectangle
|
from manim_ml.utils.mobjects.gridded_rectangle import GriddedRectangle
|
||||||
|
|
||||||
from manim_ml.neural_network.layers.parent_layers import (
|
from manim_ml.neural_network.layers.parent_layers import (
|
||||||
ThreeDLayer,
|
ThreeDLayer,
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.neural_network.layers.convolutional_2d_to_feed_forward import Convolutional2DToFeedForward
|
from manim_ml.neural_network.layers.convolutional_2d_to_feed_forward import (
|
||||||
|
Convolutional2DToFeedForward,
|
||||||
|
)
|
||||||
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.max_pooling_2d import MaxPooling2DLayer
|
from manim_ml.neural_network.layers.max_pooling_2d import MaxPooling2DLayer
|
||||||
|
|
||||||
|
|
||||||
class MaxPooling2DToFeedForward(Convolutional2DToFeedForward):
|
class MaxPooling2DToFeedForward(Convolutional2DToFeedForward):
|
||||||
"""Feed Forward to Embedding Layer"""
|
"""Feed Forward to Embedding Layer"""
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.neural_network.layers.parent_layers import NeuralNetworkLayer
|
from manim_ml.neural_network.layers.parent_layers import NeuralNetworkLayer
|
||||||
from manim_ml.image import GrayscaleImageMobject, LabeledColorImage
|
from manim_ml.utils.mobjects.image import GrayscaleImageMobject, LabeledColorImage
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.neural_network.layers import NeuralNetworkLayer
|
from manim_ml.neural_network.layers import NeuralNetworkLayer
|
||||||
from manim_ml.image import GrayscaleImageMobject, LabeledColorImage
|
from manim_ml.utils.mobjects.image import GrayscaleImageMobject, LabeledColorImage
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ from manim import *
|
|||||||
from manim_ml.neural_network.layers.parent_layers import BlankConnective, ThreeDLayer
|
from manim_ml.neural_network.layers.parent_layers import BlankConnective, ThreeDLayer
|
||||||
from manim_ml.neural_network.layers import connective_layers_list
|
from manim_ml.neural_network.layers import connective_layers_list
|
||||||
|
|
||||||
|
|
||||||
def get_connective_layer(input_layer, output_layer):
|
def get_connective_layer(input_layer, output_layer):
|
||||||
"""
|
"""
|
||||||
Deduces the relevant connective layer
|
Deduces the relevant connective layer
|
||||||
@ -12,8 +13,9 @@ def get_connective_layer(input_layer, output_layer):
|
|||||||
for candidate_class in connective_layers_list:
|
for candidate_class in connective_layers_list:
|
||||||
input_class = candidate_class.input_class
|
input_class = candidate_class.input_class
|
||||||
output_class = candidate_class.output_class
|
output_class = candidate_class.output_class
|
||||||
if isinstance(input_layer, input_class) and \
|
if isinstance(input_layer, input_class) and isinstance(
|
||||||
isinstance(output_layer, output_class):
|
output_layer, output_class
|
||||||
|
):
|
||||||
connective_layer_class = candidate_class
|
connective_layer_class = candidate_class
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -17,12 +17,13 @@ from manim import *
|
|||||||
|
|
||||||
from manim_ml.neural_network.layers.parent_layers import ConnectiveLayer, ThreeDLayer
|
from manim_ml.neural_network.layers.parent_layers import ConnectiveLayer, ThreeDLayer
|
||||||
from manim_ml.neural_network.layers.util import get_connective_layer
|
from manim_ml.neural_network.layers.util import get_connective_layer
|
||||||
from manim_ml.list_group import ListGroup
|
from manim_ml.utils.mobjects.list_group import ListGroup
|
||||||
from manim_ml.neural_network.neural_network_transformations import (
|
from manim_ml.neural_network.animations.neural_network_transformations import (
|
||||||
InsertLayer,
|
InsertLayer,
|
||||||
RemoveLayer,
|
RemoveLayer,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NeuralNetwork(Group):
|
class NeuralNetwork(Group):
|
||||||
"""Neural Network Visualization Container Class"""
|
"""Neural Network Visualization Container Class"""
|
||||||
|
|
||||||
@ -59,10 +60,7 @@ class NeuralNetwork(Group):
|
|||||||
# Make the connective layers
|
# Make the connective layers
|
||||||
self.connective_layers, self.all_layers = self._construct_connective_layers()
|
self.connective_layers, self.all_layers = self._construct_connective_layers()
|
||||||
# Make overhead title
|
# Make overhead title
|
||||||
self.title = Text(
|
self.title = Text(self.title_text, font_size=DEFAULT_FONT_SIZE / 2)
|
||||||
self.title_text,
|
|
||||||
font_size=DEFAULT_FONT_SIZE / 2
|
|
||||||
)
|
|
||||||
self.title.next_to(self, UP, 1.0)
|
self.title.next_to(self, UP, 1.0)
|
||||||
self.add(self.title)
|
self.add(self.title)
|
||||||
# Place layers at correct z index
|
# Place layers at correct z index
|
||||||
@ -92,11 +90,11 @@ class NeuralNetwork(Group):
|
|||||||
raise Exception(f"Uncrecognized input layers type: {type(input_layers)}")
|
raise Exception(f"Uncrecognized input layers type: {type(input_layers)}")
|
||||||
|
|
||||||
def add_connection(
|
def add_connection(
|
||||||
self,
|
self,
|
||||||
start_layer_name,
|
start_layer_name,
|
||||||
end_layer_name,
|
end_layer_name,
|
||||||
connection_style="default",
|
connection_style="default",
|
||||||
connection_position="bottom"
|
connection_position="bottom",
|
||||||
):
|
):
|
||||||
"""Add connection from start layer to end layer"""
|
"""Add connection from start layer to end layer"""
|
||||||
assert connection_style in ["default"]
|
assert connection_style in ["default"]
|
||||||
@ -106,7 +104,7 @@ class NeuralNetwork(Group):
|
|||||||
connection = NetworkConnection(
|
connection = NetworkConnection(
|
||||||
self.input_layers_dict[start_layer_name],
|
self.input_layers_dict[start_layer_name],
|
||||||
self.input_layers_dict[end_layer_name],
|
self.input_layers_dict[end_layer_name],
|
||||||
arc_direction="down" # TODO generalize this more
|
arc_direction="down", # TODO generalize this more
|
||||||
)
|
)
|
||||||
self.connections.append(connection)
|
self.connections.append(connection)
|
||||||
self.add(connection)
|
self.add(connection)
|
||||||
@ -138,20 +136,20 @@ class NeuralNetwork(Group):
|
|||||||
current_layer.move_to(previous_layer.get_center())
|
current_layer.move_to(previous_layer.get_center())
|
||||||
|
|
||||||
if layout_direction == "left_to_right":
|
if layout_direction == "left_to_right":
|
||||||
x_shift = previous_layer.get_width() / 2 \
|
x_shift = (
|
||||||
+ current_layer.get_width() / 2 \
|
previous_layer.get_width() / 2
|
||||||
+ self.layer_spacing
|
+ current_layer.get_width() / 2
|
||||||
|
+ self.layer_spacing
|
||||||
|
)
|
||||||
shift_vector = np.array([x_shift, 0, 0])
|
shift_vector = np.array([x_shift, 0, 0])
|
||||||
elif layout_direction == "top_to_bottom":
|
elif layout_direction == "top_to_bottom":
|
||||||
y_shift = -((
|
y_shift = -(
|
||||||
previous_layer.get_width() / 2 \
|
(previous_layer.get_width() / 2 + current_layer.get_width() / 2)
|
||||||
+ current_layer.get_width() / 2
|
+ self.layer_spacing
|
||||||
) + self.layer_spacing)
|
)
|
||||||
shift_vector = np.array([0, y_shift, 0])
|
shift_vector = np.array([0, y_shift, 0])
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(f"Unrecognized layout direction: {layout_direction}")
|
||||||
f"Unrecognized layout direction: {layout_direction}"
|
|
||||||
)
|
|
||||||
current_layer.shift(shift_vector)
|
current_layer.shift(shift_vector)
|
||||||
|
|
||||||
# After all layers have been placed place their activation functions
|
# After all layers have been placed place their activation functions
|
||||||
@ -159,13 +157,15 @@ class NeuralNetwork(Group):
|
|||||||
# Place activation function
|
# Place activation function
|
||||||
if hasattr(current_layer, "activation_function"):
|
if hasattr(current_layer, "activation_function"):
|
||||||
if not current_layer.activation_function is None:
|
if not current_layer.activation_function is None:
|
||||||
up_movement = np.array([
|
up_movement = np.array(
|
||||||
0,
|
[
|
||||||
current_layer.get_height() / 2
|
0,
|
||||||
+ current_layer.activation_function.get_height() / 2
|
current_layer.get_height() / 2
|
||||||
+ 0.5 * self.layer_spacing,
|
+ current_layer.activation_function.get_height() / 2
|
||||||
0,
|
+ 0.5 * self.layer_spacing,
|
||||||
])
|
0,
|
||||||
|
]
|
||||||
|
)
|
||||||
current_layer.activation_function.move_to(
|
current_layer.activation_function.move_to(
|
||||||
current_layer,
|
current_layer,
|
||||||
)
|
)
|
||||||
@ -259,9 +259,7 @@ class NeuralNetwork(Group):
|
|||||||
current_layer_args = layer_args[layer]
|
current_layer_args = layer_args[layer]
|
||||||
# Perform the forward pass of the current layer
|
# Perform the forward pass of the current layer
|
||||||
layer_forward_pass = layer.make_forward_pass_animation(
|
layer_forward_pass = layer.make_forward_pass_animation(
|
||||||
layer_args=current_layer_args,
|
layer_args=current_layer_args, run_time=per_layer_runtime, **kwargs
|
||||||
run_time=per_layer_runtime,
|
|
||||||
**kwargs
|
|
||||||
)
|
)
|
||||||
# Animate a forward pass for incoming connections
|
# Animate a forward pass for incoming connections
|
||||||
connection_input_pass = AnimationGroup()
|
connection_input_pass = AnimationGroup()
|
||||||
@ -272,14 +270,12 @@ class NeuralNetwork(Group):
|
|||||||
connection_input_pass = ShowPassingFlash(
|
connection_input_pass = ShowPassingFlash(
|
||||||
connection,
|
connection,
|
||||||
run_time=layer_forward_pass.run_time,
|
run_time=layer_forward_pass.run_time,
|
||||||
time_width=0.2
|
time_width=0.2,
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
layer_forward_pass = AnimationGroup(
|
layer_forward_pass = AnimationGroup(
|
||||||
layer_forward_pass,
|
layer_forward_pass, connection_input_pass, lag_ratio=0.0
|
||||||
connection_input_pass,
|
|
||||||
lag_ratio=0.0
|
|
||||||
)
|
)
|
||||||
all_animations.append(layer_forward_pass)
|
all_animations.append(layer_forward_pass)
|
||||||
# Make the animation group
|
# Make the animation group
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
"""
|
|
||||||
Module for handling syncing two animations one to one.
|
|
||||||
The goal here is to zip up two classes and their respective animations,
|
|
||||||
and create a joint class with the same animations that runs the animations
|
|
||||||
for both classes at the same time. This way we can connect two isomorphic
|
|
||||||
views of the same concept and visualize them at the same time.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class OneToOneSync:
|
|
||||||
pass
|
|
@ -1,30 +1,27 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from manim import *
|
from manim import *
|
||||||
|
|
||||||
|
|
||||||
class NetworkConnection(VGroup):
|
class NetworkConnection(VGroup):
|
||||||
"""
|
"""
|
||||||
This class allows for creating connections
|
This class allows for creating connections
|
||||||
between locations in a network
|
between locations in a network
|
||||||
"""
|
"""
|
||||||
direction_vector_map = {
|
|
||||||
"up": UP,
|
direction_vector_map = {"up": UP, "down": DOWN, "left": LEFT, "right": RIGHT}
|
||||||
"down": DOWN,
|
|
||||||
"left": LEFT,
|
|
||||||
"right": RIGHT
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
start_mobject,
|
start_mobject,
|
||||||
end_mobject,
|
end_mobject,
|
||||||
arc_direction="straight",
|
arc_direction="straight",
|
||||||
buffer=0.05,
|
buffer=0.05,
|
||||||
arc_distance=0.3,
|
arc_distance=0.3,
|
||||||
stroke_width=2.0,
|
stroke_width=2.0,
|
||||||
color=WHITE,
|
color=WHITE,
|
||||||
active_color=ORANGE
|
active_color=ORANGE,
|
||||||
):
|
):
|
||||||
"""Creates an arrow with right angles in it connecting
|
"""Creates an arrow with right angles in it connecting
|
||||||
two mobjects.
|
two mobjects.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -72,34 +69,28 @@ class NetworkConnection(VGroup):
|
|||||||
# Make an arrow
|
# Make an arrow
|
||||||
arrow_line = Line(
|
arrow_line = Line(
|
||||||
left_mobject.get_right() + np.array([self.buffer, 0.0, 0.0]),
|
left_mobject.get_right() + np.array([self.buffer, 0.0, 0.0]),
|
||||||
right_mobject.get_left() + np.array([-1 * self.buffer, 0.0, 0.0])
|
right_mobject.get_left() + np.array([-1 * self.buffer, 0.0, 0.0]),
|
||||||
)
|
|
||||||
arrow = Arrow(
|
|
||||||
arrow_line,
|
|
||||||
color=self.color,
|
|
||||||
stroke_width=self.stroke_width
|
|
||||||
)
|
)
|
||||||
|
arrow = Arrow(arrow_line, color=self.color, stroke_width=self.stroke_width)
|
||||||
self.straight_arrow = arrow
|
self.straight_arrow = arrow
|
||||||
self.add(arrow)
|
self.add(arrow)
|
||||||
else:
|
else:
|
||||||
# Figure out the direction of the arc
|
# Figure out the direction of the arc
|
||||||
direction_vector = NetworkConnection.direction_vector_map[self.arc_direction]
|
direction_vector = NetworkConnection.direction_vector_map[
|
||||||
|
self.arc_direction
|
||||||
|
]
|
||||||
# Make the start arc piece
|
# Make the start arc piece
|
||||||
start_line_start = left_mobject.get_critical_point(
|
start_line_start = left_mobject.get_critical_point(direction_vector)
|
||||||
direction_vector
|
|
||||||
)
|
|
||||||
start_line_start += direction_vector * self.buffer
|
start_line_start += direction_vector * self.buffer
|
||||||
start_line_end = start_line_start + direction_vector * self.arc_distance
|
start_line_end = start_line_start + direction_vector * self.arc_distance
|
||||||
self.start_line = Line(
|
self.start_line = Line(
|
||||||
start_line_start,
|
start_line_start,
|
||||||
start_line_end,
|
start_line_end,
|
||||||
color=self.color,
|
color=self.color,
|
||||||
stroke_width=self.stroke_width
|
stroke_width=self.stroke_width,
|
||||||
)
|
)
|
||||||
# Make the end arc piece with an arrow
|
# Make the end arc piece with an arrow
|
||||||
end_line_end = right_mobject.get_critical_point(
|
end_line_end = right_mobject.get_critical_point(direction_vector)
|
||||||
direction_vector
|
|
||||||
)
|
|
||||||
end_line_end += direction_vector * self.buffer
|
end_line_end += direction_vector * self.buffer
|
||||||
end_line_start = end_line_end + direction_vector * self.arc_distance
|
end_line_start = end_line_end + direction_vector * self.arc_distance
|
||||||
self.end_arrow = Arrow(
|
self.end_arrow = Arrow(
|
||||||
@ -108,14 +99,14 @@ class NetworkConnection(VGroup):
|
|||||||
color=WHITE,
|
color=WHITE,
|
||||||
fill_color=WHITE,
|
fill_color=WHITE,
|
||||||
stroke_opacity=1.0,
|
stroke_opacity=1.0,
|
||||||
buff=0.0
|
buff=0.0,
|
||||||
)
|
)
|
||||||
# Make the middle arc piece
|
# Make the middle arc piece
|
||||||
self.middle_line = Line(
|
self.middle_line = Line(
|
||||||
start_line_end,
|
start_line_end,
|
||||||
end_line_start,
|
end_line_start,
|
||||||
color=self.color,
|
color=self.color,
|
||||||
stroke_width=self.stroke_width
|
stroke_width=self.stroke_width,
|
||||||
)
|
)
|
||||||
# Add the mobjects
|
# Add the mobjects
|
||||||
self.add(
|
self.add(
|
||||||
@ -130,23 +121,23 @@ class NetworkConnection(VGroup):
|
|||||||
if self.arc_direction == "straight":
|
if self.arc_direction == "straight":
|
||||||
return ShowPassingFlash(
|
return ShowPassingFlash(
|
||||||
self.straight_arrow.copy().set_color(self.active_color),
|
self.straight_arrow.copy().set_color(self.active_color),
|
||||||
time_width=time_width
|
time_width=time_width,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Animate the start line
|
# Animate the start line
|
||||||
start_line_animation = ShowPassingFlash(
|
start_line_animation = ShowPassingFlash(
|
||||||
self.start_line.copy().set_color(self.active_color),
|
self.start_line.copy().set_color(self.active_color),
|
||||||
time_width=time_width
|
time_width=time_width,
|
||||||
)
|
)
|
||||||
# Animate the middle line
|
# Animate the middle line
|
||||||
middle_line_animation = ShowPassingFlash(
|
middle_line_animation = ShowPassingFlash(
|
||||||
self.middle_line.copy().set_color(self.active_color),
|
self.middle_line.copy().set_color(self.active_color),
|
||||||
time_width=time_width
|
time_width=time_width,
|
||||||
)
|
)
|
||||||
# Animate the end line
|
# Animate the end line
|
||||||
end_line_animation = ShowPassingFlash(
|
end_line_animation = ShowPassingFlash(
|
||||||
self.end_arrow.copy().set_color(self.active_color),
|
self.end_arrow.copy().set_color(self.active_color),
|
||||||
time_width=time_width
|
time_width=time_width,
|
||||||
)
|
)
|
||||||
|
|
||||||
return AnimationGroup(
|
return AnimationGroup(
|
||||||
@ -154,5 +145,5 @@ class NetworkConnection(VGroup):
|
|||||||
middle_line_animation,
|
middle_line_animation,
|
||||||
end_line_animation,
|
end_line_animation,
|
||||||
lag_ratio=1.0,
|
lag_ratio=1.0,
|
||||||
run_time=run_time
|
run_time=run_time,
|
||||||
)
|
)
|
||||||
|
@ -14,7 +14,7 @@ class GriddedRectangle(VGroup):
|
|||||||
close_new_points=True,
|
close_new_points=True,
|
||||||
grid_xstep=None,
|
grid_xstep=None,
|
||||||
grid_ystep=None,
|
grid_ystep=None,
|
||||||
grid_stroke_width=0.0, # DEFAULT_STROKE_WIDTH/2,
|
grid_stroke_width=0.0, # DEFAULT_STROKE_WIDTH/2,
|
||||||
grid_stroke_color=ORANGE,
|
grid_stroke_color=ORANGE,
|
||||||
grid_stroke_opacity=1.0,
|
grid_stroke_opacity=1.0,
|
||||||
stroke_width=2.0,
|
stroke_width=2.0,
|
||||||
@ -48,7 +48,7 @@ class GriddedRectangle(VGroup):
|
|||||||
fill_color=color,
|
fill_color=color,
|
||||||
stroke_opacity=0.0,
|
stroke_opacity=0.0,
|
||||||
fill_opacity=fill_opacity,
|
fill_opacity=fill_opacity,
|
||||||
shade_in_3d=True
|
shade_in_3d=True,
|
||||||
)
|
)
|
||||||
self.rectangle = no_border_rectangle
|
self.rectangle = no_border_rectangle
|
||||||
border_rectangle = Rectangle(
|
border_rectangle = Rectangle(
|
||||||
@ -58,7 +58,7 @@ class GriddedRectangle(VGroup):
|
|||||||
fill_color=color,
|
fill_color=color,
|
||||||
fill_opacity=fill_opacity,
|
fill_opacity=fill_opacity,
|
||||||
shade_in_3d=True,
|
shade_in_3d=True,
|
||||||
stroke_width=stroke_width
|
stroke_width=stroke_width,
|
||||||
)
|
)
|
||||||
self.dotted_lines = DashedVMobject(
|
self.dotted_lines = DashedVMobject(
|
||||||
border_rectangle,
|
border_rectangle,
|
||||||
@ -73,7 +73,7 @@ class GriddedRectangle(VGroup):
|
|||||||
stroke_width=stroke_width,
|
stroke_width=stroke_width,
|
||||||
fill_color=color,
|
fill_color=color,
|
||||||
fill_opacity=fill_opacity,
|
fill_opacity=fill_opacity,
|
||||||
shade_in_3d=True
|
shade_in_3d=True,
|
||||||
)
|
)
|
||||||
self.add(self.rectangle)
|
self.add(self.rectangle)
|
||||||
# Make grid lines
|
# Make grid lines
|
||||||
@ -123,7 +123,7 @@ class GriddedRectangle(VGroup):
|
|||||||
stroke_color=self.grid_stroke_color,
|
stroke_color=self.grid_stroke_color,
|
||||||
stroke_width=self.grid_stroke_width,
|
stroke_width=self.grid_stroke_width,
|
||||||
stroke_opacity=self.grid_stroke_opacity,
|
stroke_opacity=self.grid_stroke_opacity,
|
||||||
shade_in_3d=True
|
shade_in_3d=True,
|
||||||
)
|
)
|
||||||
for i in range(1, count)
|
for i in range(1, count)
|
||||||
)
|
)
|
@ -27,6 +27,7 @@ _tests_root_dir_path = Path(__file__).absolute().parents[2]
|
|||||||
print(f"Tests root path: {_tests_root_dir_path}")
|
print(f"Tests root path: {_tests_root_dir_path}")
|
||||||
PATH_CONTROL_DATA = _tests_root_dir_path / Path("control_data", "graphical_units_data")
|
PATH_CONTROL_DATA = _tests_root_dir_path / Path("control_data", "graphical_units_data")
|
||||||
|
|
||||||
|
|
||||||
def frames_comparison(
|
def frames_comparison(
|
||||||
func=None,
|
func=None,
|
||||||
*,
|
*,
|
||||||
@ -254,4 +255,4 @@ def _config_test(last_frame: bool) -> ManimConfig:
|
|||||||
else "config_graphical_tests_multiframes.cfg"
|
else "config_graphical_tests_multiframes.cfg"
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="manim_ml",
|
name="manim_ml",
|
||||||
version="0.0.15",
|
version="0.0.16",
|
||||||
description=(" Machine Learning Animations in python using Manim."),
|
description=(" Machine Learning Animations in python using Manim."),
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
)
|
)
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -9,6 +7,7 @@ import pytest
|
|||||||
|
|
||||||
from manim import config, tempconfig
|
from manim import config, tempconfig
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addoption(
|
parser.addoption(
|
||||||
"--skip_slow",
|
"--skip_slow",
|
||||||
|
@ -13,15 +13,19 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
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=1.5),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32, activation_function="ReLU"),
|
Convolutional2DLayer(
|
||||||
|
3, 5, 3, filter_spacing=0.32, activation_function="ReLU"
|
||||||
|
),
|
||||||
FeedForwardLayer(3, activation_function="Sigmoid"),
|
FeedForwardLayer(3, activation_function="Sigmoid"),
|
||||||
],
|
],
|
||||||
layer_spacing=0.25,
|
layer_spacing=0.25,
|
||||||
@ -32,4 +36,4 @@ class CombinedScene(ThreeDScene):
|
|||||||
# Play animation
|
# Play animation
|
||||||
forward_pass = nn.make_forward_pass_animation()
|
forward_pass = nn.make_forward_pass_animation()
|
||||||
self.wait(1)
|
self.wait(1)
|
||||||
self.play(forward_pass, run_time=30)
|
self.play(forward_pass, run_time=30)
|
||||||
|
@ -12,14 +12,11 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
|
|
||||||
class NeuralNetworkScene(ThreeDScene):
|
class NeuralNetworkScene(ThreeDScene):
|
||||||
"""Test Scene for the Neural Network"""
|
"""Test Scene for the Neural Network"""
|
||||||
|
|
||||||
def play_camera_follow_forward_pass(
|
def play_camera_follow_forward_pass(self, neural_network, buffer=0.1):
|
||||||
self,
|
|
||||||
neural_network,
|
|
||||||
buffer=0.1
|
|
||||||
):
|
|
||||||
per_layer_animations = neural_network.make_forward_pass_animation(
|
per_layer_animations = neural_network.make_forward_pass_animation(
|
||||||
return_per_layer_animations=True
|
return_per_layer_animations=True
|
||||||
)
|
)
|
||||||
@ -32,7 +29,7 @@ class NeuralNetworkScene(ThreeDScene):
|
|||||||
current_layer = all_layers[layer_index]
|
current_layer = all_layers[layer_index]
|
||||||
next_layer = all_layers[layer_index + 1]
|
next_layer = all_layers[layer_index + 1]
|
||||||
group = Group(prev_layer, current_layer, next_layer)
|
group = Group(prev_layer, current_layer, next_layer)
|
||||||
|
|
||||||
max_width = max(max_width, group.width)
|
max_width = max(max_width, group.width)
|
||||||
max_height = max(max_height, group.height)
|
max_height = max(max_height, group.height)
|
||||||
|
|
||||||
@ -46,7 +43,8 @@ class NeuralNetworkScene(ThreeDScene):
|
|||||||
# Make the Layer object
|
# Make the Layer object
|
||||||
image = Image.open("../assets/mnist/digit.jpeg")
|
image = Image.open("../assets/mnist/digit.jpeg")
|
||||||
numpy_image = np.asarray(image)
|
numpy_image = np.asarray(image)
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
ImageLayer(numpy_image, height=1.5),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
||||||
@ -60,4 +58,4 @@ class NeuralNetworkScene(ThreeDScene):
|
|||||||
# Make Animation
|
# Make Animation
|
||||||
self.add(nn)
|
self.add(nn)
|
||||||
# self.play(Create(nn))
|
# self.play(Create(nn))
|
||||||
self.play_camera_follow_forward_pass(nn)
|
self.play_camera_follow_forward_pass(nn)
|
||||||
|
@ -14,23 +14,24 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
|
||||||
|
|
||||||
|
class CombinedScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
Convolutional2DLayer(
|
Convolutional2DLayer(
|
||||||
num_feature_maps=1,
|
num_feature_maps=1,
|
||||||
feature_map_size=7,
|
feature_map_size=7,
|
||||||
padding=1,
|
padding=1,
|
||||||
padding_dashed=True
|
padding_dashed=True,
|
||||||
),
|
),
|
||||||
Convolutional2DLayer(
|
Convolutional2DLayer(
|
||||||
num_feature_maps=3,
|
num_feature_maps=3,
|
||||||
feature_map_size=7,
|
feature_map_size=7,
|
||||||
filter_size=3,
|
filter_size=3,
|
||||||
padding=0,
|
padding=0,
|
||||||
padding_dashed=False
|
padding_dashed=False,
|
||||||
),
|
),
|
||||||
FeedForwardLayer(3),
|
FeedForwardLayer(3),
|
||||||
],
|
],
|
||||||
@ -44,23 +45,22 @@ class CombinedScene(ThreeDScene):
|
|||||||
self.wait(1)
|
self.wait(1)
|
||||||
self.play(forward_pass, run_time=30)
|
self.play(forward_pass, run_time=30)
|
||||||
|
|
||||||
|
|
||||||
@frames_comparison
|
@frames_comparison
|
||||||
def test_ConvPadding(scene):
|
def test_ConvPadding(scene):
|
||||||
# Make nn
|
# Make nn
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
|
[
|
||||||
Convolutional2DLayer(
|
Convolutional2DLayer(
|
||||||
num_feature_maps=1,
|
num_feature_maps=1, feature_map_size=7, padding=1, padding_dashed=True
|
||||||
feature_map_size=7,
|
|
||||||
padding=1,
|
|
||||||
padding_dashed=True
|
|
||||||
),
|
),
|
||||||
Convolutional2DLayer(
|
Convolutional2DLayer(
|
||||||
num_feature_maps=3,
|
num_feature_maps=3,
|
||||||
feature_map_size=7,
|
feature_map_size=7,
|
||||||
filter_size=3,
|
filter_size=3,
|
||||||
padding=1,
|
padding=1,
|
||||||
filter_spacing=0.35,
|
filter_spacing=0.35,
|
||||||
padding_dashed=False
|
padding_dashed=False,
|
||||||
),
|
),
|
||||||
FeedForwardLayer(3),
|
FeedForwardLayer(3),
|
||||||
],
|
],
|
||||||
@ -71,4 +71,4 @@ def test_ConvPadding(scene):
|
|||||||
scene.add(nn)
|
scene.add(nn)
|
||||||
# Play animation
|
# Play animation
|
||||||
forward_pass = nn.make_forward_pass_animation()
|
forward_pass = nn.make_forward_pass_animation()
|
||||||
scene.play(forward_pass, run_time=30)
|
scene.play(forward_pass, run_time=30)
|
||||||
|
@ -6,6 +6,7 @@ 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
|
||||||
|
|
||||||
|
|
||||||
class SingleConvolutionalLayerScene(ThreeDScene):
|
class SingleConvolutionalLayerScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
# Make nn
|
# Make nn
|
||||||
@ -21,6 +22,7 @@ class SingleConvolutionalLayerScene(ThreeDScene):
|
|||||||
)
|
)
|
||||||
# self.play(nn.make_forward_pass_animation(run_time=5))
|
# self.play(nn.make_forward_pass_animation(run_time=5))
|
||||||
|
|
||||||
|
|
||||||
class Simple3DConvScene(ThreeDScene):
|
class Simple3DConvScene(ThreeDScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
"""
|
"""
|
||||||
@ -33,16 +35,8 @@ class Simple3DConvScene(ThreeDScene):
|
|||||||
"""
|
"""
|
||||||
# Make nn
|
# Make nn
|
||||||
layers = [
|
layers = [
|
||||||
Convolutional2DLayer(
|
Convolutional2DLayer(num_feature_maps=1, feature_map_size=3, filter_size=3),
|
||||||
num_feature_maps=1,
|
Convolutional2DLayer(num_feature_maps=1, feature_map_size=3, filter_size=3),
|
||||||
feature_map_size=3,
|
|
||||||
filter_size=3
|
|
||||||
),
|
|
||||||
Convolutional2DLayer(
|
|
||||||
num_feature_maps=1,
|
|
||||||
feature_map_size=3,
|
|
||||||
filter_size=3
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
nn = NeuralNetwork(layers)
|
nn = NeuralNetwork(layers)
|
||||||
# Center the nn
|
# Center the nn
|
||||||
@ -52,18 +46,21 @@ class Simple3DConvScene(ThreeDScene):
|
|||||||
# self.set_camera_orientation(phi=280*DEGREES, theta=-10*DEGREES, gamma=90*DEGREES)
|
# self.set_camera_orientation(phi=280*DEGREES, theta=-10*DEGREES, gamma=90*DEGREES)
|
||||||
self.play(nn.make_forward_pass_animation(run_time=30))
|
self.play(nn.make_forward_pass_animation(run_time=30))
|
||||||
|
|
||||||
|
|
||||||
# Make the specific scene
|
# Make the specific scene
|
||||||
config.pixel_height = 1200
|
config.pixel_height = 1200
|
||||||
config.pixel_width = 1900
|
config.pixel_width = 1900
|
||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
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=1.5),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
Convolutional2DLayer(1, 7, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
|
||||||
@ -79,4 +76,4 @@ class CombinedScene(ThreeDScene):
|
|||||||
# Play animation
|
# Play animation
|
||||||
forward_pass = nn.make_forward_pass_animation()
|
forward_pass = nn.make_forward_pass_animation()
|
||||||
self.wait(1)
|
self.wait(1)
|
||||||
self.play(forward_pass)
|
self.play(forward_pass)
|
||||||
|
@ -9,6 +9,7 @@ from sklearn import datasets
|
|||||||
import sklearn
|
import sklearn
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
def learn_iris_decision_tree(iris):
|
def learn_iris_decision_tree(iris):
|
||||||
decision_tree = DecisionTreeClassifier(
|
decision_tree = DecisionTreeClassifier(
|
||||||
random_state=1, max_depth=3, max_leaf_nodes=6
|
random_state=1, max_depth=3, max_leaf_nodes=6
|
||||||
@ -17,11 +18,13 @@ def learn_iris_decision_tree(iris):
|
|||||||
# output the decisioin tree in some format
|
# output the decisioin tree in some format
|
||||||
return decision_tree
|
return decision_tree
|
||||||
|
|
||||||
|
|
||||||
def make_sklearn_tree(dataset, max_tree_depth=3):
|
def make_sklearn_tree(dataset, max_tree_depth=3):
|
||||||
tree = learn_iris_decision_tree(dataset)
|
tree = learn_iris_decision_tree(dataset)
|
||||||
feature_names = dataset.feature_names[0:2]
|
feature_names = dataset.feature_names[0:2]
|
||||||
return tree, tree.tree_
|
return tree, tree.tree_
|
||||||
|
|
||||||
|
|
||||||
class DecisionTreeScene(Scene):
|
class DecisionTreeScene(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
"""Makes a decision tree object"""
|
"""Makes a decision tree object"""
|
||||||
@ -44,6 +47,7 @@ class DecisionTreeScene(Scene):
|
|||||||
self.play(create_decision_tree)
|
self.play(create_decision_tree)
|
||||||
# self.play(create_decision_tree)
|
# self.play(create_decision_tree)
|
||||||
|
|
||||||
|
|
||||||
class SurfacePlot(Scene):
|
class SurfacePlot(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
iris_dataset = datasets.load_iris()
|
iris_dataset = datasets.load_iris()
|
||||||
|
@ -5,26 +5,21 @@ from manim_ml.neural_network import NeuralNetwork, FeedForwardLayer
|
|||||||
|
|
||||||
__module_test__ = "feed_forward"
|
__module_test__ = "feed_forward"
|
||||||
|
|
||||||
|
|
||||||
@frames_comparison
|
@frames_comparison
|
||||||
def test_FeedForwardScene(scene):
|
def test_FeedForwardScene(scene):
|
||||||
"""Tests the appearance of a feed forward network"""
|
"""Tests the appearance of a feed forward network"""
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork([FeedForwardLayer(3), FeedForwardLayer(5), FeedForwardLayer(3)])
|
||||||
FeedForwardLayer(3),
|
|
||||||
FeedForwardLayer(5),
|
|
||||||
FeedForwardLayer(3)
|
|
||||||
])
|
|
||||||
|
|
||||||
scene.add(nn)
|
scene.add(nn)
|
||||||
|
|
||||||
class FeedForwardScene(Scene):
|
|
||||||
|
|
||||||
|
class FeedForwardScene(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
nn = NeuralNetwork([
|
nn = NeuralNetwork(
|
||||||
FeedForwardLayer(3),
|
[FeedForwardLayer(3), FeedForwardLayer(5), FeedForwardLayer(3)]
|
||||||
FeedForwardLayer(5),
|
)
|
||||||
FeedForwardLayer(3)
|
|
||||||
])
|
|
||||||
|
|
||||||
self.add(nn)
|
self.add(nn)
|
||||||
|
|
||||||
self.play(nn.make_forward_pass_animation())
|
self.play(nn.make_forward_pass_animation())
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.gridded_rectangle import GriddedRectangle
|
from manim_ml.utils.mobjects.gridded_rectangle import GriddedRectangle
|
||||||
|
|
||||||
|
|
||||||
class TestGriddedRectangleScene(ThreeDScene):
|
class TestGriddedRectangleScene(ThreeDScene):
|
||||||
|
|
||||||
def construct(self):
|
def construct(self):
|
||||||
rect = GriddedRectangle(
|
rect = GriddedRectangle(color=ORANGE, width=3, height=3)
|
||||||
color=ORANGE,
|
self.add(rect)
|
||||||
width=3,
|
|
||||||
height=3
|
|
||||||
)
|
|
||||||
self.add(rect)
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.image import GrayscaleImageMobject
|
from manim_ml.utils.mobjects.image import GrayscaleImageMobject
|
||||||
from manim_ml.neural_network.layers.parent_layers import ThreeDLayer
|
from manim_ml.neural_network.layers.parent_layers import ThreeDLayer
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,12 +14,14 @@ config.pixel_width = 1900
|
|||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
|
|
||||||
class CombinedScene(ThreeDScene):
|
class CombinedScene(ThreeDScene):
|
||||||
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=1.5),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
Convolutional2DLayer(1, 8, filter_spacing=0.32),
|
Convolutional2DLayer(1, 8, filter_spacing=0.32),
|
||||||
Convolutional2DLayer(3, 6, 3, filter_spacing=0.32),
|
Convolutional2DLayer(3, 6, 3, filter_spacing=0.32),
|
||||||
@ -37,12 +39,14 @@ class CombinedScene(ThreeDScene):
|
|||||||
self.wait(1)
|
self.wait(1)
|
||||||
self.play(forward_pass)
|
self.play(forward_pass)
|
||||||
|
|
||||||
|
|
||||||
class SmallNetwork(ThreeDScene):
|
class SmallNetwork(ThreeDScene):
|
||||||
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=1.5),
|
ImageLayer(numpy_image, height=1.5),
|
||||||
Convolutional2DLayer(1, 8, filter_spacing=0.32),
|
Convolutional2DLayer(1, 8, filter_spacing=0.32),
|
||||||
MaxPooling2DLayer(kernel_size=2),
|
MaxPooling2DLayer(kernel_size=2),
|
||||||
@ -55,4 +59,4 @@ class SmallNetwork(ThreeDScene):
|
|||||||
# Play animation
|
# Play animation
|
||||||
forward_pass = nn.make_forward_pass_animation()
|
forward_pass = nn.make_forward_pass_animation()
|
||||||
self.wait(1)
|
self.wait(1)
|
||||||
self.play(forward_pass)
|
self.play(forward_pass)
|
||||||
|
@ -1,31 +1,33 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.diffusion.mcmc import MCMCAxes, MultidimensionalGaussianPosterior, metropolis_hastings_sampler
|
from manim_ml.diffusion.mcmc import (
|
||||||
|
MCMCAxes,
|
||||||
|
MultidimensionalGaussianPosterior,
|
||||||
|
metropolis_hastings_sampler,
|
||||||
|
)
|
||||||
|
|
||||||
# Make the specific scene
|
# Make the specific scene
|
||||||
config.pixel_height = 1200
|
config.pixel_height = 1200
|
||||||
config.pixel_width = 1200
|
config.pixel_width = 1200
|
||||||
config.frame_height = 12.0
|
config.frame_height = 12.0
|
||||||
config.frame_width = 12.0
|
config.frame_width = 12.0
|
||||||
|
|
||||||
|
|
||||||
def test_metropolis_hastings_sampler(iterations=100):
|
def test_metropolis_hastings_sampler(iterations=100):
|
||||||
samples, _, candidates = metropolis_hastings_sampler(iterations=iterations)
|
samples, _, candidates = metropolis_hastings_sampler(iterations=iterations)
|
||||||
assert samples.shape == (iterations, 2)
|
assert samples.shape == (iterations, 2)
|
||||||
|
|
||||||
class MCMCTest(Scene):
|
|
||||||
|
|
||||||
|
class MCMCTest(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
axes = MCMCAxes()
|
axes = MCMCAxes()
|
||||||
self.play(Create(axes))
|
self.play(Create(axes))
|
||||||
gaussian_posterior = MultidimensionalGaussianPosterior(
|
gaussian_posterior = MultidimensionalGaussianPosterior(
|
||||||
mu=np.array([0.0, 0.0]),
|
mu=np.array([0.0, 0.0]), var=np.array([4.0, 2.0])
|
||||||
var=np.array([4.0, 2.0])
|
|
||||||
)
|
|
||||||
show_gaussian_animation = axes.show_ground_truth_gaussian(
|
|
||||||
gaussian_posterior
|
|
||||||
)
|
)
|
||||||
|
show_gaussian_animation = axes.show_ground_truth_gaussian(gaussian_posterior)
|
||||||
self.play(show_gaussian_animation)
|
self.play(show_gaussian_animation)
|
||||||
chain_sampling_animation = axes.visualize_metropolis_hastings_chain_sampling(
|
chain_sampling_animation = axes.visualize_metropolis_hastings_chain_sampling(
|
||||||
log_prob_fn=gaussian_posterior,
|
log_prob_fn=gaussian_posterior, sampling_kwargs={"iterations": 1000}
|
||||||
sampling_kwargs={"iterations": 1000}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.play(chain_sampling_animation)
|
self.play(chain_sampling_animation)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"""
|
"""
|
||||||
The purpose of this test is to ensure that it is possible
|
The purpose of this test is to ensure that it is possible
|
||||||
to have nested neural network layers.
|
to have nested neural network layers.
|
||||||
"""
|
"""
|
||||||
|
@ -9,49 +9,53 @@ import numpy as np
|
|||||||
|
|
||||||
__module_test__ = "residual"
|
__module_test__ = "residual"
|
||||||
|
|
||||||
|
|
||||||
@frames_comparison
|
@frames_comparison
|
||||||
def test_ResidualConnectionScene(scene):
|
def test_ResidualConnectionScene(scene):
|
||||||
"""Tests the appearance of a residual connection"""
|
"""Tests the appearance of a residual connection"""
|
||||||
nn = NeuralNetwork({
|
nn = NeuralNetwork(
|
||||||
"layer1": FeedForwardLayer(3),
|
{
|
||||||
"layer2": FeedForwardLayer(5),
|
"layer1": FeedForwardLayer(3),
|
||||||
"layer3": FeedForwardLayer(3)
|
"layer2": FeedForwardLayer(5),
|
||||||
})
|
"layer3": FeedForwardLayer(3),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
scene.add(nn)
|
scene.add(nn)
|
||||||
|
|
||||||
|
|
||||||
# Make the specific scene
|
# Make the specific scene
|
||||||
config.pixel_height = 1200
|
config.pixel_height = 1200
|
||||||
config.pixel_width = 1900
|
config.pixel_width = 1900
|
||||||
config.frame_height = 6.0
|
config.frame_height = 6.0
|
||||||
config.frame_width = 6.0
|
config.frame_width = 6.0
|
||||||
|
|
||||||
class FeedForwardScene(Scene):
|
|
||||||
|
|
||||||
|
class FeedForwardScene(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
nn = NeuralNetwork({
|
nn = NeuralNetwork(
|
||||||
"layer1": FeedForwardLayer(4),
|
{
|
||||||
"layer2": FeedForwardLayer(4),
|
"layer1": FeedForwardLayer(4),
|
||||||
"layer3": FeedForwardLayer(4)
|
"layer2": FeedForwardLayer(4),
|
||||||
},
|
"layer3": FeedForwardLayer(4),
|
||||||
layer_spacing=0.45)
|
},
|
||||||
|
layer_spacing=0.45,
|
||||||
|
)
|
||||||
|
|
||||||
nn.add_connection("layer1", "layer3")
|
nn.add_connection("layer1", "layer3")
|
||||||
|
|
||||||
self.add(nn)
|
self.add(nn)
|
||||||
|
|
||||||
self.play(
|
self.play(nn.make_forward_pass_animation(), run_time=8)
|
||||||
nn.make_forward_pass_animation(),
|
|
||||||
run_time=8
|
|
||||||
)
|
|
||||||
|
|
||||||
class ConvScene(ThreeDScene):
|
class ConvScene(ThreeDScene):
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
nn = NeuralNetwork({
|
nn = NeuralNetwork(
|
||||||
|
{
|
||||||
"layer1": Convolutional2DLayer(1, 5, padding=1),
|
"layer1": Convolutional2DLayer(1, 5, padding=1),
|
||||||
"layer2": Convolutional2DLayer(1, 5, 3, padding=1),
|
"layer2": Convolutional2DLayer(1, 5, 3, padding=1),
|
||||||
"layer3": Convolutional2DLayer(1, 5, 3, padding=1),
|
"layer3": Convolutional2DLayer(1, 5, 3, padding=1),
|
||||||
@ -63,7 +67,4 @@ class ConvScene(ThreeDScene):
|
|||||||
|
|
||||||
self.add(nn)
|
self.add(nn)
|
||||||
|
|
||||||
self.play(
|
self.play(nn.make_forward_pass_animation(), run_time=8)
|
||||||
nn.make_forward_pass_animation(),
|
|
||||||
run_time=8
|
|
||||||
)
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
from manim_ml.probability import GaussianDistribution
|
from manim_ml.utils.mobjects.probability import GaussianDistribution
|
||||||
|
|
||||||
|
|
||||||
class TestShowGaussian(Scene):
|
class TestShowGaussian(Scene):
|
||||||
|
|
||||||
def construct(self):
|
def construct(self):
|
||||||
axes = Axes()
|
axes = Axes()
|
||||||
self.add(axes)
|
self.add(axes)
|
||||||
gaussian = GaussianDistribution(
|
gaussian = GaussianDistribution(
|
||||||
axes,
|
axes, mean=np.array([0.0, 0.0]), cov=np.array([[2.0, 0.0], [0.0, 1.0]])
|
||||||
mean=np.array([0.0, 0.0]),
|
|
||||||
cov=np.array([[2.0, 0.0], [0.0, 1.0]])
|
|
||||||
)
|
)
|
||||||
self.add(gaussian)
|
self.add(gaussian)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from manim import *
|
from manim import *
|
||||||
|
|
||||||
class TestSuccession(Scene):
|
|
||||||
|
|
||||||
|
class TestSuccession(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
white_dot = Dot(color=WHITE)
|
white_dot = Dot(color=WHITE)
|
||||||
white_dot.shift(UP)
|
white_dot.shift(UP)
|
||||||
@ -16,4 +16,4 @@ class TestSuccession(Scene):
|
|||||||
Wait(1),
|
Wait(1),
|
||||||
Uncreate(red_dot),
|
Uncreate(red_dot),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user