Settings
- class plugins.train.model._base.settings.Settings(arguments: Namespace, mixed_precision: bool, is_predict: bool)
Bases:
objectCore training settings.
Sets backend settings prior to launching the model.
- Parameters:
arguments (Namespace) – The arguments that were passed to the train or convert process as generated from Faceswap’s command line arguments
mixed_precision (bool) –
Trueif Mixed Precision training should be used otherwiseFalseis_predict (bool) –
Trueif the model is being loaded for inference,Falseif the model is being loaded for training. Default:False
Attributes Summary
Trueif mixed precision training has been enabled, otherwiseFalse.Methods Summary
check_model_precision(model, state)Check the model's precision.
get_mixed_precision_layers(build_func, inputs)Get and store the mixed precision layers from a full precision enabled model.
loss_scale_optimizer(optimizer)Optimize loss scaling for mixed precision training.
Attributes Documentation
- use_mixed_precision
Trueif mixed precision training has been enabled, otherwiseFalse.
Methods Documentation
- check_model_precision(model: keras.models.Model, state: State) keras.models.Model
Check the model’s precision.
If this is a new model, then Rewrite an existing model’s training precision mode from mixed-float16 to float32 or vice versa.
This is not easy to do in keras, so we edit the model’s config to change the dtype policy for compatible layers. Create a new model from this config, then port the weights from the old model to the new model.
- Parameters:
model (keras.models.Model) – The original saved keras model to rewrite the dtype
state (State) – The State information for the model
- Return type:
The original model with the datatype updated
- get_mixed_precision_layers(build_func: Callable[[list[keras.layers.Layer]], keras.models.Model], inputs: list[keras.layers.Layer]) tuple[keras.models.Model, list[str]]
Get and store the mixed precision layers from a full precision enabled model.
- Parameters:
build_func (Callable[[list[keras.layers.Layer]], keras.models.Model]) – The function to be called to compile the newly created model
inputs (list[keras.layers.Layer]) – The inputs to the model to be compiled
- Returns:
model – The built model in fp32
names – The list of layer names within the full precision model that can be switched to mixed precision
- Return type:
tuple[keras.models.Model, list[str]]
- classmethod loss_scale_optimizer(optimizer: Optimizer) LossScaleOptimizer
Optimize loss scaling for mixed precision training.
- Parameters:
optimizer (Optimizer) – The optimizer instance to wrap
- Return type:
The original optimizer with loss scaling applied
- check_model_precision(model: keras.models.Model, state: State) keras.models.Model
Check the model’s precision.
If this is a new model, then Rewrite an existing model’s training precision mode from mixed-float16 to float32 or vice versa.
This is not easy to do in keras, so we edit the model’s config to change the dtype policy for compatible layers. Create a new model from this config, then port the weights from the old model to the new model.
- Parameters:
model (keras.models.Model) – The original saved keras model to rewrite the dtype
state (State) – The State information for the model
- Return type:
The original model with the datatype updated
- get_mixed_precision_layers(build_func: Callable[[list[keras.layers.Layer]], keras.models.Model], inputs: list[keras.layers.Layer]) tuple[keras.models.Model, list[str]]
Get and store the mixed precision layers from a full precision enabled model.
- Parameters:
build_func (Callable[[list[keras.layers.Layer]], keras.models.Model]) – The function to be called to compile the newly created model
inputs (list[keras.layers.Layer]) – The inputs to the model to be compiled
- Returns:
model – The built model in fp32
names – The list of layer names within the full precision model that can be switched to mixed precision
- Return type:
tuple[keras.models.Model, list[str]]
- classmethod loss_scale_optimizer(optimizer: Optimizer) LossScaleOptimizer
Optimize loss scaling for mixed precision training.
- Parameters:
optimizer (Optimizer) – The optimizer instance to wrap
- Return type:
The original optimizer with loss scaling applied
- property use_mixed_precision: bool
Trueif mixed precision training has been enabled, otherwiseFalse.