MCPcopy Create free account
hub / github.com/VCIP-RGBD/DFormer / _init_weights

Method _init_weights

models/net_utils.py:184–197  ·  view source on GitHub ↗
(self, m)

Source from the content-addressed store, hash-verified

182 self.apply(self._init_weights)
183
184 def _init_weights(self, m):
185 if isinstance(m, nn.Linear):
186 trunc_normal_(m.weight, std=0.02)
187 if isinstance(m, nn.Linear) and m.bias is not None:
188 nn.init.constant_(m.bias, 0)
189 elif isinstance(m, nn.LayerNorm):
190 nn.init.constant_(m.bias, 0)
191 nn.init.constant_(m.weight, 1.0)
192 elif isinstance(m, nn.Conv2d):
193 fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
194 fan_out //= m.groups
195 m.weight.data.normal_(0, math.sqrt(2.0 / fan_out))
196 if m.bias is not None:
197 m.bias.data.zero_()
198
199 def forward(self, x1, x2):
200 B, C, H, W = x1.shape

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected