class_docstr: The :class:`Model` class represents a neural network.
  
  It should be subclassed when implementing a dynamic model,
  where 'forward' method must be overwritten.
  Otherwise, please specify 'inputs' tensor(s) and 'outputs' tensor(s)
  to create a static model. In that case, 'inputs' tensors should come
  from tl.layers.Input().
  
  Parameters
  -----------
  inputs : a Layer or list of Layer
      The input(s) to the model.
  outputs : a Layer or list of Layer
      The output(s) to the model.
  name : None or str
      The name of the model.
  
  Methods
  ---------
  __init__(self, inputs=None, outputs=None, name=None)
      Initializing the Model.
  inputs()
      Get input tensors to this network (only avaiable for static model).
  outputs()
      Get output tensors to this network (only avaiable for static model).
  __call__(inputs, is_train=None, **kwargs)
      Forward input tensors through this network.
  all_layers()
      Get all layer objects of this network in a list of layers.
  weights()
      Get the weights of this network in a list of tensors.
  train()
      Set this network in training mode. (affect layers e.g. Dropout, BatchNorm).
  eval()
      Set this network in evaluation mode.
  as_layer()
      Set this network as a ModelLayer so that it can be integrated into another Model.
  release_memory()
      Release the memory that was taken up by tensors which are maintained by this network.
  save_weights(self, filepath, format='hdf5')
      Save the weights of this network in a given format.
  load_weights(self, filepath, format=None, in_order=True, skip=False)
      Load weights into this network from a specified file.
  save(self, filepath, save_weights=True)
      Save the network with/without weights.
  load(filepath, save_weights=True)
      Load the network with/without weights.
  
  Examples
  ---------
  >>> import tensorflow as tf
  >>> import numpy as np
  >>> from tensorlayer.layers import Input, Dense, Dropout
  >>> from tensorlayer.models import Model
  
  Define static model
  
  >>> class CustomModel(Model):
  >>>     def __init__(self):
  >>>         super(CustomModel, self).__init__()
  >>>         self.dense1 = Dense(n_units=800, act=tf.nn.relu, in_channels=784)
  >>>         self.dropout1 = Dropout(keep=0.8)
  >>>         self.dense2 = Dense(n_units=10, in_channels=800)
  >>>     def forward(self, x):
  >>>         z = self.dense1(x)
  >>>         z = self.dropout1(z)
  >>>         z = self.dense2(z)
  >>>         return z
  >>> M_dynamic = CustomModel()
  
  Define static model
  
  >>> ni = Input([None, 784])
  >>> nn = Dense(n_units=800, act=tf.nn.relu)(ni)
  >>> nn = Dropout(keep=0.8)(nn)
  >>> nn = Dense(n_units=10, act=tf.nn.relu)(nn)
  >>> M_static = Model(inputs=ni, outputs=nn, name="mlp")
  
  Get network information
  
  >>> print(M_static)
  ... Model(
  ...  (_inputlayer): Input(shape=[None, 784], name='_inputlayer')
  ...  (dense): Dense(n_units=800, relu, in_channels='784', name='dense')
  ...  (dropout): Dropout(keep=0.8, name='dropout')
  ...  (dense_1): Dense(n_units=10, relu, in_channels='800', name='dense_1')
  ... )
  
  Forwarding through this network
  
  >>> data = np.random.normal(size=[16, 784]).astype(np.float32)
  >>> outputs_d = M_dynamic(data)
  >>> outputs_s = M_static(data)
  
  Save and load weights
  
  >>> M_static.save_weights('./model_weights.h5')
  >>> M_static.load_weights('./model_weights.h5')
  
  Save and load the model
  
  >>> M_static.save('./model.h5')
  >>> M = Model.load('./model.h5')
  
  Convert model to layer
  
  >>> M_layer = M_static.as_layer()
class_docstr_tok: ["The",":","class",":","`","Model","`","class","represents","a","neural","network",".","It","should","be","subclassed","when","implementing","a","dynamic","model",",","where","'forward","'","method","must","be","overwritten",".","Otherwise",",","please","specify","'inputs","'","tensor","(","s",")","and","'outputs","'","tensor","(","s",")","to","create","a","static","model",".","In","that","case",",","'inputs","'","tensors","should","come","from","tl.layers.Input","(",")",".","Parameters","--","--","--","--","--","-","inputs",":","a","Layer","or","list","of","Layer","The","input","(","s",")","to","the","model",".","outputs",":","a","Layer","or","list","of","Layer","The","output","(","s",")","to","the","model",".","name",":","None","or","str","The","name","of","the","model",".","Methods","--","--","--","--","-","__init__","(","self",",","inputs=None",",","outputs=None",",","name=None",")","Initializing","the","Model",".","inputs","(",")","Get","input","tensors","to","this","network","(","only","avaiable","for","static","model",")",".","outputs","(",")","Get","output","tensors","to","this","network","(","only","avaiable","for","static","model",")",".","__call__","(","inputs",",","is_train=None",",","*","*","kwargs",")","Forward","input","tensors","through","this","network",".","all_layers","(",")","Get","all","layer","objects","of","this","network","in","a","list","of","layers",".","weights","(",")","Get","the","weights","of","this","network","in","a","list","of","tensors",".","train","(",")","Set","this","network","in","training","mode",".","(","affect","layers","e.g",".","Dropout",",","BatchNorm",")",".","eval","(",")","Set","this","network","in","evaluation","mode",".","as_layer","(",")","Set","this","network","as","a","ModelLayer","so","that","it","can","be","integrated","into","another","Model",".","release_memory","(",")","Release","the","memory","that","was","taken","up","by","tensors","which","are","maintained","by","this","network",".","save_weights","(","self",",","filepath",",","format='hdf5","'",")","Save","the","weights","of","this","network","in","a","given","format",".","load_weights","(","self",",","filepath",",","format=None",",","in_order=True",",","skip=False",")","Load","weights","into","this","network","from","a","specified","file",".","save","(","self",",","filepath",",","save_weights=True",")","Save","the","network","with\/without","weights",".","load","(","filepath",",","save_weights=True",")","Load","the","network","with\/without","weights",".","Examples","--","--","--","--","-",">",">",">","import","tensorflow","as","tf",">",">",">","import","numpy","as","np",">",">",">","from","tensorlayer.layers","import","Input",",","Dense",",","Dropout",">",">",">","from","tensorlayer.models","import","Model","Define","static","model",">",">",">","class","CustomModel","(","Model",")",":",">",">",">","def","__init__","(","self",")",":",">",">",">","super","(","CustomModel",",","self",")",".__init__","(",")",">",">",">","self.dense1","=","Dense","(","n_units=800",",","act=tf.nn.relu",",","in_channels=784",")",">",">",">","self.dropout1","=","Dropout","(","keep=0.8",")",">",">",">","self.dense2","=","Dense","(","n_units=10",",","in_channels=800",")",">",">",">","def","forward","(","self",",","x",")",":",">",">",">","z","=","self.dense1","(","x",")",">",">",">","z","=","self.dropout1","(","z",")",">",">",">","z","=","self.dense2","(","z",")",">",">",">","return","z",">",">",">","M_dynamic","=","CustomModel","(",")","Define","static","model",">",">",">","ni","=","Input","(","[","None",",","784","]",")",">",">",">","nn","=","Dense","(","n_units=800",",","act=tf.nn.relu",")","(","ni",")",">",">",">","nn","=","Dropout","(","keep=0.8",")","(","nn",")",">",">",">","nn","=","Dense","(","n_units=10",",","act=tf.nn.relu",")","(","nn",")",">",">",">","M_static","=","Model","(","inputs=ni",",","outputs=nn",",","name=","''","mlp","''",")","Get","network","information",">",">",">","print","(","M_static",")","...","Model","(","...","(","_inputlayer",")",":","Input","(","shape=","[","None",",","784","]",",","name='_inputlayer","'",")","...","(","dense",")",":","Dense","(","n_units=800",",","relu",",","in_channels='784","'",",","name='dense","'",")","...","(","dropout",")",":","Dropout","(","keep=0.8",",","name='dropout","'",")","...","(","dense_1",")",":","Dense","(","n_units=10",",","relu",",","in_channels='800","'",",","name='dense_1","'",")","...",")","Forwarding","through","this","network",">",">",">","data","=","np.random.normal","(","size=","[","16",",","784","]",")",".astype","(","np.float32",")",">",">",">","outputs_d","=","M_dynamic","(","data",")",">",">",">","outputs_s","=","M_static","(","data",")","Save","and","load","weights",">",">",">","M_static.save_weights","(","'.\/model_weights.h5","'",")",">",">",">","M_static.load_weights","(","'.\/model_weights.h5","'",")","Save","and","load","the","model",">",">",">","M_static.save","(","'.\/model.h5","'",")",">",">",">","M","=","Model.load","(","'.\/model.h5","'",")","Convert","model","to","layer",">",">",">","M_layer","=","M_static.as_layer","(",")"]
docstr: construct computation graph for static model using LayerNode object
docstr_tok: ["construct","computation","graph","for","static","model","using","LayerNode","object"]
code: def _construct_graph(self):
      """construct computation graph for static model using LayerNode object"""
      all_layers = []
      node_by_depth = []  # [[node0, node1], [node2, node3], ...]
  
      input_tensors_list = (
          self.inputs
          if isinstance(self.inputs, list)
          else [self.inputs]
      )
  
      queue_node = Queue()
  
      # BFS to visit all nodes that should be involved in the computation graph
      output_tensors_list = (
          self.outputs
          if isinstance(self.outputs, list)
          else [self.outputs]
      )
      output_nodes = [tensor._info[0] for tensor in output_tensors_list]
  
      visited_node_names = set()
      for out_node in output_nodes:
          if out_node.visited:
              continue
          queue_node.put(out_node)
  
          while not queue_node.empty():
              cur_node = queue_node.get()
              in_nodes = cur_node.in_nodes
  
              for node in in_nodes:
                  node.out_nodes.append(cur_node)
                  if not node.visited:
                      queue_node.put(node)
                      node.visited = True
                      if node.name not in visited_node_names:
                          visited_node_names.add(node.name)
                      # else have multiple layers with the same name
                      else:
                          raise ValueError(
                              "Layer name '%s' has already been used by another layer. Please change the layer name."
                              % node.layer.name
                          )
  
      # construct the computation graph in top-sort order
      cur_depth = [tensor._info[0] for tensor in input_tensors_list]
      next_depth = []
      indegrees = {}
  
      visited_layer_names = []
      while not len(cur_depth) == 0:
          node_by_depth.append(cur_depth)
          for node in cur_depth:
              if node.layer.name not in visited_layer_names:
                  all_layers.append(node.layer)
                  visited_layer_names.append(node.layer.name)
              for out_node in node.out_nodes:
                  if out_node.name not in indegrees.keys():
                      indegrees[out_node.name] = len(out_node.in_nodes)
                  indegrees[out_node.name] -= 1
                  if indegrees[out_node.name] == 0:
                      next_depth.append(out_node)
  
          cur_depth = next_depth
          next_depth = []
  
      return node_by_depth, all_layers
  
imports: import os
  from abc import abstractmethod
  from queue import Queue
  import tensorflow
  from tensorflow.python.framework import ops
  import tensorlayer
  from tensorlayer import logging
  from tensorlayer.files import utils
  from tensorlayer.layers import Layer, ModelLayer
label_desc: Use image node_id 28 for calling the Model obj's underlying member method code with example usage: obj._construct_graph() and returns: node_by_depth,  all_layers