在Keras中使用tensorboard可视化acc等曲线
2024-09-23 17:51:10
1.使用tensorboard可视化ACC,loss等曲线
keras.callbacks.TensorBoard(log_dir='./Graph',
histogram_freq= 0 ,
write_graph=True,
write_images=True)
tbCallBack = keras.callbacks.TensorBoard(log_dir='./Graph',
histogram_freq= 0,
write_graph=True,
write_images=True)
…
…
model.compile(optimizer=optim,
loss=MultiboxLoss(NUM_CLASSES, neg_pos_ratio=2.0).compute_loss, metrics=['accuracy'])
nb_epoch = 30
history = model.fit_generator(gen.generate(True), gen.train_batches,
nb_epoch, verbose=1,
callbacks=[tbCallBack],
validation_data=gen.generate(False),
nb_val_samples=gen.val_batches,
nb_worker=1)
然后新开一个终端
输入:
tensorboard --logdir path_to_current_dir/Graph
之后打开终端给出的网址即可。
2.直接使用matplotlib画出训练LOSS与ACC曲线
第一步:
# define the function
def training_vis(hist):
loss = hist.history['loss']
val_loss = hist.history['val_loss']
acc = hist.history['acc']
val_acc = hist.history['val_acc'] # make a figure
fig = plt.figure(figsize=(8,4))
# subplot loss
ax1 = fig.add_subplot(121)
ax1.plot(loss,label='train_loss')
ax1.plot(val_loss,label='val_loss')
ax1.set_xlabel('Epochs')
ax1.set_ylabel('Loss')
ax1.set_title('Loss on Training and Validation Data')
ax1.legend()
# subplot acc
ax2 = fig.add_subplot(122)
ax2.plot(acc,label='train_acc')
ax2.plot(val_acc,label='val_acc')
ax2.set_xlabel('Epochs')
ax2.set_ylabel('Accuracy')
ax2.set_title('Accuracy on Training and Validation Data')
ax2.legend()
plt.tight_layout()
第二步:
# train the model
hist = model.fit(...)
第三步:
# call the function
training_vis(hist)
最新文章
- 编写高质量代码:改善Java程序的151个建议(第8章:异常___建议114~117)
- ViewBag 找不到编译动态表达式所需的一种或多种类型,是否缺少引用?
- elasticsearch rpm 安装
- 关于 MAXScript 拷贝文件夹及内容到其他位置
- LGLProgressHUD
- Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError
- Objective-C:Foundation框架-常用类-NSArray
- 简单说说PHP优化那些事
- SEO名词_黒帽SEO
- tp框架基础知识
- 使用Python下载工具you-get下载媒体文件
- transform:translate(-50%,-50%)实现水平垂直居中
- vue案例todolist备忘录
- 一脸懵逼学习Hive的使用以及常用语法(Hive语法即Hql语法)
- DMA(直接存储器存取)
- 自己写一个java的mvc框架吧(三)
- Mongodb数据结构及与MySql对比
- winform命名规范
- Mysql和sqlite数据库操作心得
- 第9天:原型、继承、函数使用推荐以及this的指向