(m)
| 39 | |
| 40 | def weights_init(init_type='gaussian'): |
| 41 | def init_fun(m): |
| 42 | classname = m.__class__.__name__ |
| 43 | if (classname.find('Conv') == 0 or classname.find( |
| 44 | 'Linear') == 0) and hasattr(m, 'weight'): |
| 45 | if init_type == 'gaussian': |
| 46 | nn.init.normal_(m.weight, 0.0, 0.02) |
| 47 | elif init_type == 'xavier': |
| 48 | nn.init.xavier_normal_(m.weight, gain=math.sqrt(2)) |
| 49 | elif init_type == 'kaiming': |
| 50 | nn.init.kaiming_normal_(m.weight, a=0, mode='fan_in') |
| 51 | elif init_type == 'orthogonal': |
| 52 | nn.init.orthogonal_(m.weight, gain=math.sqrt(2)) |
| 53 | elif init_type == 'default': |
| 54 | pass |
| 55 | else: |
| 56 | assert 0, "Unsupported initialization: {}".format(init_type) |
| 57 | if hasattr(m, 'bias') and m.bias is not None: |
| 58 | nn.init.constant_(m.bias, 0.0) |
| 59 | |
| 60 | return init_fun |
| 61 |
nothing calls this directly
no outgoing calls
no test coverage detected