forked from davidboudin/AutoVCMaison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualizer.py
69 lines (51 loc) · 2.18 KB
/
visualizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import argparse
from model_vc import Generator
import matplotlib.pyplot as plt
import torch
from torch_utils import device
from data_loader_circular import get_loader
def show_melsp(tensor, title):
fig = plt.figure(title)
plt.imshow(tensor.detach().cpu().reshape((128,80)).numpy().T, cmap='viridis')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
# Model configuration.
parser.add_argument('--model', type=str)
parser.add_argument('--dataset', type=str, default='voxceleb')
parser.add_argument('--random', type=int, default=1)
config = parser.parse_args()
checkpoint = torch.load(config.model, map_location=device)
neck_dim = checkpoint['G_state_dict']['encoder.lstm.weight_hh_l0'].shape[1]
G = Generator(neck_dim, 256, 512, 16)
G.load_state_dict(checkpoint['G_state_dict'])
G.to(device)
loss = checkpoint["G_loss"]
dataloader = get_loader(config.dataset + '/spmel', 1, 128)
data_iter = iter(dataloader)
x_real, emb_org, emb_target = next(data_iter)
x_real = x_real.to(device)
emb_org = emb_org.to(device)
emb_target = emb_target.to(device)
# Circular mapping loss
x_target_pred, x_target_pred_psnt, code_org = G(x_real, emb_org, emb_target)
x_org_reconst, x_org_reconst_psnt, code_target_pred = G(x_target_pred.reshape(x_real.shape), emb_target, emb_org)
x_self_recon, x_self_recon_psnt, code_org = (x_real, emb_org, emb_org)
plt.semilogy(loss)
plt.xlabel('Iterations')
plt.ylabel('Loss')
plt.show()
show_melsp(x_real, 'Real utterance (A)')
show_melsp(x_target_pred, 'Converted utterance (B)')
plt.show()
show_melsp(x_real, 'Real utterance (A)')
show_melsp(x_target_pred, 'Self-converted utterance (A)')
plt.show()
show_melsp(x_target_pred, 'Converted utterance (B)')
show_melsp(x_target_pred_psnt, 'Converted utterance after PostNet (B)')
plt.show()
show_melsp(x_org_reconst, 'Reconstructed utterance (A)')
show_melsp(x_org_reconst_psnt, 'Reconstructed utterance after PostNet (A)')
plt.show()
show_melsp(x_real, 'Real utterance (A)')
show_melsp(x_org_reconst_psnt, 'Reconstructed utterance after PostNet (A)')
plt.show()