forked from razor1179/pytorch-kaldi-CGS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHCGS.py
executable file
·72 lines (60 loc) · 2.32 KB
/
HCGS.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
import math
import torch
import numpy as np
from torch.nn.parameter import Parameter
from torch.nn import functional as F
from torch.nn.modules.module import Module
import hcgs
import guided_hcgs
class HCGS(Module):
r"""Creates HCGS layer
Args:
in_features: size of each input sample
out_features: size of each output sample
Attributes:
mask: the non-learnable weights of the module of shape
`(out_features x in_features)`
"""
def __init__(self, in_features, out_features, block_sizes, drop_ratios, des='xyz'):
super(HCGS, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.mask = Parameter(hcgs.conn_mat(out_features, in_features, block_sizes[:], drop_ratios[:], des)) # torch.Tensor(, ))
# self.reset_parameters()
# def reset_parameters(self):
# stdv = 1. / math.sqrt(self.mask.size(1))
# self.mask.data.uniform_(-stdv, stdv)
#
# def forward(self, input):
# return F.linear(input, self.weight, self.bias)
#
# def extra_repr(self):
# return 'in_features={}, out_features={}, bias={}'.format(
# self.in_features, self.out_features, self.bias is not None
# )
class guidedHCGS(Module):
r"""Creates HCGS layer
Args:
in_features: size of each input sample
out_features: size of each output sample
Attributes:
mask: the non-learnable weights of the module of shape
`(out_features x in_features)`
"""
def __init__(self, in_features, out_features, block_sizes, drop_ratios, w_mat, des='xyz'):
super(guidedHCGS, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.mask = Parameter(guided_hcgs.conn_mat(out_features, in_features, block_sizes[:], drop_ratios[:], w_mat, des)) # torch.Tensor(, ))
# self.reset_parameters()
# def reset_parameters(self):
# stdv = 1. / math.sqrt(self.mask.size(1))
# self.mask.data.uniform_(-stdv, stdv)
#
# def forward(self, input):
# return F.linear(input, self.weight, self.bias)
#
# def extra_repr(self):
# return 'in_features={}, out_features={}, bias={}'.format(
# self.in_features, self.out_features, self.bias is not None
# )