Tf摘要未提供直方图,但保存了会话图(预先训练的模型)

时间:2019-03-20 18:15:23

标签: python tensorflow histogram tensorboard summary

我正在进行分析,以直观显示在线提供的预训练模型的权重分布。它是在CIFAR10上训练的Resnet18模型。

我有以下代码从metackpt恢复模型,然后尝试创建所有卷积层weightsbias的直方图使用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上看不到直方图。这里可能出什么问题了?

1 个答案:

答案 0 :(得分:1)

仅将合并的摘要节点传递到select new com.package.SomeDTO(p.id, p.title) from EntityCalss p 是不够的。您需要获取评估结果并将其传递给sess.run实例的add_summary方法。

FileWriter