Since PixelSSL is a script-based codebase, we need to export the PyTorch optimizers and LR schedulers so that the script can support them.
In the file pixelssl/nn/optimizer.py
, we have exported the optimizers supported by PyTorch == 1.0.0. There are three steps to export a new optimizer (supported by PyTorch > 1.0.0):
-
Refer to the
sgd
function in the file to implement the export function of the optimizer. -
Note that the
pytorch_support
function should be called to check whether the current PyTorch version supports the optimizer. -
Add the arguments related to the optimizer in the
add_parser_arguments
function.
Now you can call the LR optimizer in the script!
If you want to implement a new optimizer that PyTorch does not support, please refer to the official PyTorch documents for more details. After that, you can follow the above steps to export it. In the file pixelssl/nn/optimizer.py
, we provide the WDAdam (wdadam)
optimizer as an example.
In the file pixelssl/nn/lrer.py
, we have exported the LR schedulers supported by PyTorch == 1.0.0. There are four steps to export a new LR scheduler (supported by PyTorch > 1.0.0):
-
Refer to the
steplr
function in the file to implement the export function of the LR scheduler. -
Note that the
pytorch_support
function should be called to check whether the current PyTorch version supports the LR scheduler. -
Add the arguments related to the optimizer in the
add_parser_arguments
function. -
Put the name of the export function into either
EPOCH_LRERS
orITER_LRERS
.
In deep learning, the learning rate is updated after either each iteration or each epoch.EPOCH_LRERS
contains the LR schedulers that are updated once per epoch, andITER_LRERS
contains the LR schedulers that are updated once per iteration.
The LR schedulers supported by PyTorch usually belong toEPOCH_LRERS
.
Now you can call the LR scheduler in the script!
If you want to implement a new LR scheduler that PyTorch does not support, please refer to the official PyTorch documents for more details. After that, you can follow the above steps to export it. In the file pixelssl/nn/lrer.py
, we provide the PolynomialLR
LR scheduler as an example.