<reponame>MichalMucek/PSI-Projekt-Adult-ASD<gh_stars>0
from keras.callbacks import Callback
from matplotlib import pyplot as plt


class PlotLearning(Callback):
    def on_train_begin(self, logs={}):
        self.i = 0
        self.x = []
        self.losses = []
        self.val_losses = []
        self.acc = []
        self.val_acc = []
        self.fig = plt.figure()

        self.logs = []

    def on_epoch_end(self, epoch, logs={}):
        self.logs.append(logs)
        self.x.append(self.i)
        self.losses.append(logs.get('loss'))
        self.val_losses.append(logs.get('val_loss'))
        self.acc.append(logs.get('acc'))
        self.val_acc.append(logs.get('val_acc'))
        self.i += 1

        f, (ax1, ax2) = plt.subplots(1, 2, sharex='all', figsize=(40, 16), dpi=80)

        ax1.set_yscale('log')
        ax1.plot(self.x, self.losses, label="loss")
        ax1.plot(self.x, self.val_losses, label="val_loss")
        ax1.legend()

        ax2.plot(self.x, self.acc, label="accuracy")
        ax2.plot(self.x, self.val_acc, label="validation accuracy")
        ax2.legend()

        # plt.savefig('foo.png')
        # plt.show()

    def on_train_end(self, logs=None):
        plt.savefig('foo.pdf', bbox_inches='tight')

from keras.callbacks import Callback
from matplotlib import pyplot as plt


class PlotLearning(Callback):
    def on_train_begin(self, logs={}):
        self.i = 0
        self.x = []
        self.losses = []
        self.val_losses = []
        self.acc = []
        self.val_acc = []
        self.fig = plt.figure()

        self.logs = []

    def on_epoch_end(self, epoch, logs={}):
        self.logs.append(logs)
        self.x.append(self.i)
        self.losses.append(logs.get('loss'))
        self.val_losses.append(logs.get('val_loss'))
        self.acc.append(logs.get('acc'))
        self.val_acc.append(logs.get('val_acc'))
        self.i += 1

        f, (ax1, ax2) = plt.subplots(1, 2, sharex='all', figsize=(40, 16), dpi=80)

        ax1.set_yscale('log')
        ax1.plot(self.x, self.losses, label="loss")
        ax1.plot(self.x, self.val_losses, label="val_loss")
        ax1.legend()

        ax2.plot(self.x, self.acc, label="accuracy")
        ax2.plot(self.x, self.val_acc, label="validation accuracy")
        ax2.legend()

        # plt.savefig('foo.png')
        # plt.show()

    def on_train_end(self, logs=None):
        plt.savefig('foo.pdf', bbox_inches='tight')
# plt.savefig('foo.png') # plt.show()