otx.core.optimizer#

Modules related to an optimizer.

Classes

OptimizerCallableSupportHPO(optimizer_cls, ...)

Optimizer callable supports OTX hyper-parameter optimization (HPO) algorithm.

class otx.core.optimizer.OptimizerCallableSupportHPO(optimizer_cls: type[Optimizer] | str, optimizer_kwargs: dict[str, int | float | bool])[source]#

Bases: object

Optimizer callable supports OTX hyper-parameter optimization (HPO) algorithm.

It makes OptimizerCallable pickelable and accessible to parameters. It is used for HPO and adaptive batch size.

Parameters:
  • optimizer_cls – Optimizer class type or string class import path. See examples for details.

  • optimizer_kwargs – Keyword arguments used for the initialization of the given optimizer_cls.

Examples

This is an example to create MobileNetV3ForMulticlassCls with a SGD optimizer and custom configurations.

```python from torch.optim import SGD from otx.algo.classification.mobilenet_v3_large import MobileNetV3ForMulticlassCls

model = MobileNetV3ForMulticlassCls(

num_classes=3, optimizer=OptimizerCallableSupportHPO(

optimizer_cls=SGD, optimizer_kwargs={

“lr”: 0.1, “momentum”: 0.9, “weight_decay”: 1e-4,

},

),

)#

It can be created from the string class import path such as

```python from otx.algo.classification.mobilenet_v3_large import MobileNetV3ForMulticlassCls

model = MobileNetV3ForMulticlassCls(

num_classes=3, optimizer=OptimizerCallableSupportHPO(

optimizer_cls=”torch.optim.SGD”, optimizer_kwargs={

“lr”: 0.1, “momentum”: 0.9, “weight_decay”: 1e-4,

},

),

)#

__call__(params: params_t) Optimizer[source]#

Create torch.optim.Optimizer instance for the given parameters.

classmethod from_callable(func: OptimizerCallable) OptimizerCallableSupportHPO[source]#

Create this class instance from an existing optimizer callable.