import torch


def init_optimizerD(opt, D, train_last_layer_only=False):
    """Initialize optimizer for discriminator D
    """
    params_to_train = D.parameters()
    if train_last_layer_only and opt.DiscArch == 'concat_first':
        params_to_train = D.last_linear.parameters()
    optimizerD = torch.optim.Adam(params_to_train, lr=opt.lrD, betas=(opt.beta1, opt.beta2), weight_decay=opt.wdecay)
    return optimizerD