(m)
| 247 | init_param = np.sqrt(2) |
| 248 | init_type = 'default' |
| 249 | def init_func(m): |
| 250 | classname = m.__class__.__name__ |
| 251 | if classname.startswith('Conv') or classname == 'Linear': |
| 252 | if getattr(m, 'bias', None) is not None: |
| 253 | init.constant_(m.bias, 0.0) |
| 254 | if getattr(m, 'weight', None) is not None: |
| 255 | if init_type == 'normal': |
| 256 | init.normal_(m.weight, 0.0, init_param) |
| 257 | elif init_type == 'xavier': |
| 258 | init.xavier_normal_(m.weight, gain=init_param) |
| 259 | elif init_type == 'xavier_unif': |
| 260 | init.xavier_uniform_(m.weight, gain=init_param) |
| 261 | elif init_type == 'kaiming': |
| 262 | init.kaiming_normal_(m.weight, a=init_param, mode='fan_in') |
| 263 | elif init_type == 'kaiming_out': |
| 264 | init.kaiming_normal_(m.weight, a=init_param, mode='fan_out') |
| 265 | elif init_type == 'orthogonal': |
| 266 | init.orthogonal_(m.weight, gain=init_param) |
| 267 | elif init_type == 'zero': |
| 268 | init.zeros_(m.weight) |
| 269 | elif init_type == 'one': |
| 270 | init.ones_(m.weight) |
| 271 | elif init_type == 'constant': |
| 272 | init.constant_(m.weight, init_param) |
| 273 | elif init_type == 'default': |
| 274 | if hasattr(m, 'reset_parameters'): |
| 275 | m.reset_parameters() |
| 276 | else: |
| 277 | raise NotImplementedError('initialization method [%s] is not implemented' % init_type) |
| 278 | elif 'Norm' in classname: |
| 279 | if getattr(m, 'weight', None) is not None: |
| 280 | m.weight.data.fill_(1) |
| 281 | if getattr(m, 'bias', None) is not None: |
| 282 | m.bias.data.zero_() |
| 283 | |
| 284 | def save_code(path): |
| 285 | os.makedirs(path + '/code', exist_ok=True) |
nothing calls this directly
no outgoing calls
no test coverage detected