1、keras 与 tensorboard
from tensorflow.keras.callbacks import TensorBoard
filepath="snapshot/v2_weights-improvement-{epoch:02d}-{val_acc:.2f}.hdf5"
tensorboard = TensorBoard(log_dir='logs/{}'.format(filepath))
callbacks_list = [checkpoint, tensorboard]
model.fit(train_imgs, train_labels, validation_data=(test_imgs, test_labels) ,
batch_size=256, callbacks=callbacks_list, epochs=15, shuffle=True, verbose=0)
终端 tensorboard --logdir="./log"
http://localhost:6006(如果访问的是服务器,别忘记修改ip)
https://stackoverflow.com/questions/42112260/how-do-i-use-the-tensorboard-callback-of-keras
2、模型可视化
pb模型可视化
v1 = tf.Variable(tf.constant(1, shape=[1]), name='v1')
v2 = tf.Variable(tf.constant(1, shape=[1]), name='v2')
result = v1 + v2
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
graph = tf.get_default_graph()
graph_def = graph.as_graph_def()
output_grapg_def = tf.graph_util.convert_variables_to_constants(sess, graph_def, ["add"])
with tf.gfile.GFile("Model/freeze_model.pb", 'wb') as f:
f.write(output_grapg_def.SerializeToString())
graph_def.ParseFromString(tf.gfile.GFile("Model/freeze_model.pb", 'rb').read())
tf.import_graph_def(graph_def, name='graph')
summary_writer = tf.summary.FileWriter('log/', graph)
meta可视化
v1 = tf.Variable(tf.constant(1, shape=[1]), name='v1')
v2 = tf.Variable(tf.constant(1, shape=[1]), name='v2')
result = v1 + v2
saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(result))
saver.save(sess, "Model/model.ckpt")
graph = tf.get_default_graph()
graph_def = graph.as_graph_def()
_ = tf.train.import_meta_graph("Model/model.ckpt.meta")
summary_writer = tf.summary.FileWriter("log/", graph)