Used Black to reformat the code in the repository.

This commit is contained in:
Alec Helbling
2023-01-01 23:24:59 -05:00
parent 334662e8c8
commit 3d6e8072e1
71 changed files with 1701 additions and 1135 deletions

View File

@ -3,25 +3,27 @@ import numpy as np
from manim import *
from manim_ml.neural_network.layers.convolutional3d import Convolutional3DLayer
from manim_ml.neural_network.layers.image import ImageLayer
from manim_ml.neural_network.layers.parent_layers import ThreeDLayer, VGroupNeuralNetworkLayer
from manim_ml.neural_network.layers.parent_layers import (
ThreeDLayer,
VGroupNeuralNetworkLayer,
)
from manim_ml.gridded_rectangle import GriddedRectangle
class ImageToConvolutional3DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
"""Handles rendering a convolutional layer for a nn"""
input_class = ImageLayer
output_class = Convolutional3DLayer
def __init__(self, input_layer: ImageLayer, output_layer: Convolutional3DLayer, **kwargs):
def __init__(
self, input_layer: ImageLayer, output_layer: Convolutional3DLayer, **kwargs
):
super().__init__(input_layer, output_layer, **kwargs)
self.input_layer = input_layer
self.output_layer = output_layer
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"""
# Transform the image from the input layer to the
num_image_channels = self.input_layer.num_channels
@ -30,7 +32,9 @@ class ImageToConvolutional3DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
elif num_image_channels == 1:
return self.grayscale_image_animation()
else:
raise Exception(f"Unrecognized number of image channels: {num_image_channels}")
raise Exception(
f"Unrecognized number of image channels: {num_image_channels}"
)
def rbg_image_animation(self):
"""Handles animation for 3 channel image"""
@ -53,7 +57,7 @@ class ImageToConvolutional3DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
ThreeDLayer.rotation_angle,
ThreeDLayer.rotation_axis,
image_mobject.get_center(),
run_time=0.5
run_time=0.5,
)
"""
x_rotation = ApplyMethod(
@ -72,25 +76,14 @@ class ImageToConvolutional3DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
)
"""
# Set opacity
set_opacity = ApplyMethod(
image_mobject.set_opacity,
0.2,
run_time=0.5
)
# Scale the max of width or height to the
set_opacity = ApplyMethod(image_mobject.set_opacity, 0.2, run_time=0.5)
# Scale the max of width or height to the
# width of the feature_map
max_width_height = max(image_mobject.width, image_mobject.height)
scale_factor = target_feature_map.rectangle_width / max_width_height
scale_image = ApplyMethod(
image_mobject.scale,
scale_factor,
run_time=0.5
)
scale_image = ApplyMethod(image_mobject.scale, scale_factor, run_time=0.5)
# Move the image
move_image = ApplyMethod(
image_mobject.move_to,
target_feature_map
)
move_image = ApplyMethod(image_mobject.move_to, target_feature_map)
# Compose the animations
animation = Succession(
rotation,
@ -99,10 +92,10 @@ class ImageToConvolutional3DLayer(VGroupNeuralNetworkLayer, ThreeDLayer):
move_image,
)
return animation
def scale(self, scale_factor, **kwargs):
super().scale(scale_factor, **kwargs)
@override_animation(Create)
def _create_override(self, **kwargs):
return AnimationGroup()
return AnimationGroup()