forked from jjery2243542/adaptive_voice_conversion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
35 lines (28 loc) · 971 Bytes
/
utils.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
import torch
import numpy as np
from tensorboardX import SummaryWriter
import editdistance
import torch.nn as nn
import torch.nn.init as init
def cc(net):
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
return net.to(device)
class Logger(object):
def __init__(self, logdir='./log'):
self.writer = SummaryWriter(logdir)
def scalar_summary(self, tag, value, step):
self.writer.add_scalar(tag, value, step)
def scalars_summary(self, tag, dictionary, step):
self.writer.add_scalars(tag, dictionary, step)
def text_summary(self, tag, value, step):
self.writer.add_text(tag, value, step)
def audio_summary(self, tag, value, step, sr):
writer.add_audio(tag, value, step, sample_rate=sr)
def infinite_iter(iterable):
it = iter(iterable)
while True:
try:
ret = next(it)
yield ret
except StopIteration:
it = iter(iterable)