模型的编译过程 model.fit
输出为模型的参数变化,将其输入至train_log
,再通过train_log.history
读取相应值。其中epochs指训练次数。
train_log = model.fit_generator( train_generator, steps_per_epoch = nb_train_samples // batch_size, epochs = epochs, validation_data = validation_generator, validation_steps =nb_validation_samples // batch_size, ) # plot the training loss and accuracy plt.style.use("ggplot") plt.figure() plt.plot(np.arange(0, epochs), train_log.history["loss"], label="train_loss") plt.plot(np.arange(0, epochs), train_log.history["val_loss"], label="val_loss") plt.plot(np.arange(0, epochs), train_log.history["acc"], label="train_acc") plt.plot(np.arange(0, epochs), train_log.history["val_acc"], label="val_acc") plt.title("Training Loss and Accuracy on sar classifier") plt.xlabel("Epoch #") plt.ylabel("Loss/Accuracy") plt.legend(loc="upper right") plt.savefig("Loss_Accuracy_alexnet_{:d}e.jpg".format(epochs))
# -*- coding: utf-8 -*- import pandas as pd import matplotlib.pyplot as plt log = pd.read_csv('./log/mix_r40_g800_log_0511160953_300e.csv') l = list(log['epoch;acc;loss;val_acc;val_loss']) epoch = [] acc = [] loss = [] val_acc = [] val_loss = [] for i in range(0,len(l)): epoch.append(l[i].split(';')[0]) acc.append(l[i].split(';')[1]) loss.append(l[i].split(';')[2]) val_acc.append(l[i].split(';')[3]) val_loss.append(l[i].split(';')[4]) plt.style.use("ggplot") #设置绘图风格 plt.figure(figsize=(15,10)) #设置绘图大小,单位inch plt.plot(epoch, loss, label="train_loss") plt.plot(epoch, val_loss, label="val_loss") plt.plot(epoch, acc, label="train_acc") plt.plot(epoch, val_acc, label="val_acc") plt.title("Training Loss and Accuracy on sar classifier") plt.xlabel("Epoch #") plt.ylabel("Loss/Accuracy") plt.legend(loc="upper right") plt.savefig("Loss_Accuracy_mix_40-800_300e.jpg")