-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy patheval-score.py
executable file
·66 lines (52 loc) · 1.92 KB
/
eval-score.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
#!/usr/bin/env python3
import os
import argparse
import torch
import librosa
import time
import numpy as np
from tqdm import tqdm
import utils
from models import SynthesizerTrn
from mel_processing import mel_spectrogram_torch
import logging
logging.getLogger('numba').setLevel(logging.WARNING)
import torch.autograd.profiler as profiler
## check device
if torch.cuda.is_available() is True:
device = "cuda:0"
else:
device = "cpu"
from resemblyzer import preprocess_wav, VoiceEncoder
encoder = VoiceEncoder()
def compute_embedding(fpath):
wav = preprocess_wav(fpath)
embed = encoder.embed_utterance(wav)
return embed
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--hpfile", type=str, default="logs/quickvc/config.json", help="path to json config file")
parser.add_argument("--ptfile", type=str, default="logs/quickvc/quickvc.pth", help="path to pth file")
parser.add_argument("--txtpath", type=str, default="dataset/eval.txt", help="path to txt file")
parser.add_argument("--outdir", type=str, default="eval", help="path to output dir")
parser.add_argument("--use_timestamp", default=False, action="store_true")
args = parser.parse_args()
allfiles, titles, srcs, tgts = [], [], [], []
allfiles = open(args.txtpath, "r").readlines()
for i in range(len(allfiles) // 2):
tgt = allfiles[i].strip()
src = allfiles[-i].strip()
title = src.split("/")[-1][:-4] + "_" + tgt.split("/")[-1][:-4]
titles.append(title)
srcs.append(src)
tgts.append(tgt)
allscore = 0
scores = []
for tgt, res in zip(tgts, titles):
tgt_emb = compute_embedding(tgt)
res_emb = compute_embedding(f"{args.outdir}/{res}.wav")
score = np.dot(tgt_emb, res_emb)
scores.append(score)
print (f"{tgt} {res} {score}")
ns = np.array(scores)
print (f"Average: {np.mean(ns)} Min: {np.min(ns)}")