AdversarialOptimizer#

class deepinv.training.AdversarialOptimizer(optimizer_g, optimizer_d, zero_grad_g_only=False, zero_grad_d_only=False)[source]#

Bases: object

Optimizer for adversarial training that encapsulates both generator and discriminator’s optimizers.

Parameters:
  • optimizer_g (torch.optim.Optimizer) – generator’s torch optimizer

  • optimizer_d (torch.optim.Optimizer) – discriminator’s torch optimizer

  • zero_grad_g_only (bool) – whether to only zero_grad generator, defaults to False

  • zero_grad_d_only (bool) – whether to only zero_grad discriminator, defaults to False

load_state_dict(state_dict)[source]#

Load state_dict which must have “G” and “D” keys for generator and discriminator respectively

Parameters:

state_dict (dict) – state_dict with keys “G” and “D”.

state_dict(*args, **kwargs)[source]#

Return both generator and discriminator’s state_dicts with keys “G” and “D”.

zero_grad(set_to_none=True)[source]#

zero_grad generator and discriminator optimizers, optionally only zero_grad one of them.

Parameters:

set_to_none (bool) – whether to set gradients to None, defaults to True

Examples using AdversarialOptimizer:#

Imaging inverse problems with adversarial networks

Imaging inverse problems with adversarial networks