-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize.py
58 lines (54 loc) · 2.37 KB
/
initialize.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
import torch.nn as nn
import numpy as np
def weights_init_kaimingUniform(module):
for m in module.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_uniform_(m.weight, mode='fan_in', nonlinearity='relu')
if m.bias is not None:
nn.init.constant_(m.bias, 0)
elif isinstance(m, nn.BatchNorm2d):
nn.init.uniform_(m.weight, a=0, b=1)
nn.init.constant_(m.bias, val=0.)
elif isinstance(m, nn.Linear):
nn.init.kaiming_uniform_(m.weight, mode='fan_in', nonlinearity='relu')
if m.bias is not None:
nn.init.constant_(m.bias, val=0.)
def weights_init_kaimingNormal(module):
for m in module.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight, mode='fan_in', nonlinearity='relu')
if m.bias is not None:
nn.init.constant_(m.bias, 0)
elif isinstance(m, nn.BatchNorm2d):
nn.init.normal_(m.weight, 0, 0.01)
nn.init.constant_(m.bias, val=0.)
elif isinstance(m, nn.Linear):
nn.init.kaiming_normal_(m.weight, mode='fan_in', nonlinearity='relu')
if m.bias is not None:
nn.init.constant_(m.bias, val=0.)
def weights_init_xavierUniform(module):
for m in module.modules():
if isinstance(m, nn.Conv2d):
nn.init.xavier_uniform_(m.weight, gain=np.sqrt(2))
if m.bias is not None:
nn.init.constant_(m.bias, 0)
elif isinstance(m, nn.BatchNorm2d):
nn.init.uniform_(m.weight, a=0, b=1)
nn.init.constant_(m.bias, val=0.)
elif isinstance(m, nn.Linear):
nn.init.xavier_uniform_(m.weight, gain=np.sqrt(2))
if m.bias is not None:
nn.init.constant_(m.bias, val=0.)
def weights_init_xavierNormal(module):
for m in module.modules():
if isinstance(m, nn.Conv2d):
nn.init.xavier_normal_(m.weight, gain=np.sqrt(2))
if m.bias is not None:
nn.init.constant_(m.bias, 0)
elif isinstance(m, nn.BatchNorm2d):
nn.init.normal_(m.weight, 0, 0.01)
nn.init.constant_(m.bias, val=0.)
elif isinstance(m, nn.Linear):
nn.init.xavier_normal_(m.weight, gain=np.sqrt(2))
if m.bias is not None:
nn.init.constant_(m.bias, val=0.)