Finshed adding construct_layer methods for refactor.

This commit is contained in:
Alec Helbling
2023-01-15 16:52:22 +09:00
parent 42b6e37b16
commit 99dbda915b
18 changed files with 60 additions and 11 deletions

View File

@ -286,6 +286,9 @@ class Convolutional2DToConvolutional2D(ConnectiveLayer, ThreeDLayer):
self.show_grid_lines = show_grid_lines
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):
"""
Rotates the shift vectors

View File

@ -26,6 +26,9 @@ class Convolutional2DToFeedForward(ConnectiveLayer, ThreeDLayer):
)
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):
"""Forward pass animation from conv2d to conv2d"""
animations = []

View File

@ -16,11 +16,20 @@ class EmbeddingLayer(VGroupNeuralNetworkLayer):
**kwargs
):
super(VGroupNeuralNetworkLayer, self).__init__(**kwargs)
self.mean = mean
self.covariance = covariance
self.gaussian_distributions = VGroup()
self.add(self.gaussian_distributions)
self.point_radius = point_radius
self.dist_theme = dist_theme
self.paired_query_mode = paired_query_mode
def construct_layer(
self,
input_layer: 'NeuralNetworkLayer',
output_layer: 'NeuralNetworkLayer',
**kwargs
):
self.axes = Axes(
tips=False,
x_length=0.8,
@ -33,11 +42,14 @@ class EmbeddingLayer(VGroupNeuralNetworkLayer):
self.add(self.axes)
self.axes.move_to(self.get_center())
# 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)
# Make latent distribution
self.latent_distribution = GaussianDistribution(
self.axes, mean=mean, cov=covariance
self.axes, mean=self.mean, cov=self.covariance
) # Use defaults
def add_gaussian_distribution(self, gaussian_distribution):

View File

@ -30,6 +30,9 @@ class EmbeddingToFeedForward(ConnectiveLayer):
self.animation_dot_color = animation_dot_color
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):
"""Makes dots diverge from the given location and move the decoder"""
# Find point to converge on by sampling from gaussian distribution

View File

@ -30,6 +30,9 @@ class FeedForwardToEmbedding(ConnectiveLayer):
self.animation_dot_color = animation_dot_color
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):
"""Makes dots converge on a specific location"""
# Find point to converge on by sampling from gaussian distribution

View File

@ -5,7 +5,6 @@ from manim import *
from manim_ml.neural_network.layers.feed_forward import FeedForwardLayer
from manim_ml.neural_network.layers.parent_layers import ConnectiveLayer
class FeedForwardToFeedForward(ConnectiveLayer):
"""Layer for connecting FeedForward layer to FeedForwardLayer"""
@ -37,6 +36,7 @@ class FeedForwardToFeedForward(ConnectiveLayer):
self.animation_dot_color = animation_dot_color
self.edge_width = edge_width
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
self.edges = self.construct_edges()
self.add(self.edges)

View File

@ -31,6 +31,9 @@ class FeedForwardToImage(ConnectiveLayer):
self.feed_forward_layer = input_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):
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
animations = []

View File

@ -31,6 +31,9 @@ class FeedForwardToVector(ConnectiveLayer):
self.feed_forward_layer = input_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):
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
animations = []

View File

@ -10,6 +10,7 @@ class ImageLayer(NeuralNetworkLayer):
def __init__(self, numpy_image, height=1.5, show_image_on_create=True, **kwargs):
super().__init__(**kwargs)
self.image_height = height
self.numpy_image = numpy_image
self.show_image_on_create = show_image_on_create
@ -26,7 +27,10 @@ class ImageLayer(NeuralNetworkLayer):
if len(np.shape(self.numpy_image)) == 2:
# Assumed Grayscale
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:
# Assumed RGB
self.num_channels = 3

View File

@ -23,6 +23,9 @@ class ImageToConvolutional2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
self.input_layer = input_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):
"""Maps image to convolutional layer"""
# Transform the image from the input layer to the

View File

@ -31,6 +31,9 @@ class ImageToFeedForward(ConnectiveLayer):
self.feed_forward_layer = output_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):
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
animations = []

View File

@ -26,14 +26,12 @@ class MaxPooling2DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
self.kernel_size = kernel_size
self.stride = stride
self.cell_highlight_color = cell_highlight_color
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
# Make the output feature maps
feature_maps = self._make_output_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):
"""Makes a set of output feature maps"""
# Compute the size of the feature maps

View File

@ -22,6 +22,9 @@ class PairedQueryLayer(NeuralNetworkLayer):
self.add(self.assets)
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
def from_paths(cls, positive_path, negative_path, grayscale=True, **kwargs):
"""Creates a query using the paths"""

View File

@ -31,6 +31,9 @@ class PairedQueryToFeedForward(ConnectiveLayer):
self.paired_query_layer = input_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):
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
animations = []

View File

@ -25,6 +25,8 @@ class TripletLayer(NeuralNetworkLayer):
self.stroke_width = stroke_width
self.font_size = font_size
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
# Make the assets
self.assets = self.make_assets()
self.add(self.assets)

View File

@ -31,6 +31,9 @@ class TripletToFeedForward(ConnectiveLayer):
self.feed_forward_layer = output_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):
"""Makes dots diverge from the given location and move to the feed forward nodes decoder"""
animations = []

View File

@ -4,7 +4,6 @@ from manim import *
from manim_ml.neural_network.layers.parent_layers import BlankConnective, ThreeDLayer
from ..layers import connective_layers_list
def get_connective_layer(input_layer, output_layer):
"""
Deduces the relevant connective layer
@ -24,7 +23,6 @@ def get_connective_layer(input_layer, output_layer):
warnings.warn(
f"Unrecognized input/output class pair: {input_class} and {output_class}"
)
# Make the instance now
connective_layer = connective_layer_class(input_layer, output_layer)

View File

@ -11,6 +11,8 @@ class VectorLayer(VGroupNeuralNetworkLayer):
super().__init__(**kwargs)
self.num_values = num_values
self.value_func = value_func
def construct_layer(self, input_layer: 'NeuralNetworkLayer', output_layer: 'NeuralNetworkLayer', **kwargs):
# Make the vector
self.vector_label = self.make_vector()
self.add(self.vector_label)