入門tensorflow教程之TensorBoard可視化模型訓練
TensorBoard是用于可視化圖形
和其他工具以理解、調(diào)試和優(yōu)化模型的界面。
它是一種為機器學習工作流提供測量和可視化的工具。
它有助于跟蹤損失和準確性、模型圖可視化、低維空間中的項目嵌入等指標。
下面,我們使用MNIST 數(shù)據(jù)的圖像分類模型 ,將首先導入所需的庫并加載數(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 訓練模型時,
創(chuàng)建了一個 tensorboard 回調(dià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擴展程序
%load_ext tensorboard %tensorboard --logdir logs/fit from tensorboard import notebook notebook.list notebook.display(port=6006, height=1000)
如果訓練迭代5k到55k,
TensorBoard會給出測試集的大概結(jié)果
如果在torch中是使用TensorBoard,在PyTorch 1.8.1 版本的發(fā)布,需要使用 PyTorch Profiler,
需要安裝torch_tb_profiler
。
torch_tb_profiler
是TensorBoard
的一個插件,可以可視化GPU的情況,
具體參考官方教程
https://pytorch.org/tutorials/intermediate/tensorboard_profiler_tutorial.html
https://github.com/pytorch/kineto/tree/main/tb_plugin
到此這篇關(guān)于小白入門學習TensorBoard可視化模型訓練的文章就介紹到這了,更多相關(guān)TensorBoard可視化模型訓練內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python使用moviepy讀取字幕srt文件報錯的解決方法詳解
這篇文章主要為大家詳細介紹了Python使用moviepy讀取字幕srt文件報錯‘gbk‘?codec?can‘t?decode的兩種解決辦法,有需要的小伙伴可以跟隨小編一起學習一下2024-01-01python 使用Tensorflow訓練BP神經(jīng)網(wǎng)絡實現(xiàn)鳶尾花分類
這篇文章主要介紹了python 使用Tensorflow訓練BP神經(jīng)網(wǎng)絡實現(xiàn)鳶尾花分類,幫助大家更好的利用python進行深度學習,感興趣的朋友可以了解下2021-05-05利用Python對文件夾下圖片數(shù)據(jù)進行批量改名的代碼實例
今天小編就為大家分享一篇關(guān)于利用Python對文件夾下圖片數(shù)據(jù)進行批量改名的代碼實例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-02-02win7上tensorflow2.2.0安裝成功 引用DLL load failed時找不到指定模塊 tensorflo
這篇文章主要介紹了win7上tensorflow2.2.0安裝成功 引用時DLL load failed找不到指定模塊 tensorflow has no attribute xxx 解決方法,需要的朋友可以參考下2020-05-05