tensorflow可视化Keras框架中Tensorboard使用示例
作者:Bubbliiiing 时间:2023-08-09 01:39:27
Tensorboard详解
该类在存放在keras.callbacks模块中。拥有许多参数,主要的参数如下:
1、log_dir: 用来保存Tensorboard的日志文件等内容的位置
2、histogram_freq: 对于模型中各个层计算激活值和模型权重直方图的频率。
3、write_graph: 是否在 TensorBoard 中可视化图像。
4、write_grads: 是否在 TensorBoard 中可视化梯度值直方图。
5、batch_size: 用以直方图计算的传入神经元网络输入批的大小。
6、write_images: 是否在 TensorBoard中将模型权重以图片可视化。
7、update_freq: 常用的三个值为’batch’ 、 ‘epoch’ 或 整数。当使用 ‘batch’ 时,在每个 batch 之后将损失和评估值写入到 TensorBoard 中。 ‘epoch’ 类似。如果使用整数,会在每一定个样本之后将损失和评估值写入到 TensorBoard 中。
默认值如下:
log_dir='./logs', # 默认保存在当前文件夹下的logs文件夹之下
histogram_freq=0,
batch_size=32,
write_graph=True, #默认是True,默认是显示graph的。
write_grads=False,
write_images=False,
update_freq='epoch'
使用例子
以手写体为例子,我们打开histogram_freq和write_grads,也就是在Tensorboard中保存权值直方图和梯度直方图。
打开CMD,利用tensorboard --logdir=logs生成tensorboard观测网页。
1、loss和acc
2、权值直方图
3、梯度直方图
实现代码
import numpy as np
from keras.layers import Input, Dense, Dropout, Activation,Conv2D,MaxPool2D,Flatten
from keras.datasets import mnist
from keras.models import Model
from keras.utils import to_categorical
from keras.callbacks import TensorBoard
if __name__=="__main__":
(x_train,y_train),(x_test,y_test) = mnist.load_data()
x_train=np.expand_dims(x_train,axis=-1)
x_test=np.expand_dims(x_test,axis=-1)
y_train=to_categorical(y_train,num_classes=10)
y_test=to_categorical(y_test,num_classes=10)
batch_size=128
epochs=10
inputs = Input([28,28,1])
x = Conv2D(32, (5,5), activation='relu')(inputs)
x = Conv2D(64, (5,5), activation='relu')(x)
x = MaxPool2D(pool_size=(2,2))(x)
x = Flatten()(x)
x = Dense(128, activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(10, activation='softmax')(x)
model = Model(inputs,x)
model.compile(loss='categorical_crossentropy', optimizer="adam",metrics=['acc'])
Tensorboard= TensorBoard(log_dir="./model", histogram_freq=1,write_grads=True)
history=model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, shuffle=True, validation_split=0.2,callbacks=[Tensorboard])
来源:https://blog.csdn.net/weixin_44791964/article/details/105002793
标签:tensorflow,Keras,Tensorboard,可视化
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
thinkphp学习笔记之多表查询
2023-11-15 02:57:15
Goland项目使用gomod配置的详细步骤
2024-04-26 17:35:34
![](https://img.aspxhome.com/file/2023/4/133944_0s.png)
Python eval的常见错误封装及利用原理详解
2021-06-11 22:38:42
vue.js 图片上传并预览及图片更换功能的实现代码
2024-05-09 15:23:47
![](https://img.aspxhome.com/file/2023/8/126428_0s.png)
pandas实现一行拆分成多行
2021-09-19 16:22:37
![](https://img.aspxhome.com/file/2023/3/88973_0s.png)
Dreamweaver初学者常见问题解答
2007-02-03 11:39:00
Python协程实践分享
2023-09-01 05:50:51
![](https://img.aspxhome.com/file/2023/5/62875_0s.png)
Python数据分析之使用scikit-learn构建模型
2023-11-10 23:19:10
![](https://img.aspxhome.com/file/2023/5/64365_0s.jpg)
在Python中的Django框架中进行字符串翻译
2022-11-04 09:39:03
js实现九宫格抽奖
2024-04-17 10:34:36
python实战练习做一个随机点名的程序
2022-06-16 07:42:31
![](https://img.aspxhome.com/file/2023/8/77768_0s.png)
使用Python进行中文繁简转换的实现代码
2021-05-04 09:19:03
ASP.NET State service状态服务的问题解决方法
2023-06-25 15:02:15
vue3的watch用法以及和vue2中watch的区别
2024-04-30 08:42:37
![](https://img.aspxhome.com/file/2023/6/132996_0s.png)
Python实现简易端口扫描器代码实例
2022-08-07 16:58:24
![](https://img.aspxhome.com/file/2023/5/84895_0s.png)
Python网络编程之ZeroMQ知识总结
2022-07-06 20:16:25
![](https://img.aspxhome.com/file/2023/6/115006_0s.png)
python实现朴素贝叶斯分类器
2022-12-05 03:35:50
python字符串的一些常见实用操作
2022-05-08 15:53:30
![](https://img.aspxhome.com/file/2023/5/71375_0s.gif)
Python实现Matplotlib,Seaborn动态数据图的示例代码
2023-02-03 23:47:22
![](https://img.aspxhome.com/file/2023/5/77745_0s.gif)
无法通过Google网站管理工具验证的部分情况解决办法
2009-07-28 12:56:00