-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmetrics.py
More file actions
executable file
·39 lines (30 loc) · 982 Bytes
/
metrics.py
File metadata and controls
executable file
·39 lines (30 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python2.7
#-*- coding: utf-8 -*-
"""
loss management module
"""
import tensorflow as tf
COLLECTION_LOSS_VIEW = "loss_view"
LOSS_AVERAGE_DECAY=0.99
def add_to_loss_view(loss):
"""
add loss variable to the watch collecition.
:param tf.Tensor loss: loss Tensor
:return:
"""
tf.add_to_collection(name=COLLECTION_LOSS_VIEW, value=loss)
def add_loss_summaries():
"""
add loss summaries to a graph.
This collects losses from values passed to add_to_loss_view.
:rtype: tf.Operator
:return:
loss average op
"""
loss_averages = tf.train.ExponentialMovingAverage(LOSS_AVERAGE_DECAY, name='avg', zero_debias=True)
losses = tf.get_collection(COLLECTION_LOSS_VIEW)
loss_averages_op = loss_averages.apply(losses)
for l in losses:
tf.summary.scalar(name=l.op.name, tensor=l)
tf.summary.scalar(name=l.op.name + "_avg", tensor=loss_averages.average(l))
return loss_averages_op