Keraflow
Deep Learning for Python.
 All Classes Namespaces Functions Pages
keraflow.models.Model Class Reference

A model is a directed Kensor graph. More...

Inheritance diagram for keraflow.models.Model:
keraflow.models.Sequential

Public Member Functions

def __init__
 
def compile
 Configure the model and prepare inner utilized tensors. More...
 
def fit
 Adjust model parameters to fit input data and true answers. More...
 
def predict
 Returns the output values given the input data. More...
 
def evaluate
 Returns the loss value and metrics values given the input data and true answer. More...
 
def save_to_file
 Save the model to disk for later use. More...
 
def save_arch
 
def save_weights
 

Static Public Member Functions

def load_from_file
 Load model from disk. More...
 

Detailed Description

A model is a directed Kensor graph.

Kensor connects with one another by Layer.__call__ and users specify the input kensors and out kensors to build the graph.

See Also
An Overview of Model

Constructor & Destructor Documentation

def keraflow.models.Model.__init__ (   self,
  inputs,
  outputs,
  name = None 
)
Parameters
inputssingle/list of Input.
outputssingle/list of Kensor.
namestr. Name of the model for easy debugging.

Member Function Documentation

def keraflow.models.Model.compile (   self,
  optimizer,
  loss,
  metrics = [] 
)

Configure the model and prepare inner utilized tensors.

Parameters
optimizerstr(name of optimizer class)/optimizer object. See keraflow.optimizers
lossdict/list/single objective function(s)/str(name of objective function(s)). Objective(s) for output(s). See Objectives for a list of predefined objective functions.
metricsdict/list/single objective function(s)/str(name of objective function(s)). Objective(s) for outputs(s). See Objectives for a list of predefined objective functions.
def keraflow.models.Model.evaluate (   self,
  x,
  y,
  sample_weights = None,
  batch_size = 32,
  train_mode = False 
)

Returns the loss value and metrics values given the input data and true answer.

Parameters
xdict/list/single numpy array(s) or an Nd list. Input data. Rules for assigning x is the same as in fit.
ydict/list/single numpy array(s) or an Nd list. True answer. Rules for assigning y is the same as in fit.
sample_weightslist/numpy array. Weights of each sample.
batch_sizeint. The batch size to predict the testing data. Might cause memorage error if set too large.
train_modeboolean. For debugging usage. Do not use this flag in your code.
def keraflow.models.Model.fit (   self,
  x,
  y,
  batch_size = 32,
  nb_epoch = 10,
  verbose = 1,
  callbacks = [],
  sample_weights = None,
  validation_split = 0.0,
  validation_data = None,
  shuffle = True 
)

Adjust model parameters to fit input data and true answers.

Parameters
xdict/list/single numpy array(s) or an Nd list. Input data.
ydict/list/single numpy array(s) or an Nd list. True answer.
batch_sizeint. Number of samples per gradient update. Report error if unequal to (not None) input kensors' batch_size.
nb_epochint. The number of epochs to train the model.
verbose0 for no logging, 1 for logging to stdout.
callbackslist of keraflow.callbacks.Callback instances.
sample_weightslist/numpy array. Weights of each sample.
validation_splitfloat between 0 and 1. Fraction of the training data to be used as validation data.
validation_datatuple (val_x, val_y), or (val_x, val_y, val_sample_weight) to be used as held-out validation data. val_x, val_y, and val_sample_weights accept the same type of data as x, y, and sample_weights respectively. This argument override validation_split argument.
shuffleboolean. Whether to shuffle the samples at each epoch.
Returns
list of dict. Each dict in the list describes the loss (and validation loss if applicable) and metrics for one epoch.
Note
Rules for assigning x, y:
  1. If a dict is passed (and the corresponding input kensors and output layers are named), the values are assigned according to the keys.
  2. If a list of numpy array is passed, the arrays are assigned to the kensor in the order you construct the model.
  3. If there's only a single input/output kensor, a single numpy array (or Nd list, will be casted into numpy array) is acceptable.
def keraflow.models.Model.load_from_file (   arch_fname,
  weight_fname = None 
)
static

Load model from disk.

Parameters
arch_fnamestr. The file name storing the model architecture.
weight_fnamestr. The file name storing weights of the model. If None, the weights are not loaded.
Returns
Model. The Model instance reconstructed from the file. Note that you should compile it before using it.
def keraflow.models.Model.predict (   self,
  x,
  batch_size = 32,
  train_mode = False 
)

Returns the output values given the input data.

Parameters
xdict/list/single numpy array(s) or an Nd list. Input data. Rules for assigning x is the same as in fit.
batch_sizeint. The batch size to predict the testing data. Might cause memorage error if set too large.
train_modeboolean. For debugging usage. Do not use this flag in your code.
Returns
list of numpy arrays. The length of the list is equal to the number of output channels.
def keraflow.models.Model.save_arch (   self,
  arch_fname,
  overwrite = False,
  kwargs 
)
Parameters
arch_fnamestr. The file name for storing the model architecture. Should ends with either 'json' or 'yaml' for different storing types.
kwargskeyword arguments. The keyword arguments for json.dump or yaml.dump.
overwriteWhether to overwrite existing files.
def keraflow.models.Model.save_to_file (   self,
  arch_fname,
  weight_fname = None,
  overwrite = False,
  kwargs 
)

Save the model to disk for later use.

Combining operations done by save_arch and save_weights.

Parameters
arch_fnamestr. The file name for storing the model architecture. Should ends with either 'json' or 'yaml' for different storing types.
weight_fnamestr. The file name for storing weights of the model. If None, the weights are not saved.
overwriteWhether to overwrite existing files.
kwargskeyword arguments. The keyword arguments for json.dump or yaml.dump.
def keraflow.models.Model.save_weights (   self,
  weight_fname,
  overwrite = False 
)
Parameters
weight_fnamestr. The file name for storing weights of the model. If None, the weights are not saved.
overwriteWhether to overwrite existing files.