Keraflow
Deep Learning for Python.
|
Building block of a model. More...
Public Member Functions | |
def | __init__ |
def | set_trainable_params |
Register the layer's trainable parameters. More... | |
def | input_dimension |
Return the expected dimension of input tensor. More... | |
def | check_input_shape |
Check if the input shape(s) are valid. More... | |
def | init_param |
Initializes trainable parameter(s) of the layer. More... | |
def | output |
Calculates the output tensor of the layer given the input tensor(s). More... | |
def | output_shape |
Calculates the shape of the output tensor given the shape of the input tensor(s). More... | |
def | support_mask |
Whether the layer supports to carry on to the output tensor the mask embedded in input tensor. More... | |
def | pack_init_param |
Check keraflow.utils.generic_utils.serialize. | |
def | get_tensor_shape |
Get the shape of a tensor. More... | |
def | get_weights |
Gets trainable parameter name, value (numpy arrays) pairs. More... | |
def | embed |
Embeds the target layer such that its trainable parameters (along with regularizers and constraints on the parameters) are treated as the host layer's parameters and are updated during traing process. More... | |
def | __call__ |
Feed an input kensor or multiple input kensors to the layer and outputs another Kensor. More... | |
Static Public Member Functions | |
def | unpack_init_param |
Check keraflow.utils.generic_utils.unserialize. More... | |
Building block of a model.
A Layer transform input Kensor (s) into an output Kensor. The transformation could be one-to-one or many-to-one.
def keraflow.layers.base.Layer.__init__ | ( | self, | |
name = None , |
|||
trainable = True , |
|||
initial_weights = None , |
|||
regularizers = None , |
|||
constraints = None |
|||
) |
name | str. The name of the layer. |
trainable | boolean. Whether parameters of the layer will be updated during the training process. |
initial_weights | dict/list/single numpy array(s) or an Nd list. The initial value of the parameters of the layer. If None, a default initialization method (defined in each layer's init) is used. |
regularizers | dict/list of regularizer instance(s)/str(alias names of regurizers). The regularizers of the parameters of the layer. |
constraints | dict/list of constraint instance(s)/str(alias names of constraints). The constraints of the parameters of the layer. |
Trainable parameters of a Layer will be defined in a certain order (check init of each layer). For assigning initial_weights
, regularizers
, constraints
, the following rules apply:
initial_weights
, passing a single numpy array (or Nd list, will be casted into numpy array) is equivalent to passing a list with a single numpy array.def keraflow.layers.base.Layer.__call__ | ( | self, | |
input_kensors | |||
) |
def keraflow.layers.base.Layer.check_input_shape | ( | self, | |
input_shapes | |||
) |
Check if the input shape(s) are valid.
Recommended to implement if inheriting MultiInputLayer (multiple inputs) to help keraflow detect incorrect input shapes. Default behaviors:
input_shapes | tuple/list of tuple. The input shape(s) of input kensor(s) |
def keraflow.layers.base.Layer.embed | ( | self, | |
target_layer | |||
) |
Embeds the target layer such that its trainable parameters (along with regularizers and constraints on the parameters) are treated as the host layer's parameters and are updated during traing process.
Use it in a custmoized layer's output() function like:
target_layer | Layer. The target layer. |
def keraflow.layers.base.Layer.get_tensor_shape | ( | self, | |
tensor | |||
) |
Get the shape of a tensor.
Note that the we could only get the shape if the tensor is outputted by a layer or an embedded layer.
tensor | backend tensor. |
def keraflow.layers.base.Layer.get_weights | ( | self | ) |
Gets trainable parameter name, value (numpy arrays) pairs.
The names are decided by Layer.init_param of each layer.
def keraflow.layers.base.Layer.init_param | ( | self, | |
input_shape | |||
) |
Initializes trainable parameter(s) of the layer.
Inherited layer class should implement this function if the layer has trainable parameter(s). Always use Layer.set_trainable_params to register parameters.
input_shape | list of tuple(s). |
def keraflow.layers.base.Layer.input_dimension | ( | self | ) |
Return the expected dimension of input tensor.
Recommended to implement if inheriting Layer (single input) to help keraflow detect incorrect input shape.
def keraflow.layers.base.Layer.output | ( | self, | |
input_tensors | |||
) |
Calculates the output tensor of the layer given the input tensor(s).
All layers must implement this function.
input_tensors | backend tensor/list of backend tensors. |
def keraflow.layers.base.Layer.output_shape | ( | self, | |
input_shapes | |||
) |
Calculates the shape of the output tensor given the shape of the input tensor(s).
input_shapes | tuple/list of tuple. The shape(s) of the input tensor(s). |
def keraflow.layers.base.Layer.set_trainable_params | ( | self, | |
args | |||
) |
Register the layer's trainable parameters.
Note that the order of args affect how user initialize the layer with initial_weights, regularizers, and constraints.
args | arbitrary length of arguments in the pattern of ('param_name1': tensor1, 'param_name2': tensor2, ...) |
def keraflow.layers.base.Layer.support_mask | ( | self | ) |
Whether the layer supports to carry on to the output tensor the mask embedded in input tensor.
If return True, the output tensor will be assigned a .keraflow_mask
attribute same as the input tensor. This mask is currently used only by recurrent layers.
|
static |
Check keraflow.utils.generic_utils.unserialize.
params | dict. The result from pack_init_param |