Trainer API¶
Parameters¶
-
paddle.v2.parameters.
create
(layers)¶ Create parameter pool by topology.
Parameters: layers – Returns:
-
class
paddle.v2.parameters.
Parameters
¶ Parameters is a dictionary contains Paddle’s parameter. The key of Parameters is the name of parameter. The value of Parameters is a plain
numpy.ndarry
.Basically usage is
data = paddle.layers.data(...) ... out = paddle.layers.fc(...) parameters = paddle.parameters.create(out) parameter_names = parameters.names() fc_mat = parameters.get('fc') print fc_mat
-
keys
()¶ keys are the names of each parameter.
Returns: list of parameter name Return type: list
-
names
()¶ names of each parameter.
Returns: list of parameter name Return type: list
-
has_key
(key)¶ has_key return true if there are such parameter name == key
Parameters: key (basestring) – Parameter name Returns: True if contains such key
-
get_shape
(key)¶ get shape of the parameter.
Parameters: key (basestring) – parameter name Returns: parameter’s shape Return type: tuple
-
get
(parameter_name)¶ Get parameter by parameter name.
Note: It will always copy the parameter from C++ side. Parameters: parameter_name (basestring) – parameter name Returns: The parameter matrix. Return type: np.ndarray
-
set
(parameter_name, value)¶ Set parameter by parameter name & matrix.
Parameters: - parameter_name (basestring) – parameter name
- value (np.ndarray) – parameter matrix
Returns: Nothing.
-
append_gradient_machine
(gradient_machine)¶ append gradient machine to parameters. This method is used internally in Trainer.train.
Parameters: gradient_machine (api.GradientMachine) – Paddle C++ GradientMachine object. Returns:
-
Trainer¶
-
class
paddle.v2.trainer.
SGD
(cost, parameters, update_equation)¶ Simple SGD Trainer. TODO(yuyang18): Complete comments
Parameters: - update_equation (paddle.v2.optimizer.Optimizer) – The optimizer object.
- cost (paddle.v2.config_base.Layer) – Target cost that neural network should be optimized.
- parameters (paddle.v2.parameters.Parameters) – The parameters dictionary.
-
train
(reader, num_passes=1, event_handler=None, reader_dict=None)¶ Training method. Will train num_passes of input data.
Parameters: - reader –
- num_passes – The total train passes.
- event_handler ((BaseEvent) => None) – Event handler. A method will be invoked when event occurred.
Returns:
Event¶
All training events.
There are:
- BeginIteration
- EndIteration
- BeginPass
- EndPass
TODO(yuyang18): Complete it!
-
class
paddle.v2.event.
TestResult
(evaluator, cost)¶ Result that trainer.test return.
-
class
paddle.v2.event.
BeginPass
(pass_id)¶ Event On One Pass Training Start.
-
class
paddle.v2.event.
EndPass
(pass_id, evaluator)¶ Event On One Pass Training Complete.
-
class
paddle.v2.event.
BeginIteration
(pass_id, batch_id)¶ Event On One Batch Training Start.
-
class
paddle.v2.event.
EndIteration
(pass_id, batch_id, cost, evaluator)¶ Event On One Batch Training Complete.