Пример #1
0
def verka(encoder: nn.Module):
    res = []
    for i, (image, lm) in enumerate(LazyLoader.celeba_test(64)):
        content = encoder(image.cuda())
        mes = UniformMeasure2D01(lm.cuda())
        pred_measures: UniformMeasure2D01 = UniformMeasure2DFactory.from_heatmap(content)
        res.append(Samples_Loss(p=1)(mes, pred_measures).item() * image.shape[0])
    return np.mean(res)/len(LazyLoader.celeba_test(1).dataset)
        ll = (bc_net(ws).reshape(-1, padding, 2) - bs).pow(2).sum() / 32
        print(ll.item())
        lll = ll.item()
        ll.backward()
        bc_net_opt.step()

    # replay_buf = replay_buf[replay_buf.__len__() - 32:]

    barycenter.coord = bc_net(weights[None, :]).reshape(1, padding, 2).detach()
    return barycenter, lll


# mafl_dataloader = LazyLoader.w300().loader_train_inf
# mes = UniformMeasure2D01(next(mafl_dataloader)['meta']['keypts_normalized'].type(torch.float32)).cuda()
mes = UniformMeasure2D01(next(iter(
    LazyLoader.celeba_test(batch_size)))[1]).cuda()

for j in range(10000):
    weights = Dirichlet(torch.ones(batch_size) / 10).sample().cuda()
    barycenter, lll = compute_wbc(mes, weights, min(200, j + 10))

    if j % 50 == 0:
        print(j)
        sced.step(lll)

    if j % 50 == 0:
        plt.imshow(barycenter.toImage(200)[0][0].detach().cpu().numpy())
        plt.show()

    starting_model_number = 0
    if j % 1000 == 0 and j > 0: