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: Load model weights from a given file, which should be previously saved by self.save_weights().
  
  Parameters
  ----------
  filepath : str
      Filename from which the model weights will be loaded.
  format : str or None
      If not specified (None), the postfix of the filepath will be used to decide its format. If specified,
      value should be 'hdf5', 'npz', 'npz_dict' or 'ckpt'. Other format is not supported now.
      In addition, it should be the same format when you saved the file using self.save_weights().
      Default is None.
  in_order : bool
      Allow loading weights into model in a sequential way or by name. Only useful when 'format' is 'hdf5'.
      If 'in_order' is True, weights from the file will be loaded into model in a sequential way.
      If 'in_order' is False, weights from the file will be loaded into model by matching the name
      with the weights of the model, particularly useful when trying to restore model in eager(graph) mode from
      a weights file which is saved in graph(eager) mode.
      Default is True.
  skip : bool
      Allow skipping weights whose name is mismatched between the file and model. Only useful when 'format' is
      'hdf5' or 'npz_dict'. If 'skip' is True, 'in_order' argument will be ignored and those loaded weights
      whose name is not found in model weights (self.all_weights) will be skipped. If 'skip' is False, error will
      occur when mismatch is found.
      Default is False.
  
  Examples
  --------
  1) load model from a hdf5 file.
  >>> net = tl.models.vgg16()
  >>> net.load_weights('./model_graph.h5', in_order=False, skip=True) # load weights by name, skipping mismatch
  >>> net.load_weights('./model_eager.h5') # load sequentially
  
  2) load model from a npz file
  >>> net.load_weights('./model.npz')
  
  2) load model from a npz file, which is saved as npz_dict previously
  >>> net.load_weights('./model.npz', format='npz_dict')
  
  Notes
  -------
  1) 'in_order' is only useful when 'format' is 'hdf5'. If you are trying to load a weights file which is
     saved in a different mode, it is recommended to set 'in_order' be True.
  2) 'skip' is useful when 'format' is 'hdf5' or 'npz_dict'. If 'skip' is True,
     'in_order' argument will be ignored.
docstr_tok: ["Load","model","weights","from","a","given","file",",","which","should","be","previously","saved","by","self.save_weights","(",")",".","Parameters","--","--","--","--","--","filepath",":","str","Filename","from","which","the","model","weights","will","be","loaded",".","format",":","str","or","None","If","not","specified","(","None",")",",","the","postfix","of","the","filepath","will","be","used","to","decide","its","format",".","If","specified",",","value","should","be","'hdf5","'",",","'npz","'",",","'npz_dict","'","or","'ckpt","'",".","Other","format","is","not","supported","now",".","In","addition",",","it","should","be","the","same","format","when","you","saved","the","file","using","self.save_weights","(",")",".","Default","is","None",".","in_order",":","bool","Allow","loading","weights","into","model","in","a","sequential","way","or","by","name",".","Only","useful","when","'format","'","is","'hdf5","'",".","If","'in_order","'","is","True",",","weights","from","the","file","will","be","loaded","into","model","in","a","sequential","way",".","If","'in_order","'","is","False",",","weights","from","the","file","will","be","loaded","into","model","by","matching","the","name","with","the","weights","of","the","model",",","particularly","useful","when","trying","to","restore","model","in","eager","(","graph",")","mode","from","a","weights","file","which","is","saved","in","graph","(","eager",")","mode",".","Default","is","True",".","skip",":","bool","Allow","skipping","weights","whose","name","is","mismatched","between","the","file","and","model",".","Only","useful","when","'format","'","is","'hdf5","'","or","'npz_dict","'",".","If","'skip","'","is","True",",","'in_order","'","argument","will","be","ignored","and","those","loaded","weights","whose","name","is","not","found","in","model","weights","(","self.all_weights",")","will","be","skipped",".","If","'skip","'","is","False",",","error","will","occur","when","mismatch","is","found",".","Default","is","False",".","Examples","--","--","--","--","1",")","load","model","from","a","hdf5","file",".",">",">",">","net","=","tl.models.vgg16","(",")",">",">",">","net.load_weights","(","'.\/model_graph.h5","'",",","in_order=False",",","skip=True",")","#","load","weights","by","name",",","skipping","mismatch",">",">",">","net.load_weights","(","'.\/model_eager.h5","'",")","#","load","sequentially","2",")","load","model","from","a","npz","file",">",">",">","net.load_weights","(","'.\/model.npz","'",")","2",")","load","model","from","a","npz","file",",","which","is","saved","as","npz_dict","previously",">",">",">","net.load_weights","(","'.\/model.npz","'",",","format='npz_dict","'",")","Notes","--","--","--","-","1",")","'in_order","'","is","only","useful","when","'format","'","is","'hdf5","'",".","If","you","are","trying","to","load","a","weights","file","which","is","saved","in","a","different","mode",",","it","is","recommended","to","set","'in_order","'","be","True",".","2",")","'skip","'","is","useful","when","'format","'","is","'hdf5","'","or","'npz_dict","'",".","If","'skip","'","is","True",",","'in_order","'","argument","will","be","ignored","."]
code: def load_weights(
      self, filepath, format=None, in_order=True, skip=False
  ):
      """Load model weights from a given file, which should be previously saved by self.save_weights().
  
      Parameters
      ----------
      filepath : str
          Filename from which the model weights will be loaded.
      format : str or None
          If not specified (None), the postfix of the filepath will be used to decide its format. If specified,
          value should be 'hdf5', 'npz', 'npz_dict' or 'ckpt'. Other format is not supported now.
          In addition, it should be the same format when you saved the file using self.save_weights().
          Default is None.
      in_order : bool
          Allow loading weights into model in a sequential way or by name. Only useful when 'format' is 'hdf5'.
          If 'in_order' is True, weights from the file will be loaded into model in a sequential way.
          If 'in_order' is False, weights from the file will be loaded into model by matching the name
          with the weights of the model, particularly useful when trying to restore model in eager(graph) mode from
          a weights file which is saved in graph(eager) mode.
          Default is True.
      skip : bool
          Allow skipping weights whose name is mismatched between the file and model. Only useful when 'format' is
          'hdf5' or 'npz_dict'. If 'skip' is True, 'in_order' argument will be ignored and those loaded weights
          whose name is not found in model weights (self.all_weights) will be skipped. If 'skip' is False, error will
          occur when mismatch is found.
          Default is False.
  
      Examples
      --------
      1) load model from a hdf5 file.
      >>> net = tl.models.vgg16()
      >>> net.load_weights('./model_graph.h5', in_order=False, skip=True) # load weights by name, skipping mismatch
      >>> net.load_weights('./model_eager.h5') # load sequentially
  
      2) load model from a npz file
      >>> net.load_weights('./model.npz')
  
      2) load model from a npz file, which is saved as npz_dict previously
      >>> net.load_weights('./model.npz', format='npz_dict')
  
      Notes
      -------
      1) 'in_order' is only useful when 'format' is 'hdf5'. If you are trying to load a weights file which is
         saved in a different mode, it is recommended to set 'in_order' be True.
      2) 'skip' is useful when 'format' is 'hdf5' or 'npz_dict'. If 'skip' is True,
         'in_order' argument will be ignored.
  
      """
      if not os.path.exists(filepath):
          raise FileNotFoundError(
              "file {} doesn't exist.".format(filepath)
          )
  
      if format is None:
          format = filepath.split(".")[-1]
  
      if format == "hdf5" or format == "h5":
          if skip == True or in_order == False:
              # load by weights name
              utils.load_hdf5_to_weights(filepath, self, skip)
          else:
              # load in order
              utils.load_hdf5_to_weights_in_order(filepath, self)
      elif format == "npz":
          utils.load_and_assign_npz(filepath, self)
      elif format == "npz_dict":
          utils.load_and_assign_npz_dict(filepath, self, skip)
      elif format == "ckpt":
          # TODO: enable this when tf save ckpt is enabled
          raise NotImplementedError(
              "ckpt load/save is not supported now."
          )
      else:
          raise ValueError(
              "File format must be 'hdf5', 'npz', 'npz_dict' or 'ckpt'. "
              "Other format is not supported now."
          )
  
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 33 for calling the Model obj's underlying member method code with example usage: obj.load_weights(filepath, format, in_order, skip) without return types