Daporte commited on
Commit
b17425b
·
verified ·
1 Parent(s): c199313

Upload utils.py

Browse files

Add more files from https://github.com/facebookresearch/speech-resynthesis

Files changed (1) hide show
  1. utils.py +36 -0
utils.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # # Copyright (c) Facebook, Inc. and its affiliates.
2
+ # # All rights reserved.
3
+ # #
4
+ # # This source code is licensed under the license found in the
5
+ # # LICENSE file in the root directory of this source tree.
6
+ #
7
+ # # Adapted from https://github.com/jik876/hifi-gan
8
+ #
9
+ import os
10
+ import torch
11
+
12
+
13
+ def init_weights(m, mean=0.0, std=0.01):
14
+ classname = m.__class__.__name__
15
+ if classname.find("Conv") != -1:
16
+ m.weight.data.normal_(mean, std)
17
+
18
+
19
+ def get_padding(kernel_size, dilation=1):
20
+ return int((kernel_size*dilation - dilation)/2)
21
+
22
+
23
+ def load_checkpoint(filepath, device):
24
+ assert os.path.isfile(filepath)
25
+ print("Loading '{}'".format(filepath))
26
+ checkpoint_dict = torch.load(filepath, map_location=device)
27
+ print("Complete.")
28
+ return checkpoint_dict
29
+
30
+
31
+ class AttrDict(dict):
32
+ def __init__(self, *args, **kwargs):
33
+ super(AttrDict, self).__init__(*args, **kwargs)
34
+ self.__dict__ = self
35
+
36
+