-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutils.py
30 lines (26 loc) · 858 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
import numpy as np
import torch
from numpy.random import *
from torch.autograd import Variable
from torch.nn.modules.batchnorm import BatchNorm2d, BatchNorm1d, BatchNorm3d
def textread(path):
# if not os.path.exists(path):
# print path, 'does not exist.'
# return False
f = open(path)
lines = f.readlines()
f.close()
for i in range(len(lines)):
lines[i] = lines[i].replace('\n', '')
return lines
def weights_init(m):
classname = m.__class__.__name__
if classname.find('Conv') != -1:
m.weight.data.normal_(0.0, 0.01)
m.bias.data.normal_(0.0, 0.01)
elif classname.find('BatchNorm') != -1:
m.weight.data.normal_(1.0, 0.01)
m.bias.data.fill_(0)
elif classname.find('Linear') != -1:
m.weight.data.normal_(0.0, 0.01)
m.bias.data.normal_(0.0, 0.01)