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: Return all layers of this network in a list.
docstr_tok: ["Return","all","layers","of","this","network","in","a","list","."]
code: def all_layers(self):
      """Return all layers of this network in a list."""
      if self._all_layers is not None:
          return self._all_layers
  
      if self._inputs is not None and self._outputs is not None:
          # static model
          return self._all_layers
      else:
          # dynamic model
          self._all_layers = list()
          attr_list = [attr for attr in dir(self) if attr[:2] != "__"]
          attr_list.remove("all_weights")
          attr_list.remove("trainable_weights")
          attr_list.remove("nontrainable_weights")
          attr_list.remove("_all_weights")
          attr_list.remove("_trainable_weights")
          attr_list.remove("_nontrainable_weights")
          attr_list.remove("all_layers")
          attr_list.remove("_all_layers")
          attr_list.remove("n_weights")
          for idx, attr in enumerate(attr_list):
              try:
                  if isinstance(getattr(self, attr), Layer):
                      nowlayer = getattr(self, attr)
                      if not nowlayer._built:
                          raise AttributeError(
                              "Layer %s not built yet." % repr(nowlayer)
                          )
                      self._all_layers.append(nowlayer)
                  elif isinstance(getattr(self, attr), Model):
                      nowmodel = getattr(self, attr)
                      self._all_layers.append(nowmodel)
                  elif isinstance(getattr(self, attr), list):
                      self._all_layers.extend(
                          _add_list_to_all_layers(getattr(self, attr))
                      )
              # TODO: define customised exception for TL
              except AttributeError as e:
                  raise e
              except Exception:
                  pass
  
          # check layer name uniqueness
          local_layer_name_dict = set()
          for layer in self._all_layers:
              if layer.name in local_layer_name_dict:
                  raise ValueError(
                      "Layer name '%s' has already been used by another layer. Please change the layer name."
                      % layer.name
                  )
              else:
                  local_layer_name_dict.add(layer.name)
          return self._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 6 for calling the Model obj's underlying member method code with example usage: obj.all_layers() and returns: self, self, self