A model is a directed Kensor graph.
More...
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
| def keraflow.models.Model.__init__ |
( |
|
self, |
|
|
|
inputs, |
|
|
|
outputs, |
|
|
|
name = None |
|
) |
| |
- Parameters
-
| inputs | single/list of Input. |
| outputs | single/list of Kensor. |
| name | str. Name of the model for easy debugging. |
| def keraflow.models.Model.compile |
( |
|
self, |
|
|
|
optimizer, |
|
|
|
loss, |
|
|
|
metrics = [] |
|
) |
| |
Configure the model and prepare inner utilized tensors.
- Parameters
-
| optimizer | str(name of optimizer class)/optimizer object. See keraflow.optimizers |
| loss | dict/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. |
| metrics | dict/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
-
| x | dict/list/single numpy array(s) or an Nd list. Input data. Rules for assigning x is the same as in fit. |
| y | dict/list/single numpy array(s) or an Nd list. True answer. Rules for assigning y is the same as in fit. |
| sample_weights | list/numpy array. Weights of each sample. |
| batch_size | int. The batch size to predict the testing data. Might cause memorage error if set too large. |
| train_mode | boolean. 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
-
| x | dict/list/single numpy array(s) or an Nd list. Input data. |
| y | dict/list/single numpy array(s) or an Nd list. True answer. |
| batch_size | int. Number of samples per gradient update. Report error if unequal to (not None) input kensors' batch_size. |
| nb_epoch | int. The number of epochs to train the model. |
| verbose | 0 for no logging, 1 for logging to stdout. |
| callbacks | list of keraflow.callbacks.Callback instances. |
| sample_weights | list/numpy array. Weights of each sample. |
| validation_split | float between 0 and 1. Fraction of the training data to be used as validation data. |
| validation_data | tuple (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. |
| shuffle | boolean. 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:
- If a dict is passed (and the corresponding input kensors and output layers are named), the values are assigned according to the keys.
- If a list of numpy array is passed, the arrays are assigned to the kensor in the order you construct the model.
- 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_fname | str. The file name storing the model architecture. |
| weight_fname | str. 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
-
| x | dict/list/single numpy array(s) or an Nd list. Input data. Rules for assigning x is the same as in fit. |
| batch_size | int. The batch size to predict the testing data. Might cause memorage error if set too large. |
| train_mode | boolean. 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_fname | str. The file name for storing the model architecture. Should ends with either 'json' or 'yaml' for different storing types. |
| kwargs | keyword arguments. The keyword arguments for json.dump or yaml.dump. |
| overwrite | Whether 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_fname | str. The file name for storing the model architecture. Should ends with either 'json' or 'yaml' for different storing types. |
| weight_fname | str. The file name for storing weights of the model. If None, the weights are not saved. |
| overwrite | Whether to overwrite existing files. |
| kwargs | keyword arguments. The keyword arguments for json.dump or yaml.dump. |
| def keraflow.models.Model.save_weights |
( |
|
self, |
|
|
|
weight_fname, |
|
|
|
overwrite = False |
|
) |
| |
- Parameters
-
| weight_fname | str. The file name for storing weights of the model. If None, the weights are not saved. |
| overwrite | Whether to overwrite existing files. |