-
Notifications
You must be signed in to change notification settings - Fork 1
/
eval.py
88 lines (73 loc) · 2.68 KB
/
eval.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# MIT License
#
# Copyright (c) 2021 Sangchun Ha
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
import torch
import numpy as np
import random
import hydra
from hydra.core.config_store import ConfigStore
from omegaconf import OmegaConf, DictConfig
from evaluator.evaluator import Evaluator
from model_builder import load_test_model
from data import (
MelSpectrogramConfig,
SpectrogramConfig,
MFCCConfig,
FilterBankConfig
)
from evaluator import EvaluateConfig
from data.data_loader import (
SpectrogramDataset,
AudioDataLoader,
)
from vocabulary import (
load_label,
load_dataset,
)
cs = ConfigStore.instance()
cs.store(group="audio", name="melspectrogram", node=MelSpectrogramConfig, package="audio")
cs.store(group="audio", name="filterbank", node=FilterBankConfig, package="audio")
cs.store(group="audio", name="mfcc", node=MFCCConfig, package="audio")
cs.store(group="audio", name="spectrogram", node=SpectrogramConfig, package="audio")
cs.store(group="eval", name="default", node=EvaluateConfig, package="eval")
@hydra.main(config_path='configs', config_name='eval')
def main(config: DictConfig) -> None:
print(OmegaConf.to_yaml(config))
torch.manual_seed(config.eval.seed)
torch.cuda.manual_seed_all(config.eval.seed)
np.random.seed(config.eval.seed)
random.seed(config.eval.seed)
use_cuda = config.eval.cuda and torch.cuda.is_available()
device = torch.device('cuda' if use_cuda else 'cpu')
char2id, id2char = load_label(config.eval.label_path, config.eval.blank_id)
audio_paths, transcripts, _, _ = load_dataset(config.eval.dataset_path, config.eval.mode)
test_dataset = SpectrogramDataset(
config.eval.audio_path,
audio_paths,
transcripts,
config.audio.sampling_rate,
config.audio.n_mel,
config.audio.frame_length,
config.audio.frame_stride,
config.audio.extension,
config.train.sos_id,
config.train.eos_id,
)
test_loader = AudioDataLoader(
test_dataset,
batch_size=config.eval.batch_size,
num_workers=config.eval.num_workers,
)
model = load_test_model(config, device)
print('Start Test !!!')
evaluator = Evaluator(config, device, test_loader, id2char)
evaluator.evaluate(model)
if __name__ == "__main__":
main()