forked from w-transposed-x/hifi-gan-denoising
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.py
executable file
·32 lines (25 loc) · 1.14 KB
/
logs.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
import librosa
from torch.utils.tensorboard import SummaryWriter
from hparams import hparams as hp
class Logger(SummaryWriter):
def __init__(self, logdir):
super(Logger, self).__init__(logdir)
self.scalars = dict()
def log_training(self, step, scalars):
for plot, series in scalars.items():
self.add_scalars(plot, series, step)
def log_validation(self, model, step, scalars, audio_data=None):
for plot, series in scalars.items():
self.add_scalars(plot, series, step)
# Log and plot distribution of parameters
for tag, value in model.named_parameters():
tag = tag.replace('.', '/')
self.add_histogram(tag, value.data.cpu().numpy(), step)
# Log audio data
if audio_data is not None:
for name, sound_data in audio_data.items():
for i, sound in enumerate(sound_data):
self.add_audio(f'{i}_{name}',
librosa.util.normalize(sound.squeeze()),
global_step=step,
sample_rate=hp.dsp.sample_rate)