Expand the base name if there are node names nested under the node.

    For example, if there are two nodes in the graph, "a" and "a/read", then
    calling this function on "a" will give "a/(a)", a form that points at
    a leaf node in the nested TensorBoard graph. Calling this function on
    "a/read" will just return "a/read", because there is no node nested under
    it.

    This method is thread-safe.

    Args:
      node_name: Name of the node.
      graph_def: The `GraphDef` that the node is a part of.

    Returns:
      Possibly base-expanded node name.

def maybe_base_expanded_node_name(self, node_name):
    """Expand the base name if there are node names nested under the node.

    For example, if there are two nodes in the graph, "a" and "a/read", then
    calling this function on "a" will give "a/(a)", a form that points at
    a leaf node in the nested TensorBoard graph. Calling this function on
    "a/read" will just return "a/read", because there is no node nested under
    it.

    This method is thread-safe.

    Args:
      node_name: Name of the node.
      graph_def: The `GraphDef` that the node is a part of.

    Returns:
      Possibly base-expanded node name.
    """
    with self._node_name_lock:
      # Lazily populate the map from original node name to base-expanded ones.
      if self._maybe_base_expanded_node_names is None:
        self._maybe_base_expanded_node_names = dict()
        # Sort all the node names.
        sorted_names = sorted(node.name for node in self._graph_def.node)
        for i, name in enumerate(sorted_names):
          j = i + 1
          while j < len(sorted_names) and sorted_names[j].startswith(name):
            if sorted_names[j].startswith(name + '/'):
              self._maybe_base_expanded_node_names[name] = (
                  name + '/(' + name.split('/')[-1] + ')')
              break
            j += 1
      return self._maybe_base_expanded_node_names.get(node_name, node_name)