想要查看每次训练模型后的 loss 值变化需要如下操作
loss_value= [ ] self.history = model.fit(state,target_f,epochs=1, batch_size =32) b = abs(float(self.history.history[‘loss'][0])) loss_value.append(b) print(loss_value) loss_value = np.array( loss_value) x = np.array(range(len( loss_value))) plt.plot(x, loss_value, c = ‘g') pt.svefit('c地址‘, dpi= 100) plt.show()
scipy.sparse 稀疏矩阵 函数集合
pandas 用于在各种文件中提取,并处理分析数据; 有DataFrame数据结构,类似表格。
x=np.linspace(-10, 10, 100) 生成100个在-10到10之间的数组
补充知识:对keras训练过程中loss,val_loss,以及accuracy,val_accuracy的可视化
我就废话不多说了,大家还是直接看代码吧!
hist = model.fit_generator(generator=data_generator_reg(X=x_train, Y=[y_train_a,y_train_g], batch_size=batch_size), steps_per_epoch=train_num // batch_size, validation_data=(x_test, [y_test_a,y_test_g]), epochs=nb_epochs, verbose=1, workers=8, use_multiprocessing=True, callbacks=callbacks) logging.debug("Saving weights...") model.save_weights(os.path.join(db_name+"_models/"+save_name, save_name+'.h5'), overwrite=True) pd.DataFrame(hist.history).to_hdf(os.path.join(db_name+"_models/"+save_name, 'history_'+save_name+'.h5'), "history")
在训练时,会输出如下打印:
640/640 [==============================] - 35s 55ms/step - loss: 4.0216 - mean_absolute_error: 4.6525 - val_loss: 3.2888 - val_mean_absolute_error: 3.9109
有训练loss,训练预测准确度,以及测试loss,以及测试准确度,将文件保存后,使用下面的代码可以对训练以及评估进行可视化,下面有对应的参数名称:
loss,mean_absolute_error,val_loss,val_mean_absolute_error
import pandas as pd import matplotlib.pyplot as plt import argparse import os import numpy as np def get_args(): parser = argparse.ArgumentParser(description="This script shows training graph from history file.") parser.add_argument("--input", "-i", type=str, required=True, help="path to input history h5 file") args = parser.parse_args() return args def main(): args = get_args() input_path = args.input df = pd.read_hdf(input_path, "history") print(np.min(df['val_mean_absolute_error'])) input_dir = os.path.dirname(input_path) plt.plot(df["loss"], '-o', label="loss (age)", linewidth=2.0) plt.plot(df["val_loss"], '-o', label="val_loss (age)", linewidth=2.0) plt.xlabel("Number of epochs", fontsize=20) plt.ylabel("Loss", fontsize=20) plt.legend() plt.grid() plt.savefig(os.path.join(input_dir, "loss.pdf"), bbox_inches='tight', pad_inches=0) plt.cla() plt.plot(df["mean_absolute_error"], '-o', label="training", linewidth=2.0) plt.plot(df["val_mean_absolute_error"], '-o', label="validation", linewidth=2.0) ax = plt.gca() ax.set_ylim([2,13]) ax.set_aspect(0.6/ax.get_data_ratio()) plt.xticks(fontsize=20) plt.yticks(fontsize=20) plt.xlabel("Number of epochs", fontsize=20) plt.ylabel("Mean absolute error", fontsize=20) plt.legend(fontsize=20) plt.grid() plt.savefig(os.path.join(input_dir, "performance.pdf"), bbox_inches='tight', pad_inches=0) if __name__ == '__main__': main()
以上这篇在keras中实现查看其训练loss值就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 群星《前途海量 电影原声专辑》[FLAC/分轨][227.78MB]
- 张信哲.1992-知道新曲与精丫巨石】【WAV+CUE】
- 王翠玲.1995-ANGEL【新艺宝】【WAV+CUE】
- 景冈山.1996-我的眼里只有你【大地唱片】【WAV+CUE】
- 群星《八戒 电影原声带》[320K/MP3][188.97MB]
- 群星《我的阿勒泰 影视原声带》[320K/MP3][139.47MB]
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[320K/MP3][148.91MB]
- 刘雅丽.2001-丽花皇后·EMI精选王【EMI百代】【FLAC分轨】
- 齐秦.1994-黄金十年1981-1990CHINA.TOUR.LIVE精丫上华】【WAV+CUE】
- 群星.2008-本色·百代音乐人创作专辑【EMI百代】【WAV+CUE】
- 群星.2001-同步过冬AVCD【环球】【WAV+CUE】
- 群星.2020-同步过冬2020冀待晴空【环球】【WAV+CUE】
- 沈雁.1986-四季(2012梦田复刻版)【白云唱片】【WAV+CUE】
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[FLAC/分轨][257.88MB]
- 《国语老歌 怀旧篇 3CD》[WAV/分轨][1.6GB]