Tf Summary 不提供直方图但保存会话图(预训练模型)
Tf Summary not giving the histograms but saves the session graph (pre-trained model)
我正在进行一项分析,以可视化在线提供的预训练模型的权重分布。它是在 CIFAR10 上训练的 Resnet18 模型。
我有以下代码从 meta
和 ckpt
恢复模型,然后我尝试创建所有 weights
和 bias
的直方图使用 tf.summary.histogram
的卷积层
`with tf.Session(graph=tf.Graph()) as sess:
read=tf.train.import_meta_graph(self.paths[0], clear_devices=True)
try:
read.restore(sess, tf.train.latest_checkpoint(self.paths[1]))
except ValueError:
try:
read.restore(sess, self.paths[1])
except Exception as e:
print(e.message)
# Summaries of weights
summ_writer = tf.summary.FileWriter(self.sum_path, sess.graph)
fp_summaries = []
for lys in tf.trainable_variables():
lay_nam = lys.name.split("/")[-2]
if 'kernel' in lys.name:
with tf.name_scope(lay_nam+'_hist'):
tf_w_hist = tf.summary.histogram('Weights', tf.reshape(lys.eval(), [-1]))
fp_summaries.extend([tf_w_hist])
if 'bias' in lys.name:
with tf.name_scope(lay_nam+'_hist'):
tf_b_hist = tf.summary.histogram('Bias', lys.eval())
fp_summaries.extend([tf_b_hist])
tf_fp_summaries = tf.summary.merge(fp_summaries)
# Run the graph
output, _=sess.run([softmax, tf_fp_summaries], feed_dict={x: self.x_test[0:100, ]})
但是,文件夹中存储的日志事件仅存储主图。在 tensorboard
上看不到直方图。这里可能出了什么问题?
将合并的摘要节点传递给 sess.run
是不够的。您需要获取评估结果并将其传递给 FileWriter
实例的 add_summary
方法。
# evaluate the merged summary node in the graph
output, summ = sess.run([softmax, tf_fp_summaries], ...)
# explicitly write to file
summ_writer.add_summary(summ, global_step)
# optional, force to write to disk
summ_writer.flush()
我正在进行一项分析,以可视化在线提供的预训练模型的权重分布。它是在 CIFAR10 上训练的 Resnet18 模型。
我有以下代码从 meta
和 ckpt
恢复模型,然后我尝试创建所有 weights
和 bias
的直方图使用 tf.summary.histogram
`with tf.Session(graph=tf.Graph()) as sess:
read=tf.train.import_meta_graph(self.paths[0], clear_devices=True)
try:
read.restore(sess, tf.train.latest_checkpoint(self.paths[1]))
except ValueError:
try:
read.restore(sess, self.paths[1])
except Exception as e:
print(e.message)
# Summaries of weights
summ_writer = tf.summary.FileWriter(self.sum_path, sess.graph)
fp_summaries = []
for lys in tf.trainable_variables():
lay_nam = lys.name.split("/")[-2]
if 'kernel' in lys.name:
with tf.name_scope(lay_nam+'_hist'):
tf_w_hist = tf.summary.histogram('Weights', tf.reshape(lys.eval(), [-1]))
fp_summaries.extend([tf_w_hist])
if 'bias' in lys.name:
with tf.name_scope(lay_nam+'_hist'):
tf_b_hist = tf.summary.histogram('Bias', lys.eval())
fp_summaries.extend([tf_b_hist])
tf_fp_summaries = tf.summary.merge(fp_summaries)
# Run the graph
output, _=sess.run([softmax, tf_fp_summaries], feed_dict={x: self.x_test[0:100, ]})
但是,文件夹中存储的日志事件仅存储主图。在 tensorboard
上看不到直方图。这里可能出了什么问题?
将合并的摘要节点传递给 sess.run
是不够的。您需要获取评估结果并将其传递给 FileWriter
实例的 add_summary
方法。
# evaluate the merged summary node in the graph
output, summ = sess.run([softmax, tf_fp_summaries], ...)
# explicitly write to file
summ_writer.add_summary(summ, global_step)
# optional, force to write to disk
summ_writer.flush()