(self)
| 363 | cur += num_layer |
| 364 | |
| 365 | def init_weights(self): |
| 366 | if self.pretrained is None: |
| 367 | for m in self.modules(): |
| 368 | if isinstance(m, nn.Linear): |
| 369 | trunc_normal_init(m.weight, std=.02) |
| 370 | if m.bias is not None: |
| 371 | constant_init(m.bias, 0) |
| 372 | elif isinstance(m, nn.LayerNorm): |
| 373 | constant_init(m.bias, 0) |
| 374 | constant_init(m.weight, 1.0) |
| 375 | elif isinstance(m, nn.Conv2d): |
| 376 | fan_out = m.kernel_size[0] * m.kernel_size[ |
| 377 | 1] * m.out_channels |
| 378 | fan_out //= m.groups |
| 379 | normal_init(m.weight, 0, math.sqrt(2.0 / fan_out)) |
| 380 | if m.bias is not None: |
| 381 | constant_init(m.bias, 0) |
| 382 | elif isinstance(self.pretrained, str): |
| 383 | logger = get_root_logger() |
| 384 | checkpoint = _load_checkpoint( |
| 385 | self.pretrained, logger=logger, map_location='cpu') |
| 386 | if 'state_dict' in checkpoint: |
| 387 | state_dict = checkpoint['state_dict'] |
| 388 | else: |
| 389 | state_dict = checkpoint |
| 390 | |
| 391 | self.load_state_dict(state_dict, False) |
| 392 | |
| 393 | def forward(self, x): |
| 394 | outs = [] |
nothing calls this directly
no outgoing calls
no test coverage detected