Utils.ema(模型平均) 模块¶
ppsci.utils.ema
¶
AveragedModel
¶
Bases: Layer
Base class for Averaged Model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Layer
|
The model to be averaged. |
required |
decay |
float
|
The decay rate for averaging. |
None
|
Source code in ppsci/utils/ema.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
apply_shadow()
¶
Set averaged model parameters to online model.
Source code in ppsci/utils/ema.py
restore()
¶
Restore online model parameters from backup parameter dict.
Source code in ppsci/utils/ema.py
ExponentialMovingAverage
¶
Bases: AveragedModel
Implements the exponential moving average (EMA) of the model.
All parameters are updated by the formula as below:
Where \(\alpha\) is the decay rate, \(\theta_{EMA}^{t}\) is the moving average parameters and \(\theta^{t}\) is the online parameters at step \(t\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Layer
|
The model to be averaged. |
required |
decay |
float
|
The decay rate for averaging. |
0.9
|
Source code in ppsci/utils/ema.py
StochasticWeightAverage
¶
Bases: AveragedModel
Implements the stochastic weight averaging (SWA) of the model.
Stochastic Weight Averaging was proposed in Averaging Weights Leads to Wider Optima and Better Generalization,
All parameters are updated by the formula as below:
Where \(\theta_{SWA}^{t}\) is the average parameters between step \(t_0\) and \(t\), \(\theta^{i}\) is the online parameters at step \(i\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Layer
|
The model to be averaged. |
required |