关于Tensorboard的使用

要点:
导入:from keras.callbacks import TensorBoard
首尾呼应: 在fit()里加入 callbacks=[TensorBoard(log_dir='/Users/mikegao/tensorlog')]
这个就是你的tensorboard需要保存的记录文件位置,读取的时候也从这里读取

完整代码如下: 基于minst
训练完成!

然后在 命令行 tensorboard --logdir=“目录’” 《----注意要使用双引号!!!!
得到一个链接,打开就看到啦!

import numpy as np
from keras.datasets import mnist
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import Convolution2D, Activation, MaxPool2D, Flatten, Dense
from keras.optimizers import Adam
from keras.callbacks import TensorBoard #要点!!!

nb_class = 10
nb_epoch = 2
batchsize = 1024

(X_train,Y_train),(X_test,Y_test) = mnist.load_data()
print(X_train.shape)

X_train = X_train.reshape(-1,28,28,1)

X_test = X_test.reshape(-1,28,28,1)
print (X_train.shape)
#-set type into float32 设置成浮点型
X_train = X_train.astype('float32')  #astype SET AS TYPE into 
X_test = X_test.astype('float32')
X_train = X_train/255.0
X_test /=255.0

#Class vectors [0,0,0,0,0,0,0,1(7),0,0] #转成二进制
Y_test = np_utils.to_categorical(Y_test,10) #定义LABEL类数量
Y_train = np_utils.to_categorical(Y_train,10)

# setup model

model = Sequential()

# # 1st Conv2D layer
# model.add(Convolution2D(
#     filters=32,
#     kernel_size=[5, 5],
#     padding='same',
#     input_shape=(28, 28, 1)
# ))
# model.add(Activation('relu'))

# model.add(MaxPool2D(
#     pool_size=(2, 2),
#     strides=(2, 2),
#     padding="same",
# ))

# # 2nd Conv2D layer
# model.add(Convolution2D(
#     filters=64,
#     kernel_size=(5, 5),
#     padding='same',
# ))

# model.add(Activation('relu'))
# model.add(MaxPool2D(
#     pool_size=(2, 2),
#     strides=(2, 2),
#     padding="same",
# ))

#1st Fully connected Dense
model.add(Flatten())
model.add(Dense(1024))
model.add(Activation('relu'))

#2nd Fully connected Dense
model.add(Dense(10))
model.add(Activation('softmax'))


#Define Optimizer and setup Parameter
adam = Adam(lr=0.001)

#compile model
model.compile(
    optimizer=adam,
    loss='categorical_crossentropy',
    metrics=['accuracy'],
)

#Run/Fireup network

model.fit(x=X_train,
          y=Y_train,
          epochs=nb_epoch,
          batch_size=batchsize,
          verbose= 1,
          validation_data=(X_test,Y_test),
          callbacks=[TensorBoard(log_dir='/Users/mikegao/tensorlog')])  #要点!!!!