Exemplo n.º 1
0
    gaussian_record = open('test/gaussian_record.txt', 'w')
    for word_list in generate_words:
        for i, word in enumerate(word_list):
            if (i + 1) % 4 != 0:
                word += ', '
            else:
                word += '\n'
            print(word, file=gaussian_record, end='')
    print('Gaussian score: ', gaussian_score, file=gaussian_record)
    gaussian_record.close()


test_dataset = WordDataset('test')
max_length = test_dataset.max_length
dataloader = DataLoader(test_dataset, batch_size=1, shuffle=False)
tense_list = dataloader.dataset.tense2idx.values()
transformer = WordTransoformer()

# Epoch 57 is the best
loadmodel = 'model/cycle_500/checkpoint57.pkl'
model = CVAE(max_length)
model = model.cuda()
state_dict = torch.load(loadmodel)
model.load_state_dict(state_dict)

average_bleu_score, predict_list, gaussian_score, generate_words = evaluate(
    model, dataloader, tense_list)
record_score(average_bleu_score, gaussian_score, predict_list, generate_words,
             dataloader, transformer)
Exemplo n.º 2
0
if __name__ == '__main__':
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    # Dataset
    datasets, dataloaders, dataset_sizes = get_data(num_quadrant_inputs=1,
                                                    batch_size=128)
    baseline_net = BaselineNet(500, 500)
    baseline_net.load_state_dict(
        torch.load('/Users/carlossouza/Downloads/baseline_net_q1.pth',
                   map_location='cpu'))
    baseline_net.eval()

    cvae_net = CVAE(200, 500, 500, baseline_net)
    cvae_net.load_state_dict(
        torch.load('/Users/carlossouza/Downloads/cvae_net_q1.pth',
                   map_location='cpu'))
    cvae_net.eval()

    visualize(device=device,
              num_quadrant_inputs=1,
              pre_trained_baseline=baseline_net,
              pre_trained_cvae=cvae_net,
              num_images=10,
              num_samples=10)

    # df = generate_table(
    #     device=device,
    #     num_quadrant_inputs=1,
    #     pre_trained_baseline=baseline_net,
    #     pre_trained_cvae=cvae_net,