class_docstr: Generic network abstraction.
  
  Acts as a convenience wrapper for a parameterized network construction
  function, providing several utility methods and convenient access to
  the inputs/outputs/weights.
  
  Network objects can be safely pickled and unpickled for long-term
  archival purposes. The pickling works reliably as long as the underlying
  network construction function is defined in a standalone Python module
  that has no side effects or application-specific imports.
  
  Args:
      name: Network name. Used to select TensorFlow name and variable scopes.
      func_name: Fully qualified name of the underlying network construction function, or a top-level function object.
      static_kwargs: Keyword arguments to be passed in to the network construction function.
  
  Attributes:
      name: User-specified name, defaults to build func name if None.
      scope: Unique TensorFlow scope containing template graph and variables, derived from the user-specified name.
      static_kwargs: Arguments passed to the user-supplied build func.
      components: Container for sub-networks. Passed to the build func, and retained between calls.
      num_inputs: Number of input tensors.
      num_outputs: Number of output tensors.
      input_shapes: Input tensor shapes (NC or NCHW), including minibatch dimension.
      output_shapes: Output tensor shapes (NC or NCHW), including minibatch dimension.
      input_shape: Short-hand for input_shapes[0].
      output_shape: Short-hand for output_shapes[0].
      input_templates: Input placeholders in the template graph.
      output_templates: Output tensors in the template graph.
      input_names: Name string for each input.
      output_names: Name string for each output.
      own_vars: Variables defined by this network (local_name => var), excluding sub-networks.
      vars: All variables (local_name => var).
      trainables: All trainable variables (local_name => var).
      var_global_to_local: Mapping from variable global names to local names.
class_docstr_tok: ["Generic","network","abstraction",".","Acts","as","a","convenience","wrapper","for","a","parameterized","network","construction","function",",","providing","several","utility","methods","and","convenient","access","to","the","inputs\/outputs\/weights",".","Network","objects","can","be","safely","pickled","and","unpickled","for","long-term","archival","purposes",".","The","pickling","works","reliably","as","long","as","the","underlying","network","construction","function","is","defined","in","a","standalone","Python","module","that","has","no","side","effects","or","application-specific","imports",".","Args",":","name",":","Network","name",".","Used","to","select","TensorFlow","name","and","variable","scopes",".","func_name",":","Fully","qualified","name","of","the","underlying","network","construction","function",",","or","a","top-level","function","object",".","static_kwargs",":","Keyword","arguments","to","be","passed","in","to","the","network","construction","function",".","Attributes",":","name",":","User-specified","name",",","defaults","to","build","func","name","if","None",".","scope",":","Unique","TensorFlow","scope","containing","template","graph","and","variables",",","derived","from","the","user-specified","name",".","static_kwargs",":","Arguments","passed","to","the","user-supplied","build","func",".","components",":","Container","for","sub-networks",".","Passed","to","the","build","func",",","and","retained","between","calls",".","num_inputs",":","Number","of","input","tensors",".","num_outputs",":","Number","of","output","tensors",".","input_shapes",":","Input","tensor","shapes","(","NC","or","NCHW",")",",","including","minibatch","dimension",".","output_shapes",":","Output","tensor","shapes","(","NC","or","NCHW",")",",","including","minibatch","dimension",".","input_shape",":","Short-hand","for","input_shapes","[","0","]",".","output_shape",":","Short-hand","for","output_shapes","[","0","]",".","input_templates",":","Input","placeholders","in","the","template","graph",".","output_templates",":","Output","tensors","in","the","template","graph",".","input_names",":","Name","string","for","each","input",".","output_names",":","Name","string","for","each","output",".","own_vars",":","Variables","defined","by","this","network","(","local_name","=",">","var",")",",","excluding","sub-networks",".","vars",":","All","variables","(","local_name","=",">","var",")",".","trainables",":","All","trainable","variables","(","local_name","=",">","var",")",".","var_global_to_local",":","Mapping","from","variable","global","names","to","local","names","."]
code: def _init_graph(self) -> None:
      # Collect inputs.
      self.input_names = []
  
      for param in inspect.signature(
          self._build_func
      ).parameters.values():
          if (
              param.kind == param.POSITIONAL_OR_KEYWORD
              and param.default is param.empty
          ):
              self.input_names.append(param.name)
  
      self.num_inputs = len(self.input_names)
      assert self.num_inputs >= 1
  
      # Choose name and scope.
      if self.name is None:
          self.name = self._build_func_name
      assert re.match("^[A-Za-z0-9_.\\-]*$", self.name)
      with tf.name_scope(None):
          self.scope = tf.get_default_graph().unique_name(
              self.name, mark_as_used=True
          )
  
      # Finalize build func kwargs.
      build_kwargs = dict(self.static_kwargs)
      build_kwargs["is_template_graph"] = True
      build_kwargs["components"] = self.components
  
      # Build template graph.
      with tfutil.absolute_variable_scope(
          self.scope, reuse=False
      ), tfutil.absolute_name_scope(
          self.scope
      ):  # ignore surrounding scopes
          assert tf.get_variable_scope().name == self.scope
          assert tf.get_default_graph().get_name_scope() == self.scope
          with tf.control_dependencies(
              None
          ):  # ignore surrounding control dependencies
              self.input_templates = [
                  tf.placeholder(tf.float32, name=name)
                  for name in self.input_names
              ]
              out_expr = self._build_func(
                  *self.input_templates, **build_kwargs
              )
  
      # Collect outputs.
      assert tfutil.is_tf_expression(out_expr) or isinstance(
          out_expr, tuple
      )
      self.output_templates = (
          [out_expr]
          if tfutil.is_tf_expression(out_expr)
          else list(out_expr)
      )
      self.num_outputs = len(self.output_templates)
      assert self.num_outputs >= 1
      assert all(
          tfutil.is_tf_expression(t) for t in self.output_templates
      )
  
      # Perform sanity checks.
      if any(t.shape.ndims is None for t in self.input_templates):
          raise ValueError(
              "Network input shapes not defined. Please call x.set_shape() for each input."
          )
      if any(t.shape.ndims is None for t in self.output_templates):
          raise ValueError(
              "Network output shapes not defined. Please call x.set_shape() where applicable."
          )
      if any(
          not isinstance(comp, Network)
          for comp in self.components.values()
      ):
          raise ValueError(
              "Components of a Network must be Networks themselves."
          )
      if len(self.components) != len(
          set(comp.name for comp in self.components.values())
      ):
          raise ValueError(
              "Components of a Network must have unique names."
          )
  
      # List inputs and outputs.
      self.input_shapes = [
          t.shape.as_list() for t in self.input_templates
      ]
      self.output_shapes = [
          t.shape.as_list() for t in self.output_templates
      ]
      self.input_shape = self.input_shapes[0]
      self.output_shape = self.output_shapes[0]
      self.output_names = [
          t.name.split("/")[-1].split(":")[0]
          for t in self.output_templates
      ]
  
      # List variables.
      self.own_vars = OrderedDict(
          (var.name[len(self.scope) + 1 :].split(":")[0], var)
          for var in tf.global_variables(self.scope + "/")
      )
      self.vars = OrderedDict(self.own_vars)
      self.vars.update(
          (comp.name + "/" + name, var)
          for comp in self.components.values()
          for name, var in comp.vars.items()
      )
      self.trainables = OrderedDict(
          (name, var)
          for name, var in self.vars.items()
          if var.trainable
      )
      self.var_global_to_local = OrderedDict(
          (var.name.split(":")[0], name)
          for name, var in self.vars.items()
      )
  
imports: import types
  import inspect
  import re
  import uuid
  import sys
  import numpy
  import tensorflow
  from collections import OrderedDict
  from typing import Any, List, Tuple, Union
  from .None import tfutil
  from ..None import util
  from .tfutil import TfExpression, TfExpressionEx
label_desc: Use image node_id 3 for calling the Network obj's underlying member method code with example usage: obj._init_graph() without return types