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: Initializing the Model.
  
  Parameters
  ----------
  inputs : Tensor or list of tensors
      Input tensor(s), which must come from tl.layers.Input()
  outputs : Tensor or list of tensors
      Output tensor(s), which must be the output(s) of some TL layers
  name : str or None
      Name for this network
docstr_tok: ["Initializing","the","Model",".","Parameters","--","--","--","--","--","inputs",":","Tensor","or","list","of","tensors","Input","tensor","(","s",")",",","which","must","come","from","tl.layers.Input","(",")","outputs",":","Tensor","or","list","of","tensors","Output","tensor","(","s",")",",","which","must","be","the","output","(","s",")","of","some","TL","layers","name",":","str","or","None","Name","for","this","network"]
code: def __init__(self, inputs=None, outputs=None, name=None):
      """
      Initializing the Model.
  
      Parameters
      ----------
      inputs : Tensor or list of tensors
          Input tensor(s), which must come from tl.layers.Input()
      outputs : Tensor or list of tensors
          Output tensor(s), which must be the output(s) of some TL layers
      name : str or None
          Name for this network
      """
      # Auto naming if the name is not given
      self._NameNone = False
      global _global_model_name_dict
      global _global_model_name_set
      if name is None:
          self._NameNone = True
          prefix = self.__class__.__name__.lower()
          if _global_model_name_dict.get(prefix) is not None:
              _global_model_name_dict[prefix] += 1
              name = prefix + "_" + str(_global_model_name_dict[prefix])
          else:
              _global_model_name_dict[prefix] = 0
              name = prefix
          while name in _global_model_name_set:
              _global_model_name_dict[prefix] += 1
              name = prefix + "_" + str(_global_model_name_dict[prefix])
          _global_model_name_set.add(name)
      else:
          if name in _global_model_name_set:
              raise ValueError(
                  "Model name '%s' has already been used by another model. Please change the model name."
                  % name
              )
          _global_model_name_set.add(name)
          _global_model_name_dict[name] = 0
  
      # Model properties
      self.name = name
  
      # Model state: train or test
      self.is_train = None
  
      # Model weights
      self._all_weights = None
      self._trainable_weights = None
      self._nontrainable_weights = None
  
      # Model args of all layers, ordered by all_layers
      self._config = None
  
      # Model inputs and outputs
      # TODO: note that in dynamic network, inputs and outputs are both None, may cause problem, test needed
      self._inputs = inputs
      self._outputs = outputs
  
      # Model converted into a Layer
      self._model_layer = None
  
      # Layer Node status
      self._nodes_fixed = False
  
      # Model layers
      self._all_layers = None
  
      if inputs is None and outputs is None:
          pass
  
      else:
          # check type of inputs and outputs
          check_order = ["inputs", "outputs"]
          for co, check_argu in enumerate([inputs, outputs]):
              if isinstance(
                  check_argu, (tf.Tensor, tf.SparseTensor, tf.Variable)
              ) or tf_ops.is_dense_tensor_like(check_argu):
                  pass
              elif isinstance(check_argu, list):
                  if len(check_argu) == 0:
                      raise ValueError(
                          "The argument `%s` is detected as an empty list. "
                          % check_order[co]
                          + "It should be either Tensor or a list of Tensor."
                      )
                  for idx in range(len(check_argu)):
                      if not isinstance(
                          check_argu[idx],
                          (tf.Tensor, tf.SparseTensor, tf.Variable),
                      ) or not tf_ops.is_dense_tensor_like(
                          check_argu[idx]
                      ):
                          raise TypeError(
                              "The argument `%s` should be either Tensor or a list of Tensor "
                              % (check_order[co])
                              + "but the %s[%d] is detected as %s"
                              % (
                                  check_order[co],
                                  idx,
                                  type(check_argu[idx]),
                              )
                          )
              else:
                  raise TypeError(
                      "The argument `%s` should be either Tensor or a list of Tensor but received %s"
                      % (check_order[co], type(check_argu))
                  )
  
          if not _check_tl_layer_tensors(inputs):
              raise TypeError(
                  "The argument `inputs` should be either Tensor or a list of Tensor "
                  "that come from TensorLayer's Input layer: tl.layers.Input(shape). "
              )
          if not _check_tl_layer_tensors(outputs):
              raise TypeError(
                  "The argument `outputs` should be either Tensor or a list of Tensor "
                  "that is/are outputs from some TensorLayer's layers, e.g. tl.layers.Dense, tl.layers.Conv2d."
              )
  
          # build network graph
          (
              self._node_by_depth,
              self._all_layers,
          ) = self._construct_graph()
  
          self._fix_nodes_for_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 3 to create a new Model object from inherited base classes: object with example: obj = Model(inputs, outputs, name)