forked from lv-jiajun/S2FVD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil1.py
More file actions
35 lines (28 loc) · 1 KB
/
Copy pathutil1.py
File metadata and controls
35 lines (28 loc) · 1 KB
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.utils.data as Data
import torch.nn as nn
# 权重初始化,默认xavier
def init_network(model, method='xavier', exclude='embedding', seed=123):
for name, w in model.named_parameters():
if exclude not in name:
if 'weight' in name:
if method == 'xavier':
nn.init.xavier_normal_(w)
elif method == 'kaiming':
nn.init.kaiming_normal_(w)
else:
nn.init.normal_(w)
elif 'bias' in name:
nn.init.constant_(w, 0)
else:
pass
class NodesDataset(Data.Dataset):
"""
Stores all nodes (represented as instruction list) within a single CFG
"""
def __init__(self, node_list):
super(NodesDataset, self).__init__()
self.node_list = node_list
def __len__(self):
return len(self.node_list)
def __getitem__(self, index):
return self.node_list[index]