mirror of
https://github.com/helblazer811/ManimML.git
synced 2025-05-20 20:16:32 +08:00
Finshed adding construct_layer methods for refactor.
This commit is contained in:
@ -286,6 +286,9 @@ class Convolutional2DToConvolutional2D(ConnectiveLayer, ThreeDLayer):
|
|||||||
self.show_grid_lines = show_grid_lines
|
self.show_grid_lines = show_grid_lines
|
||||||
self.highlight_color = highlight_color
|
self.highlight_color = highlight_color
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def get_rotated_shift_vectors(self):
|
def get_rotated_shift_vectors(self):
|
||||||
"""
|
"""
|
||||||
Rotates the shift vectors
|
Rotates the shift vectors
|
||||||
|
@ -26,6 +26,9 @@ class Convolutional2DToFeedForward(ConnectiveLayer, ThreeDLayer):
|
|||||||
)
|
)
|
||||||
self.passing_flash_color = passing_flash_color
|
self.passing_flash_color = passing_flash_color
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def make_forward_pass_animation(self, layer_args={}, run_time=1.5, **kwargs):
|
def make_forward_pass_animation(self, layer_args={}, run_time=1.5, **kwargs):
|
||||||
"""Forward pass animation from conv2d to conv2d"""
|
"""Forward pass animation from conv2d to conv2d"""
|
||||||
animations = []
|
animations = []
|
||||||
|
@ -16,11 +16,20 @@ class EmbeddingLayer(VGroupNeuralNetworkLayer):
|
|||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
super(VGroupNeuralNetworkLayer, self).__init__(**kwargs)
|
super(VGroupNeuralNetworkLayer, self).__init__(**kwargs)
|
||||||
|
self.mean = mean
|
||||||
|
self.covariance = covariance
|
||||||
self.gaussian_distributions = VGroup()
|
self.gaussian_distributions = VGroup()
|
||||||
self.add(self.gaussian_distributions)
|
self.add(self.gaussian_distributions)
|
||||||
self.point_radius = point_radius
|
self.point_radius = point_radius
|
||||||
self.dist_theme = dist_theme
|
self.dist_theme = dist_theme
|
||||||
self.paired_query_mode = paired_query_mode
|
self.paired_query_mode = paired_query_mode
|
||||||
|
|
||||||
|
def construct_layer(
|
||||||
|
self,
|
||||||
|
input_layer: 'NeuralNetworkLayer',
|
||||||
|
output_layer: 'NeuralNetworkLayer',
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
self.axes = Axes(
|
self.axes = Axes(
|
||||||
tips=False,
|
tips=False,
|
||||||
x_length=0.8,
|
x_length=0.8,
|
||||||
@ -33,11 +42,14 @@ class EmbeddingLayer(VGroupNeuralNetworkLayer):
|
|||||||
self.add(self.axes)
|
self.add(self.axes)
|
||||||
self.axes.move_to(self.get_center())
|
self.axes.move_to(self.get_center())
|
||||||
# Make point cloud
|
# Make point cloud
|
||||||
self.point_cloud = self.construct_gaussian_point_cloud(mean, covariance)
|
self.point_cloud = self.construct_gaussian_point_cloud(
|
||||||
|
self.mean,
|
||||||
|
self.covariance
|
||||||
|
)
|
||||||
self.add(self.point_cloud)
|
self.add(self.point_cloud)
|
||||||
# Make latent distribution
|
# Make latent distribution
|
||||||
self.latent_distribution = GaussianDistribution(
|
self.latent_distribution = GaussianDistribution(
|
||||||
self.axes, mean=mean, cov=covariance
|
self.axes, mean=self.mean, cov=self.covariance
|
||||||
) # Use defaults
|
) # Use defaults
|
||||||
|
|
||||||
def add_gaussian_distribution(self, gaussian_distribution):
|
def add_gaussian_distribution(self, gaussian_distribution):
|
||||||
|
@ -30,6 +30,9 @@ class EmbeddingToFeedForward(ConnectiveLayer):
|
|||||||
self.animation_dot_color = animation_dot_color
|
self.animation_dot_color = animation_dot_color
|
||||||
self.dot_radius = dot_radius
|
self.dot_radius = dot_radius
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def make_forward_pass_animation(self, layer_args={}, run_time=1.5, **kwargs):
|
def make_forward_pass_animation(self, layer_args={}, run_time=1.5, **kwargs):
|
||||||
"""Makes dots diverge from the given location and move the decoder"""
|
"""Makes dots diverge from the given location and move the decoder"""
|
||||||
# Find point to converge on by sampling from gaussian distribution
|
# Find point to converge on by sampling from gaussian distribution
|
||||||
|
@ -30,6 +30,9 @@ class FeedForwardToEmbedding(ConnectiveLayer):
|
|||||||
self.animation_dot_color = animation_dot_color
|
self.animation_dot_color = animation_dot_color
|
||||||
self.dot_radius = dot_radius
|
self.dot_radius = dot_radius
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def make_forward_pass_animation(self, layer_args={}, run_time=1.5, **kwargs):
|
def make_forward_pass_animation(self, layer_args={}, run_time=1.5, **kwargs):
|
||||||
"""Makes dots converge on a specific location"""
|
"""Makes dots converge on a specific location"""
|
||||||
# Find point to converge on by sampling from gaussian distribution
|
# Find point to converge on by sampling from gaussian distribution
|
||||||
|
@ -5,7 +5,6 @@ from manim import *
|
|||||||
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.parent_layers import ConnectiveLayer
|
from manim_ml.neural_network.layers.parent_layers import ConnectiveLayer
|
||||||
|
|
||||||
|
|
||||||
class FeedForwardToFeedForward(ConnectiveLayer):
|
class FeedForwardToFeedForward(ConnectiveLayer):
|
||||||
"""Layer for connecting FeedForward layer to FeedForwardLayer"""
|
"""Layer for connecting FeedForward layer to FeedForwardLayer"""
|
||||||
|
|
||||||
@ -37,6 +36,7 @@ class FeedForwardToFeedForward(ConnectiveLayer):
|
|||||||
self.animation_dot_color = animation_dot_color
|
self.animation_dot_color = animation_dot_color
|
||||||
self.edge_width = edge_width
|
self.edge_width = edge_width
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
self.edges = self.construct_edges()
|
self.edges = self.construct_edges()
|
||||||
self.add(self.edges)
|
self.add(self.edges)
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@ class FeedForwardToImage(ConnectiveLayer):
|
|||||||
self.feed_forward_layer = input_layer
|
self.feed_forward_layer = input_layer
|
||||||
self.image_layer = output_layer
|
self.image_layer = output_layer
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
||||||
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
||||||
animations = []
|
animations = []
|
||||||
|
@ -31,6 +31,9 @@ class FeedForwardToVector(ConnectiveLayer):
|
|||||||
self.feed_forward_layer = input_layer
|
self.feed_forward_layer = input_layer
|
||||||
self.vector_layer = output_layer
|
self.vector_layer = output_layer
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
||||||
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
||||||
animations = []
|
animations = []
|
||||||
|
@ -10,6 +10,7 @@ class ImageLayer(NeuralNetworkLayer):
|
|||||||
|
|
||||||
def __init__(self, numpy_image, height=1.5, show_image_on_create=True, **kwargs):
|
def __init__(self, numpy_image, height=1.5, show_image_on_create=True, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
self.image_height = height
|
||||||
self.numpy_image = numpy_image
|
self.numpy_image = numpy_image
|
||||||
self.show_image_on_create = show_image_on_create
|
self.show_image_on_create = show_image_on_create
|
||||||
|
|
||||||
@ -26,7 +27,10 @@ class ImageLayer(NeuralNetworkLayer):
|
|||||||
if len(np.shape(self.numpy_image)) == 2:
|
if len(np.shape(self.numpy_image)) == 2:
|
||||||
# Assumed Grayscale
|
# Assumed Grayscale
|
||||||
self.num_channels = 1
|
self.num_channels = 1
|
||||||
self.image_mobject = GrayscaleImageMobject(self.numpy_image, height=height)
|
self.image_mobject = GrayscaleImageMobject(
|
||||||
|
self.numpy_image,
|
||||||
|
height=self.image_height
|
||||||
|
)
|
||||||
elif len(np.shape(self.numpy_image)) == 3:
|
elif len(np.shape(self.numpy_image)) == 3:
|
||||||
# Assumed RGB
|
# Assumed RGB
|
||||||
self.num_channels = 3
|
self.num_channels = 3
|
||||||
|
@ -23,6 +23,9 @@ class ImageToConvolutional2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
|
|||||||
self.input_layer = input_layer
|
self.input_layer = input_layer
|
||||||
self.output_layer = output_layer
|
self.output_layer = output_layer
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def make_forward_pass_animation(self, run_time=5, layer_args={}, **kwargs):
|
def make_forward_pass_animation(self, run_time=5, layer_args={}, **kwargs):
|
||||||
"""Maps image to convolutional layer"""
|
"""Maps image to convolutional layer"""
|
||||||
# Transform the image from the input layer to the
|
# Transform the image from the input layer to the
|
||||||
|
@ -31,6 +31,9 @@ class ImageToFeedForward(ConnectiveLayer):
|
|||||||
self.feed_forward_layer = output_layer
|
self.feed_forward_layer = output_layer
|
||||||
self.image_layer = input_layer
|
self.image_layer = input_layer
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
||||||
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
||||||
animations = []
|
animations = []
|
||||||
|
@ -26,14 +26,12 @@ class MaxPooling2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
|
|||||||
self.kernel_size = kernel_size
|
self.kernel_size = kernel_size
|
||||||
self.stride = stride
|
self.stride = stride
|
||||||
self.cell_highlight_color = cell_highlight_color
|
self.cell_highlight_color = cell_highlight_color
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
# Make the output feature maps
|
# Make the output feature maps
|
||||||
feature_maps = self._make_output_feature_maps()
|
feature_maps = self._make_output_feature_maps()
|
||||||
self.add(feature_maps)
|
self.add(feature_maps)
|
||||||
|
|
||||||
def construct_layer(self, input_layer, output_layer):
|
|
||||||
"""Constructs the layer in the context of adjacent layers"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _make_output_feature_maps(self):
|
def _make_output_feature_maps(self):
|
||||||
"""Makes a set of output feature maps"""
|
"""Makes a set of output feature maps"""
|
||||||
# Compute the size of the feature maps
|
# Compute the size of the feature maps
|
||||||
|
@ -22,6 +22,9 @@ class PairedQueryLayer(NeuralNetworkLayer):
|
|||||||
self.add(self.assets)
|
self.add(self.assets)
|
||||||
self.add(self.title)
|
self.add(self.title)
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_paths(cls, positive_path, negative_path, grayscale=True, **kwargs):
|
def from_paths(cls, positive_path, negative_path, grayscale=True, **kwargs):
|
||||||
"""Creates a query using the paths"""
|
"""Creates a query using the paths"""
|
||||||
|
@ -31,6 +31,9 @@ class PairedQueryToFeedForward(ConnectiveLayer):
|
|||||||
self.paired_query_layer = input_layer
|
self.paired_query_layer = input_layer
|
||||||
self.feed_forward_layer = output_layer
|
self.feed_forward_layer = output_layer
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
||||||
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
||||||
animations = []
|
animations = []
|
||||||
|
@ -25,6 +25,8 @@ class TripletLayer(NeuralNetworkLayer):
|
|||||||
|
|
||||||
self.stroke_width = stroke_width
|
self.stroke_width = stroke_width
|
||||||
self.font_size = font_size
|
self.font_size = font_size
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
# Make the assets
|
# Make the assets
|
||||||
self.assets = self.make_assets()
|
self.assets = self.make_assets()
|
||||||
self.add(self.assets)
|
self.add(self.assets)
|
||||||
|
@ -31,6 +31,9 @@ class TripletToFeedForward(ConnectiveLayer):
|
|||||||
self.feed_forward_layer = output_layer
|
self.feed_forward_layer = output_layer
|
||||||
self.triplet_layer = input_layer
|
self.triplet_layer = input_layer
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
|
return super().construct_layer(input_layer, output_layer, **kwargs)
|
||||||
|
|
||||||
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
def make_forward_pass_animation(self, layer_args={}, **kwargs):
|
||||||
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
|
||||||
animations = []
|
animations = []
|
||||||
|
@ -4,7 +4,6 @@ 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 ..layers import connective_layers_list
|
from ..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
|
||||||
@ -24,7 +23,6 @@ def get_connective_layer(input_layer, output_layer):
|
|||||||
warnings.warn(
|
warnings.warn(
|
||||||
f"Unrecognized input/output class pair: {input_class} and {output_class}"
|
f"Unrecognized input/output class pair: {input_class} and {output_class}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Make the instance now
|
# Make the instance now
|
||||||
connective_layer = connective_layer_class(input_layer, output_layer)
|
connective_layer = connective_layer_class(input_layer, output_layer)
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ class VectorLayer(VGroupNeuralNetworkLayer):
|
|||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.num_values = num_values
|
self.num_values = num_values
|
||||||
self.value_func = value_func
|
self.value_func = value_func
|
||||||
|
|
||||||
|
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
|
||||||
# Make the vector
|
# Make the vector
|
||||||
self.vector_label = self.make_vector()
|
self.vector_label = self.make_vector()
|
||||||
self.add(self.vector_label)
|
self.add(self.vector_label)
|
||||||
|
Reference in New Issue
Block a user