运行环境:Win10 + anaconda3。
TensorFlow版本:'2.0.0'
import numpy as np
import tensorflow as tf
import tensorflow.keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import matplotlib.pyplot as plt
from tensorflow.keras.callbacks import TensorBoard
X_train = np.random.rand(100)
noise = np.random.normal(0,0.01,X_train.shape)y_train = X_train*0.5+0.2+noiseplt.scatter(X_train, y_train)
plt.show()model = Sequential()
model.add(Dense(1,input_dim = 1))
model.compile(optimizer = 'sgd', loss = 'mse',metrics = ['mae'])model.summary()history = model.fit(X_train,y_train,epochs = 200,verbose=0,callbacks=[TensorBoard(log_dir='mytensorboard')])
W,b = model.layers[0].get_weights()print(W , b)y_pre = model.predict(X_train)plt.plot(X_train,y_pre,'r-',ms = 10,lw = 3)
plt.scatter(X_train,y_train)
随后日志会建立到当前工作目录下的文件夹mytensorboard(如果目前无该文件夹,则会新建该文件夹)
随后打开anaconda prompt,
直接输入:
tensorboard --logdir=工作目录\mytensorboard
回车后会得到一个网址
复制后到浏览器打开即可。
注意路径不能错,不然就打不开了。
使用完毕后在命令行里Ctrl+C即可退出。
具体对于可视化的阅读和模块的更多使用见下面的链接。
参考链接:
https://www.cnblogs.com/ipersevere/p/10843115.html
https://blog.csdn.net/weixin_38517705/article/details/82971147
https://blog.csdn.net/qq_35082030/article/details/94379395
https://www.jianshu.com/p/aa910632be2f
https://blog.csdn.net/dugudaibo/article/details/77961836
https://blog.csdn.net/qq_41872630/article/details/86686236