Add summary ops for all trainable variables matching the regex, under a reused 'param-summary' name scope. This function is a no-op if not calling from main training tower. Args: summary_lists (list): each is (regex, [list of summary type]). Summary type is defi
(*summary_lists, **kwargs)
| 159 | |
| 160 | |
| 161 | def add_param_summary(*summary_lists, **kwargs): |
| 162 | """ |
| 163 | Add summary ops for all trainable variables matching the regex, under a |
| 164 | reused 'param-summary' name scope. |
| 165 | This function is a no-op if not calling from main training tower. |
| 166 | |
| 167 | Args: |
| 168 | summary_lists (list): each is (regex, [list of summary type]). |
| 169 | Summary type is defined in :func:`add_tensor_summary`. |
| 170 | collections (list[str]): collections of the summary ops. |
| 171 | |
| 172 | Example: |
| 173 | |
| 174 | .. code-block:: python |
| 175 | |
| 176 | add_param_summary( |
| 177 | ('.*/W', ['histogram', 'rms']), |
| 178 | ('.*/gamma', ['scalar']), |
| 179 | ) |
| 180 | """ |
| 181 | collections = kwargs.pop('collections', None) |
| 182 | assert len(kwargs) == 0, "Unknown kwargs: " + str(kwargs) |
| 183 | ctx = get_current_tower_context() |
| 184 | if ctx is not None and not ctx.is_main_training_tower: |
| 185 | return |
| 186 | |
| 187 | params = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES) |
| 188 | with cached_name_scope('param-summary'): |
| 189 | for p in params: |
| 190 | name = p.op.name |
| 191 | for rgx, actions in summary_lists: |
| 192 | if not rgx.endswith('$'): |
| 193 | rgx = rgx + '$' |
| 194 | if re.match(rgx, name): |
| 195 | add_tensor_summary(p, actions, name=name, collections=collections) |
| 196 | |
| 197 | |
| 198 | def add_moving_summary(*args, **kwargs): |
no test coverage detected