入門tensorflow教程之TensorBoard可視化模型訓(xùn)練
TensorBoard是用于可視化圖形
和其他工具以理解、調(diào)試和優(yōu)化模型的界面。
它是一種為機(jī)器學(xué)習(xí)工作流提供測量和可視化的工具。
它有助于跟蹤損失和準(zhǔn)確性、模型圖可視化、低維空間中的項(xiàng)目嵌入等指標(biāo)。
下面,我們使用MNIST 數(shù)據(jù)的圖像分類模型 ,將首先導(dǎo)入所需的庫并加載數(shù)據(jù)集。
模型的建立使用最簡單的順序模型
import tensorflow as tf
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.mnist.load_data()
from tensorflow.keras.utils import np_utils
X_train=X_train.astype('float32')
X_test=X_test.astype('float32')
X_train/=255
X_test/=255
X_train = X_train.reshape(X_train.shape[0], 28, 28, 1).astype('float32')
X_test = X_test.reshape(X_test.shape[0], 28, 28, 1).astype('float32')
y_train = np_utils.to_categorical(y_train, 10)
y_test = np_utils.to_categorical(y_test, 10)
model = Sequential()
model.add(Convolution2D(32, 3, 3, input_shape=(28, 28, 1)))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Convolution2D(32, 3, 3))
model.add(Activation('relu'))
model.add(Convolution2D(32, 3, 3))
model.add(Activation('relu'))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128))
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dense(10))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
keras API 訓(xùn)練模型時(shí),
創(chuàng)建了一個(gè) tensorboard 回調(diào)
以確保將指標(biāo)記錄在指定的目錄中。
這里保存到logs/fit
import datetime
!rm -rf ./logs/
log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback=tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
model.fit(x=X_train, y=y_train,epochs=30,validation_data=(X_test, y_test), callbacks=[tensorboard_callback])

如果使用colab,并不支持使用終端
對于 Windows 用戶:tensorboard --logdir= logs/fitg
Tensorboard 位于:http://localhost:6006
如果使用colab,需要加載TensorBoard擴(kuò)展程序
%load_ext tensorboard %tensorboard --logdir logs/fit from tensorboard import notebook notebook.list notebook.display(port=6006, height=1000)


如果訓(xùn)練迭代5k到55k,
TensorBoard會給出測試集的大概結(jié)果

如果在torch中是使用TensorBoard,在PyTorch 1.8.1 版本的發(fā)布,需要使用 PyTorch Profiler,
需要安裝torch_tb_profiler。
torch_tb_profiler是TensorBoard的一個(gè)插件,可以可視化GPU的情況,
具體參考官方教程
https://pytorch.org/tutorials/intermediate/tensorboard_profiler_tutorial.html
https://github.com/pytorch/kineto/tree/main/tb_plugin
到此這篇關(guān)于小白入門學(xué)習(xí)TensorBoard可視化模型訓(xùn)練的文章就介紹到這了,更多相關(guān)TensorBoard可視化模型訓(xùn)練內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python實(shí)現(xiàn)二次元圖片展示(屏保)
這篇文章主要介紹了python實(shí)現(xiàn)二次元圖片展示,用了API端口相關(guān)的知識實(shí)現(xiàn),下面詳細(xì)的文章內(nèi)容需要的小伙伴可以參考一下2022-02-02
python GUI實(shí)現(xiàn)小球滿屏亂跑效果
這篇文章主要為大家詳細(xì)介紹了python GUI實(shí)現(xiàn)小球滿屏亂跑效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05
使用python實(shí)現(xiàn)個(gè)性化詞云的方法
最近看到可視化的詞云,看到網(wǎng)上也很多這樣的工具,但是都不怎么完美,有些不支持中文,有的中文詞頻統(tǒng)計(jì)得莫名其妙、有的不支持自定義形狀、所有的都不能自定義顏色,于是網(wǎng)上找了一下,決定用python繪制詞云2017-06-06
python 用Matplotlib作圖中有多個(gè)Y軸
這篇文章主要介紹了python 如何用Matplotlib作圖中有多個(gè)Y軸,幫助大家更好的利用python繪圖,感興趣的朋友可以了解下2020-11-11
Python基于BeautifulSoup和requests實(shí)現(xiàn)的爬蟲功能示例
這篇文章主要介紹了Python基于BeautifulSoup和requests實(shí)現(xiàn)的爬蟲功能,結(jié)合實(shí)例形式分析了Python使用BeautifulSoup和requests庫爬取網(wǎng)站指定信息的相關(guān)操作技巧,需要的朋友可以參考下2019-08-08
python實(shí)現(xiàn)向微信用戶發(fā)送每日一句 python實(shí)現(xiàn)微信聊天機(jī)器人
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)向微信用戶發(fā)送每日一句,python調(diào)實(shí)現(xiàn)微信聊天機(jī)器人,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-03-03
基于python實(shí)現(xiàn)計(jì)算且附帶進(jìn)度條代碼實(shí)例
這篇文章主要介紹了基于python實(shí)現(xiàn)計(jì)算且附帶進(jìn)度條代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
python Selenium爬取內(nèi)容并存儲至MySQL數(shù)據(jù)庫的實(shí)現(xiàn)代碼
這篇文章主要介紹了python Selenium爬取內(nèi)容并存儲至MySQL數(shù)據(jù)庫的實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-03-03
Python中Django框架下的staticfiles使用簡介
這篇文章主要介紹了Python中Django框架下的staticfiles使用簡介,staticfiles是一個(gè)幫助Django管理靜態(tài)資源的工具,需要的朋友可以參考下2015-05-05

