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: Input filepath, save model weights into a file of given format.
      Use self.load_weights() to restore.
  
  Parameters
  ----------
  filepath : str
      Filename to which the model weights will be saved.
  format : str or None
      Saved file format.
      Value should be None, 'hdf5', 'npz', 'npz_dict' or 'ckpt'. Other format is not supported now.
      1) If this is set to None, then the postfix of filepath will be used to decide saved format.
      If the postfix is not in ['h5', 'hdf5', 'npz', 'ckpt'], then file will be saved in hdf5 format by default.
      2) 'hdf5' will save model weights name in a list and each layer has its weights stored in a group of
      the hdf5 file.
      3) 'npz' will save model weights sequentially into a npz file.
      4) 'npz_dict' will save model weights along with its name as a dict into a npz file.
      5) 'ckpt' will save model weights into a tensorflow ckpt file.
  
      Default None.
  
  Examples
  --------
  1) Save model weights in hdf5 format by default.
  >>> net = tl.models.vgg16()
  >>> net.save_weights('./model.h5')
  ...
  >>> net.load_weights('./model.h5')
  
  2) Save model weights in npz/npz_dict format
  >>> net = tl.models.vgg16()
  >>> net.save_weights('./model.npz')
  >>> net.save_weights('./model.npz', format='npz_dict')
docstr_tok: ["Input","filepath",",","save","model","weights","into","a","file","of","given","format",".","Use","self.load_weights","(",")","to","restore",".","Parameters","--","--","--","--","--","filepath",":","str","Filename","to","which","the","model","weights","will","be","saved",".","format",":","str","or","None","Saved","file","format",".","Value","should","be","None",",","'hdf5","'",",","'npz","'",",","'npz_dict","'","or","'ckpt","'",".","Other","format","is","not","supported","now",".","1",")","If","this","is","set","to","None",",","then","the","postfix","of","filepath","will","be","used","to","decide","saved","format",".","If","the","postfix","is","not","in","[","'h5","'",",","'hdf5","'",",","'npz","'",",","'ckpt","'","]",",","then","file","will","be","saved","in","hdf5","format","by","default",".","2",")","'hdf5","'","will","save","model","weights","name","in","a","list","and","each","layer","has","its","weights","stored","in","a","group","of","the","hdf5","file",".","3",")","'npz","'","will","save","model","weights","sequentially","into","a","npz","file",".","4",")","'npz_dict","'","will","save","model","weights","along","with","its","name","as","a","dict","into","a","npz","file",".","5",")","'ckpt","'","will","save","model","weights","into","a","tensorflow","ckpt","file",".","Default","None",".","Examples","--","--","--","--","1",")","Save","model","weights","in","hdf5","format","by","default",".",">",">",">","net","=","tl.models.vgg16","(",")",">",">",">","net.save_weights","(","'.\/model.h5","'",")","...",">",">",">","net.load_weights","(","'.\/model.h5","'",")","2",")","Save","model","weights","in","npz\/npz_dict","format",">",">",">","net","=","tl.models.vgg16","(",")",">",">",">","net.save_weights","(","'.\/model.npz","'",")",">",">",">","net.save_weights","(","'.\/model.npz","'",",","format='npz_dict","'",")"]
code: def save_weights(self, filepath, format=None):
      """Input filepath, save model weights into a file of given format.
          Use self.load_weights() to restore.
  
      Parameters
      ----------
      filepath : str
          Filename to which the model weights will be saved.
      format : str or None
          Saved file format.
          Value should be None, 'hdf5', 'npz', 'npz_dict' or 'ckpt'. Other format is not supported now.
          1) If this is set to None, then the postfix of filepath will be used to decide saved format.
          If the postfix is not in ['h5', 'hdf5', 'npz', 'ckpt'], then file will be saved in hdf5 format by default.
          2) 'hdf5' will save model weights name in a list and each layer has its weights stored in a group of
          the hdf5 file.
          3) 'npz' will save model weights sequentially into a npz file.
          4) 'npz_dict' will save model weights along with its name as a dict into a npz file.
          5) 'ckpt' will save model weights into a tensorflow ckpt file.
  
          Default None.
  
      Examples
      --------
      1) Save model weights in hdf5 format by default.
      >>> net = tl.models.vgg16()
      >>> net.save_weights('./model.h5')
      ...
      >>> net.load_weights('./model.h5')
  
      2) Save model weights in npz/npz_dict format
      >>> net = tl.models.vgg16()
      >>> net.save_weights('./model.npz')
      >>> net.save_weights('./model.npz', format='npz_dict')
  
      """
      if self.all_weights is None or len(self.all_weights) == 0:
          logging.warning(
              "Model contains no weights or layers haven't been built, nothing will be saved"
          )
          return
  
      if format is None:
          postfix = filepath.split(".")[-1]
          if postfix in ["h5", "hdf5", "npz", "ckpt"]:
              format = postfix
          else:
              format = "hdf5"
  
      if format == "hdf5" or format == "h5":
          utils.save_weights_to_hdf5(filepath, self)
      elif format == "npz":
          utils.save_npz(self.all_weights, filepath)
      elif format == "npz_dict":
          utils.save_npz_dict(self.all_weights, filepath)
      elif format == "ckpt":
          # TODO: enable this when tf save ckpt is enabled
          raise NotImplementedError(
              "ckpt load/save is not supported now."
          )
      else:
          raise ValueError(
              "Save 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 32 for calling the Model obj's underlying member method code with example usage: obj.save_weights(filepath, format) without return types