-
Notifications
You must be signed in to change notification settings - Fork 0
/
Evaluate.py
53 lines (39 loc) · 1.53 KB
/
Evaluate.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
from Frechet_Inception_Distance import Compute_FID
import torch
import argparse
# Direct use of FAD from https://github.com/gudgud96/frechet-audio-distance
# NOTE: require https://github.com/qiuqiangkong/torchlibrosa to work with PANN model
from frechet_audio_distance import FrechetAudioDistance
# Set the path for the real and fake samples for FID and FAD scoring
parser = argparse.ArgumentParser()
parser.add_argument('--FID_real', default=f"real/") # Mel-spectrogram image samples
parser.add_argument('--FID_fake', default=f"fake/")
parser.add_argument('--FAD_real', default=f"real/") # Keep the audio samples in a separate directory
parser.add_argument('--FAD_fake', default=f"fake/")
a = parser.parse_args()
device = torch.device("cuda:0" if (torch.cuda.is_available()) else "cpu")
def evaluate():
# --------------- Frechet Inception Distance ---------------------- #
# Real
path_real = a.FID_real
# Fake
path_fake = a.FID_fake
paths = [path_real, path_fake]
fid = Compute_FID(paths=paths, dev=device)
print(f"FID: {fid}")
# -------------- Frechet Audio Distance ------------------------- #
# Real
path_real = a.FAD_real
# Fake
path_fake = a.FAD_fake
# There is a problem when using "pann" model... Stick to "vggish" for now
frechet = FrechetAudioDistance(
model_name="vggish",
use_pca=False,
use_activation=False,
verbose=False
)
fad = frechet.score(path_real, path_fake)
print(f"FAD: {fad}")
if __name__ == '__main__':
evaluate()