入門tensorflow教程之TensorBoard可視化模型訓(xùn)練
TensorBoard是用于可視化圖形
和其他工具以理解、調(diào)試和優(yōu)化模型的界面。
它是一種為機(jī)器學(xué)習(xí)工作流提供測(cè)量和可視化的工具。
它有助于跟蹤損失和準(zhǔn)確性、模型圖可視化、低維空間中的項(xiàng)目嵌入等指標(biāo)。
下面,我們使用MNIST 數(shù)據(jù)的圖像分類模型 ,將首先導(dǎo)入所需的庫(kù)并加載數(shù)據(jù)集。
模型的建立使用最簡(jiǎn)單的順序模型
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
,并不支持使用終端
對(duì)于 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會(huì)給出測(cè)試集的大概結(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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用tensorflow實(shí)現(xiàn)線性svm
這篇文章主要為大家詳細(xì)介紹了使用tensorflow實(shí)現(xiàn)線性svm的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-09-09Python使用moviepy讀取字幕srt文件報(bào)錯(cuò)的解決方法詳解
這篇文章主要為大家詳細(xì)介紹了Python使用moviepy讀取字幕srt文件報(bào)錯(cuò)‘gbk‘?codec?can‘t?decode的兩種解決辦法,有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01python 使用Tensorflow訓(xùn)練BP神經(jīng)網(wǎng)絡(luò)實(shí)現(xiàn)鳶尾花分類
這篇文章主要介紹了python 使用Tensorflow訓(xùn)練BP神經(jīng)網(wǎng)絡(luò)實(shí)現(xiàn)鳶尾花分類,幫助大家更好的利用python進(jìn)行深度學(xué)習(xí),感興趣的朋友可以了解下2021-05-05利用Python對(duì)文件夾下圖片數(shù)據(jù)進(jìn)行批量改名的代碼實(shí)例
今天小編就為大家分享一篇關(guān)于利用Python對(duì)文件夾下圖片數(shù)據(jù)進(jìn)行批量改名的代碼實(shí)例,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02win7上tensorflow2.2.0安裝成功 引用DLL load failed時(shí)找不到指定模塊 tensorflo
這篇文章主要介紹了win7上tensorflow2.2.0安裝成功 引用時(shí)DLL load failed找不到指定模塊 tensorflow has no attribute xxx 解決方法,需要的朋友可以參考下2020-05-05