MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / add_tensor_summary

Function add_tensor_summary

tensorpack/tfutils/summary.py:95–137  ·  view source on GitHub ↗

Summarize a tensor by different methods. Args: x (tf.Tensor): a tensor to summarize types (list[str]): summary types, can be scalar/histogram/sparsity/mean/rms name (str): summary name. Defaults to be the op name. collections (list[str]): collections of the

(x, types, name=None, collections=None,
                       main_tower_only=True)

Source from the content-addressed store, hash-verified

93
94
95def add_tensor_summary(x, types, name=None, collections=None,
96 main_tower_only=True):
97 """
98 Summarize a tensor by different methods.
99
100 Args:
101 x (tf.Tensor): a tensor to summarize
102 types (list[str]): summary types, can be scalar/histogram/sparsity/mean/rms
103 name (str): summary name. Defaults to be the op name.
104 collections (list[str]): collections of the summary ops.
105 main_tower_only (bool): Only run under main training tower. If
106 set to True, calling this function under other TowerContext
107 has no effect.
108
109 Example:
110
111 .. code-block:: python
112
113 with tf.name_scope('mysummaries'): # to not mess up tensorboard
114 add_tensor_summary(
115 tensor, ['histogram', 'rms', 'sparsity'], name='mytensor')
116 """
117 types = set(types)
118 if name is None:
119 name = x.op.name
120 ctx = get_current_tower_context()
121 if main_tower_only and ctx is not None and not ctx.is_main_training_tower:
122 return
123
124 SUMMARY_TYPES_DIC = {
125 'scalar': lambda: tf.summary.scalar(name + '-summary', x, collections=collections),
126 'histogram': lambda: tf.summary.histogram(name + '-histogram', x, collections=collections),
127 'sparsity': lambda: tf.summary.scalar(
128 name + '-sparsity', tf.nn.zero_fraction(x),
129 collections=collections),
130 'mean': lambda: tf.summary.scalar(
131 name + '-mean', tf.reduce_mean(x),
132 collections=collections),
133 'rms': lambda: tf.summary.scalar(
134 name + '-rms', rms(x), collections=collections)
135 }
136 for typ in types:
137 SUMMARY_TYPES_DIC[typ]()
138
139
140def add_activation_summary(x, types=None, name=None, collections=None):

Callers 2

add_activation_summaryFunction · 0.85
add_param_summaryFunction · 0.85

Calls 2

rmsFunction · 0.85

Tested by

no test coverage detected