MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / init_func

Function init_func

pix2pix/models/networks.py:78–95  ·  view source on GitHub ↗
(m)

Source from the content-addressed store, hash-verified

76 work better for some applications. Feel free to try yourself.
77 """
78 def init_func(m): # define the initialization function
79 classname = m.__class__.__name__
80 if hasattr(m, 'weight') and (classname.find('Conv') != -1 or classname.find('Linear') != -1):
81 if init_type == 'normal':
82 init.normal_(m.weight.data, 0.0, init_gain)
83 elif init_type == 'xavier':
84 init.xavier_normal_(m.weight.data, gain=init_gain)
85 elif init_type == 'kaiming':
86 init.kaiming_normal_(m.weight.data, a=0, mode='fan_in')
87 elif init_type == 'orthogonal':
88 init.orthogonal_(m.weight.data, gain=init_gain)
89 else:
90 raise NotImplementedError('initialization method [%s] is not implemented' % init_type)
91 if hasattr(m, 'bias') and m.bias is not None:
92 init.constant_(m.bias.data, 0.0)
93 elif classname.find('BatchNorm2d') != -1: # BatchNorm Layer's weight is not a matrix; only normal distribution applies.
94 init.normal_(m.weight.data, 1.0, init_gain)
95 init.constant_(m.bias.data, 0.0)
96
97 print('initialize network with %s' % init_type)
98 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