multiml.task.keras.keras_ensemble module
- class multiml.task.keras.keras_ensemble.EnsembleTask(subtasks, dropout_rate=None, individual_loss=False, individual_loss_weights=0.0, **kwargs)
Bases:
KerasBaseTask
- __init__(subtasks, dropout_rate=None, individual_loss=False, individual_loss_weights=0.0, **kwargs)
- Parameters:
subtasks (list) – list of task instances.
dropout_rate (float) – dropout_rate for ensemble weights. If None, no dropout.
individual_loss (bool) – use multiple outputs
individual_loss_weights (float) – coefficient for multiple outputs
**kwargs – Arbitrary keyword arguments
- compile()
Compile model, optimizer and loss.
Compiled objects will be avaialble via
self.ml.model
,self.ml.optimizer
andself.ml.loss
.Examples
>>> # compile all together, >>> self.compile() >>> # which is equivalent to: >>> self.build_model() # set self._model >>> self.compile_model() # set self.ml.model >>> self.compile_optimizer() # set self.ml.optimizer >>> self.compile_loss() # set self.ml.loss
- compile_loss()
Compile keras model.
- build_model()
Build model.
- get_input_true_data(phase)
Get input and true data.
- Parameters:
phase (str) – data type (train, valid, test or None).
- Returns:
(input, true) data for model.
- Return type:
tuple
- get_inputs()
Returns keras Input from input_var_names.
- get_submodel_names()
Returns subtask_id used in ensembling.
- Returns:
list of subtask_id
- Return type:
list (str)
- get_submodel(i_models)
Get a submodel by model index.
- Parameters:
i_models (int) – submodel index
- Returns:
submodel for the input index
- Return type:
- static get_ensemble_weights(model)
Collect ensemble_weights in the keras model.
- Parameters:
model (keras.Model) –
- Returns:
list of ensemble weights
- Return type:
list (tf.Variable)