tensorflow summary

博客介绍了人工智能相关存储方法。一是scalar存储结果,需先在训练循环外定义,在session run时获取值并添加;二是histogram存储权重和偏执,同样先在训练循环外定义,再在session run时获取值添加。

定义summary

writer = tf.summary.FileWriter(logdir=self.han_config.log_path, graph=session.graph)

 

1.scalar存储结果

  a.先在训练的循环外定义:

test_accuracy_summary = tf.summary.scalar('test_accuracy', self.han_model.accuracy)
            test_loss_summary = tf.summary.scalar('test_loss', self.han_model.loss)
            test_scalar = tf.summary.merge([test_accuracy_summary, test_loss_summary])

 

  b.在session run的时候run test_scalar,获得值,然后再添加。

 writer.add_summary(summary=train_scalar_, global_step=steps)

 

 

2.histogram存储权重,偏执。

  a.先在训练的循环外定义:

            W_w_attention_word_histogram = tf.summary.histogram('W_w_attention_word', self.han_model.W_w_attention_word)
            W_b_attention_word_histogram = tf.summary.histogram('W_w_attention_word', self.han_model.W_b_attention_word)
            context_vecotor_word_histogram = tf.summary.histogram('context_vecotor_word',
                                                                  self.han_model.context_vecotor_word)
            W_w_attention_sentence_histogram = tf.summary.histogram('W_w_attention_sentence',
                                                                    self.han_model.W_w_attention_sentence)
            W_b_attention_sentence_histogram = tf.summary.histogram('W_b_attention_sentence',
                                                                    self.han_model.W_b_attention_sentence)
            context_vecotor_sentence_histogram = tf.summary.histogram('context_vecotor_sentence',
                                                                      self.han_model.context_vecotor_sentence)
            train_variable_histogram = tf.summary.merge([W_w_attention_word_histogram, W_b_attention_word_histogram,
                                                    context_vecotor_word_histogram, W_w_attention_sentence_histogram,
                                                W_b_attention_sentence_histogram, context_vecotor_sentence_histogram])

 

  b.在session run的时候run test_scalar,获得值,然后再添加。

writer.add_summary(summary=train_variable_histogram_, global_step=steps)

 

转载于:https://www.cnblogs.com/callyblog/p/9549993.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值