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","."]
docstr: Run this network for the given NumPy array(s), and return the output(s) as NumPy array(s).
  
  Args:
      input_transform:    A dict specifying a custom transformation to be applied to the input tensor(s) before evaluating the network.
                          The dict must contain a 'func' field that points to a top-level function. The function is called with the input
                          TensorFlow expression(s) as positional arguments. Any remaining fields of the dict will be passed in as kwargs.
      output_transform:   A dict specifying a custom transformation to be applied to the output tensor(s) after evaluating the network.
                          The dict must contain a 'func' field that points to a top-level function. The function is called with the output
                          TensorFlow expression(s) as positional arguments. Any remaining fields of the dict will be passed in as kwargs.
      return_as_list:     True = return a list of NumPy arrays, False = return a single NumPy array, or a tuple if there are multiple outputs.
      print_progress:     Print progress to the console? Useful for very large input arrays.
      minibatch_size:     Maximum minibatch size to use, None = disable batching.
      num_gpus:           Number of GPUs to use.
      assume_frozen:      Improve multi-GPU performance by assuming that the trainable parameters will remain changed between calls.
      custom_inputs:      Allow to use another tensor as input instead of default placeholders.
      dynamic_kwargs:     Additional keyword arguments to be passed into the network build function.
docstr_tok: ["Run","this","network","for","the","given","NumPy","array","(","s",")",",","and","return","the","output","(","s",")","as","NumPy","array","(","s",")",".","Args",":","input_transform",":","A","dict","specifying","a","custom","transformation","to","be","applied","to","the","input","tensor","(","s",")","before","evaluating","the","network",".","The","dict","must","contain","a","'func","'","field","that","points","to","a","top-level","function",".","The","function","is","called","with","the","input","TensorFlow","expression","(","s",")","as","positional","arguments",".","Any","remaining","fields","of","the","dict","will","be","passed","in","as","kwargs",".","output_transform",":","A","dict","specifying","a","custom","transformation","to","be","applied","to","the","output","tensor","(","s",")","after","evaluating","the","network",".","The","dict","must","contain","a","'func","'","field","that","points","to","a","top-level","function",".","The","function","is","called","with","the","output","TensorFlow","expression","(","s",")","as","positional","arguments",".","Any","remaining","fields","of","the","dict","will","be","passed","in","as","kwargs",".","return_as_list",":","True","=","return","a","list","of","NumPy","arrays",",","False","=","return","a","single","NumPy","array",",","or","a","tuple","if","there","are","multiple","outputs",".","print_progress",":","Print","progress","to","the","console","?","Useful","for","very","large","input","arrays",".","minibatch_size",":","Maximum","minibatch","size","to","use",",","None","=","disable","batching",".","num_gpus",":","Number","of","GPUs","to","use",".","assume_frozen",":","Improve","multi-GPU","performance","by","assuming","that","the","trainable","parameters","will","remain","changed","between","calls",".","custom_inputs",":","Allow","to","use","another","tensor","as","input","instead","of","default","placeholders",".","dynamic_kwargs",":","Additional","keyword","arguments","to","be","passed","into","the","network","build","function","."]
code: def run(
      self,
      *in_arrays: Tuple[Union[np.ndarray, None], ...],
      input_transform: dict = None,
      output_transform: dict = None,
      return_as_list: bool = False,
      print_progress: bool = False,
      minibatch_size: int = None,
      num_gpus: int = 1,
      assume_frozen: bool = False,
      custom_inputs: Any = None,
      **dynamic_kwargs,
  ) -> Union[np.ndarray, Tuple[np.ndarray, ...], List[np.ndarray]]:
      """Run this network for the given NumPy array(s), and return the output(s) as NumPy array(s).
  
      Args:
          input_transform:    A dict specifying a custom transformation to be applied to the input tensor(s) before evaluating the network.
                              The dict must contain a 'func' field that points to a top-level function. The function is called with the input
                              TensorFlow expression(s) as positional arguments. Any remaining fields of the dict will be passed in as kwargs.
          output_transform:   A dict specifying a custom transformation to be applied to the output tensor(s) after evaluating the network.
                              The dict must contain a 'func' field that points to a top-level function. The function is called with the output
                              TensorFlow expression(s) as positional arguments. Any remaining fields of the dict will be passed in as kwargs.
          return_as_list:     True = return a list of NumPy arrays, False = return a single NumPy array, or a tuple if there are multiple outputs.
          print_progress:     Print progress to the console? Useful for very large input arrays.
          minibatch_size:     Maximum minibatch size to use, None = disable batching.
          num_gpus:           Number of GPUs to use.
          assume_frozen:      Improve multi-GPU performance by assuming that the trainable parameters will remain changed between calls.
          custom_inputs:      Allow to use another tensor as input instead of default placeholders.
          dynamic_kwargs:     Additional keyword arguments to be passed into the network build function.
      """
      assert len(in_arrays) == self.num_inputs
      assert not all(arr is None for arr in in_arrays)
      assert input_transform is None or util.is_top_level_function(
          input_transform["func"]
      )
      assert output_transform is None or util.is_top_level_function(
          output_transform["func"]
      )
      (
          output_transform,
          dynamic_kwargs,
      ) = _handle_legacy_output_transforms(
          output_transform, dynamic_kwargs
      )
      num_items = in_arrays[0].shape[0]
      if minibatch_size is None:
          minibatch_size = num_items
  
      # Construct unique hash key from all arguments that affect the TensorFlow graph.
      key = dict(
          input_transform=input_transform,
          output_transform=output_transform,
          num_gpus=num_gpus,
          assume_frozen=assume_frozen,
          dynamic_kwargs=dynamic_kwargs,
      )
  
      def unwind_key(obj):
          if isinstance(obj, dict):
              return [
                  (key, unwind_key(value))
                  for key, value in sorted(obj.items())
              ]
          if callable(obj):
              return util.get_top_level_function_name(obj)
          return obj
  
      key = repr(unwind_key(key))
  
      # Build graph.
      if key not in self._run_cache:
          with tfutil.absolute_name_scope(
              self.scope + "/_Run"
          ), tf.control_dependencies(None):
              if custom_inputs is not None:
                  with tf.device("/gpu:0"):
                      in_expr = [
                          input_builder(name)
                          for input_builder, name in zip(
                              custom_inputs, self.input_names
                          )
                      ]
                      in_split = list(
                          zip(*[tf.split(x, num_gpus) for x in in_expr])
                      )
              else:
                  with tf.device("/cpu:0"):
                      in_expr = [
                          tf.placeholder(tf.float32, name=name)
                          for name in self.input_names
                      ]
                      in_split = list(
                          zip(*[tf.split(x, num_gpus) for x in in_expr])
                      )
  
              out_split = []
              for gpu in range(num_gpus):
                  with tf.device("/gpu:%d" % gpu):
                      net_gpu = self.clone() if assume_frozen else self
                      in_gpu = in_split[gpu]
  
                      if input_transform is not None:
                          in_kwargs = dict(input_transform)
                          in_gpu = in_kwargs.pop("func")(
                              *in_gpu, **in_kwargs
                          )
                          in_gpu = (
                              [in_gpu]
                              if tfutil.is_tf_expression(in_gpu)
                              else list(in_gpu)
                          )
  
                      assert len(in_gpu) == self.num_inputs
                      out_gpu = net_gpu.get_output_for(
                          *in_gpu, return_as_list=True, **dynamic_kwargs
                      )
  
                      if output_transform is not None:
                          out_kwargs = dict(output_transform)
                          out_gpu = out_kwargs.pop("func")(
                              *out_gpu, **out_kwargs
                          )
                          out_gpu = (
                              [out_gpu]
                              if tfutil.is_tf_expression(out_gpu)
                              else list(out_gpu)
                          )
  
                      assert len(out_gpu) == self.num_outputs
                      out_split.append(out_gpu)
  
              with tf.device("/cpu:0"):
                  out_expr = [
                      tf.concat(outputs, axis=0)
                      for outputs in zip(*out_split)
                  ]
                  self._run_cache[key] = in_expr, out_expr
  
      # Run minibatches.
      in_expr, out_expr = self._run_cache[key]
      out_arrays = [
          np.empty(
              [num_items] + expr.shape.as_list()[1:], expr.dtype.name
          )
          for expr in out_expr
      ]
  
      for mb_begin in range(0, num_items, minibatch_size):
          if print_progress:
              print("\r%d / %d" % (mb_begin, num_items), end="")
  
          mb_end = min(mb_begin + minibatch_size, num_items)
          mb_num = mb_end - mb_begin
          mb_in = [
              src[mb_begin:mb_end]
              if src is not None
              else np.zeros([mb_num] + shape[1:])
              for src, shape in zip(in_arrays, self.input_shapes)
          ]
          mb_out = tf.get_default_session().run(
              out_expr, dict(zip(in_expr, mb_in))
          )
  
          for dst, src in zip(out_arrays, mb_out):
              dst[mb_begin:mb_end] = src
  
      # Done.
      if print_progress:
          print("\r%d / %d" % (num_items, num_items))
  
      if not return_as_list:
          out_arrays = (
              out_arrays[0]
              if len(out_arrays) == 1
              else tuple(out_arrays)
          )
      return out_arrays
  
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 20 for calling the Network obj's underlying member method code with example usage: obj.run() and returns: out_arrays, obj, unknown, util