MCPcopy Create free account
hub / github.com/chenhaoxing/HDNet / init_func

Function init_func

models/networks.py:112–129  ·  view source on GitHub ↗
(m)

Source from the content-addressed store, hash-verified

110 work better for some applications. Feel free to try yourself.
111 """
112 def init_func(m): # define the initialization function
113 classname = m.__class__.__name__
114 if hasattr(m, 'weight') and (classname.find('Conv') != -1 or classname.find('Linear') != -1):
115 if init_type == 'normal':
116 init.normal_(m.weight.data, 0.0, init_gain)
117 elif init_type == 'xavier':
118 init.xavier_normal_(m.weight.data, gain=init_gain)
119 elif init_type == 'kaiming':
120 init.kaiming_normal_(m.weight.data, a=0, mode='fan_in')
121 elif init_type == 'orthogonal':
122 init.orthogonal_(m.weight.data, gain=init_gain)
123 else:
124 raise NotImplementedError('initialization method [%s] is not implemented' % init_type)
125 if hasattr(m, 'bias') and m.bias is not None:
126 init.constant_(m.bias.data, 0.0)
127 elif classname.find('BatchNorm2d') != -1: # BatchNorm Layer's weight is not a matrix; only normal distribution applies.
128 init.normal_(m.weight.data, 1.0, init_gain)
129 init.constant_(m.bias.data, 0.0)
130
131 print('initialize network with %s' % init_type)
132 net.apply(init_func) # apply the initialization function <init_func>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected