Return a context which either opens and caches a new name scope, or reenter an existing one. Args: top_level(bool): if True, the name scope will always be top-level. It will not be nested under any existing name scope of the caller.
(name, top_level=True)
| 150 | |
| 151 | @contextmanager |
| 152 | def cached_name_scope(name, top_level=True): |
| 153 | """ |
| 154 | Return a context which either opens and caches a new name scope, |
| 155 | or reenter an existing one. |
| 156 | |
| 157 | Args: |
| 158 | top_level(bool): if True, the name scope will always be top-level. |
| 159 | It will not be nested under any existing name scope of the caller. |
| 160 | """ |
| 161 | if not top_level: |
| 162 | current_ns = tf.get_default_graph().get_name_scope() |
| 163 | if current_ns: |
| 164 | name = current_ns + '/' + name |
| 165 | ns = _get_cached_ns(name) |
| 166 | with tf.name_scope(ns): |
| 167 | yield ns |
no test coverage detected