Initial commit
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,41 @@
|
||||
from abc import ABC
|
||||
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
from neural_net.epoch import Epoch
|
||||
from neural_net.neural_net import NeuralNet
|
||||
from ui.components.plot_figure import PlotFrame
|
||||
from ui.plotters.plotter import Plotter
|
||||
|
||||
class GradientsPlot(PlotFrame):
|
||||
def __init__(self, parent, neural_net: NeuralNet):
|
||||
super().__init__(parent)
|
||||
self.plotter = GradientsPlotter(self.figure, neural_net)
|
||||
|
||||
class GradientsPlotter(Plotter, ABC):
|
||||
def __init__(self, figure: Figure, neural_net: NeuralNet):
|
||||
super().__init__(figure)
|
||||
self.neural_net = neural_net
|
||||
self.axes = figure.subplots(1, 2)
|
||||
|
||||
def reset_plot(self):
|
||||
self.axes[0].clear()
|
||||
self.axes[0].set_xlabel('Neuron Index')
|
||||
self.axes[0].set_ylabel('Input Index')
|
||||
self.axes[1].clear()
|
||||
self.axes[1].set_xlabel('Output Neuron Index')
|
||||
self.axes[1].set_ylabel('Hidden Neuron Index')
|
||||
|
||||
def plot(self, data: Epoch):
|
||||
gradients_layer1 = data.layer_dl_gradients[1][-1]
|
||||
self.axes[0].imshow(gradients_layer1, cmap='coolwarm', aspect='auto')
|
||||
|
||||
gradients_layer2 = data.layer_dl_gradients[0][-1]
|
||||
self.axes[1].imshow(gradients_layer2, cmap='coolwarm', aspect='auto')
|
||||
|
||||
def plot_gradients_histogram(self, current_epoch: Epoch):
|
||||
gradients_layer1 = current_epoch.layer_dl_gradients[1][-1]
|
||||
self.axes[0].hist(gradients_layer1.flatten(), bins=50, color='blue', alpha=0.7)
|
||||
|
||||
gradients_layer2 = current_epoch.layer_dl_gradients[0][-1]
|
||||
self.axes[1].hist(gradients_layer2.flatten(), bins=50, color='green', alpha=0.7)
|
||||
@@ -0,0 +1,39 @@
|
||||
from ui.components.plot_figure import PlotFrame
|
||||
import math
|
||||
from abc import ABC
|
||||
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
from neural_net.activation_layers.activation_layer import ActivationLayer
|
||||
from neural_net.neural_net import NeuralNet
|
||||
from ui.plotters.plotter import Plotter
|
||||
from utils.matplotlib.utils import mpl_matshow
|
||||
|
||||
class LayerWeightsPlot(PlotFrame):
|
||||
def __init__(self, parent, neural_net: NeuralNet, layer: ActivationLayer, rows, cols):
|
||||
super().__init__(parent)
|
||||
self.plotter = LayerWeightsPlotter(self.figure, neural_net, layer, rows, cols)
|
||||
|
||||
class LayerWeightsPlotter(Plotter, ABC):
|
||||
def __init__(self, figure: Figure, neural_net: NeuralNet, layer: ActivationLayer, rows, columns):
|
||||
super().__init__(figure)
|
||||
self.neural_net = neural_net
|
||||
self.layer = layer
|
||||
self.axes = figure.subplots(nrows=rows, ncols=columns, squeeze=True,
|
||||
gridspec_kw={'wspace': 0.05, 'hspace': 0.05})
|
||||
|
||||
def reset_plot(self):
|
||||
for axes in self.axes:
|
||||
for ax in axes:
|
||||
ax.clear()
|
||||
|
||||
def plot(self, data):
|
||||
weights = self.layer.weights.T
|
||||
n_neurons = weights.shape[0]
|
||||
n_pixels = weights.shape[1]
|
||||
for i in range(n_neurons):
|
||||
row = i // self.axes.shape[1]
|
||||
col = i % self.axes.shape[1]
|
||||
mpl_matshow(self.axes[row, col], weights[i], int(math.sqrt(n_pixels)))
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
from neural_net.trainer import NeuralNetTrainer
|
||||
from ui.components.plot_figure import PlotFrame
|
||||
|
||||
from abc import ABC
|
||||
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
from neural_net.neural_net import NeuralNet
|
||||
from ui.plotters.plotter import Plotter
|
||||
|
||||
class LossPlot(PlotFrame):
|
||||
def __init__(self, parent, neural_net: NeuralNet, trainer: NeuralNetTrainer):
|
||||
super().__init__(parent)
|
||||
self.plotter = LossPlotter(self.figure, neural_net, trainer)
|
||||
|
||||
class LossPlotter(Plotter, ABC):
|
||||
def __init__(self, figure: Figure, neural_net: NeuralNet, trainer: NeuralNetTrainer):
|
||||
super().__init__(figure)
|
||||
self.neural_net = neural_net
|
||||
self.trainer = trainer
|
||||
self.axes = figure.add_subplot()
|
||||
|
||||
def reset_plot(self):
|
||||
self.axes.clear()
|
||||
self.axes.set_title('Loss')
|
||||
self.axes.set_ylabel("Loss")
|
||||
self.axes.set_xlabel("Epoch")
|
||||
|
||||
def plot(self, data):
|
||||
losses = []
|
||||
for epoch in self.trainer.epoch_history:
|
||||
if epoch.finished:
|
||||
losses.append(epoch.loss)
|
||||
|
||||
self.axes.plot(losses, marker='o', label=f"Loss")
|
||||
for idx, loss in enumerate(losses):
|
||||
self.axes.annotate(f"{loss:.4f}", xy=(idx, loss), rotation=45)
|
||||
|
||||
self.axes.legend()
|
||||
self.axes.grid(True)
|
||||
@@ -0,0 +1,37 @@
|
||||
from ui.components.plot_figure import PlotFrame
|
||||
from abc import ABC
|
||||
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
from ui.plotters.plotter import Plotter
|
||||
|
||||
class PredictionsPlot(PlotFrame):
|
||||
def __init__(self, parent):
|
||||
super().__init__(parent, height=32)
|
||||
self.plotter = PredictionsPlotter(self.figure)
|
||||
|
||||
class PredictionsPlotter(Plotter, ABC):
|
||||
def __init__(self, figure: Figure):
|
||||
super().__init__(figure)
|
||||
self.axes = figure.add_subplot()
|
||||
self.clean_axes()
|
||||
|
||||
def plot(self, data):
|
||||
self.axes.imshow(data, cmap='coolwarm', aspect='auto')
|
||||
for idx in range(10):
|
||||
self.axes.annotate(f"{idx}", xy=(idx - 0.2, 0.2))
|
||||
self.clean_axes()
|
||||
|
||||
def clean_axes(self):
|
||||
# Remove axis ticks, labels, and spines
|
||||
self.axes.set_xticks([]) # Remove x-ticks
|
||||
self.axes.set_yticks([]) # Remove y-ticks
|
||||
self.axes.spines['top'].set_visible(False)
|
||||
self.axes.spines['bottom'].set_visible(False)
|
||||
self.axes.spines['left'].set_visible(False)
|
||||
self.axes.spines['right'].set_visible(False)
|
||||
self.axes.set_facecolor((0, 0, 0))
|
||||
|
||||
def reset_plot(self):
|
||||
self.axes.clear()
|
||||
|
||||
Reference in New Issue
Block a user