Exemplo n.º 1
0
def define_C(gpu_ids=[]):
    use_gpu = len(gpu_ids) > 0

    if use_gpu:
        assert (torch.cuda.is_available())
    netC = Classifier()
    if use_gpu:
        netC.cuda(device=gpu_ids[0])
    #netC.apply(weights_init)
    return netC
Exemplo n.º 2
0
def define_C(gpu_ids=[]):
    """
    gender preserving classifier
    :param gpu_ids:
    :return:
    """
    use_gpu = len(gpu_ids) > 0

    if use_gpu:
        assert (torch.cuda.is_available())
    netC = Classifier()
    if use_gpu:
        netC.cuda(device=gpu_ids[0])
    # netC.apply(weights_init)
    return netC
Exemplo n.º 3
0
def get_modules(opt):
    modules = {}
    disc = Discriminator()
    gen = Generator()
    clf = Classifier()
    if opt.cuda:
        disc = disc.cuda()
        gen = gen.cuda()
        clf = clf.cuda()

    modules['Discriminator'] = disc
    modules['Generator'] = gen
    modules['Classifier'] = clf
    return modules
Exemplo n.º 4
0
data_itr_tgt = get_data_iter("USPS", train=True)

pos_labels = Variable(torch.Tensor([1]))
neg_lables = Variable(torch.Tensor([-1]))
g_step = 0

g_loss_durations = []
d_loss_durations = []
c_loss_durations = []

# take variable into cuda
if use_cuda:
    generator.cuda()
    generator_larger.cuda()
    critic.cuda()
    classifier.cuda()
    pos_labels = pos_labels.cuda()
    neg_lables = neg_lables.cuda()

# for 循环
for epoch in range(params.num_epochs):
    # break
    # 训练 鉴别器
    # 开启求 鉴别器的梯度
    for p in critic.parameters():
        p.requires_grad = True
    # 设置 鉴别器的训练步数
    if g_step < 25 or g_step % 500 == 0:
        # this helps to start with the critic at optimum
        # even in the first iterations.
        critic_steps = 100