Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weight bias init update #96

Merged
merged 28 commits into from
Dec 10, 2018
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
155ae9b
Update weight and bias for selu activation
joemehltretter Nov 13, 2018
8496ee9
Adjust weight initilization and bias for just selu
joemehltretter Nov 16, 2018
f439d19
Update _init_bias to check is not None
joemehltretter Nov 16, 2018
19963b1
Merge branch 'master' of https://github.com/Aifred-Health/Vulcan2 int…
joemehltretter Nov 20, 2018
3c066dc
Updated to have bias set through bias function
joemehltretter Nov 20, 2018
015b7d9
Changed initializer to weight_init
joemehltretter Nov 20, 2018
cf8e1a6
Remove assignment of self.activation in DenseUnit
joemehltretter Nov 20, 2018
f584df8
Add documentation for selu_weight_init_ and selu_bias_init. Remove un…
joemehltretter Nov 26, 2018
0c9c856
Removed used of tensor.data and adjusted initializer to weight_init i…
joemehltretter Nov 26, 2018
7895c8c
Changed initializer documents to weight_init in DenseUnit.
joemehltretter Nov 26, 2018
dc329e7
Added documentation to selu_bias_init
joemehltretter Nov 26, 2018
09537e4
Updated selu weight and bias init function descriptions
joemehltretter Nov 27, 2018
5d2d882
Added parameter types for selu_bias_init
joemehltretter Nov 27, 2018
c9b082e
Moved selu weight and bias functions to models utils.py
joemehltretter Nov 30, 2018
4f8b2dd
Update import of selu weight and bias from utls
joemehltretter Dec 3, 2018
9cb59de
Test for selu weight and bias for dense unit
joemehltretter Dec 3, 2018
97e3008
Add test for conv unit weight and bias initialization
joemehltretter Dec 4, 2018
08f162b
Update tests to confirm weight and bias are properly initialized for …
joemehltretter Dec 4, 2018
cc90351
Added testing to check selu weights and bias after training. Need to …
joemehltretter Dec 5, 2018
d4bc1fe
Update example script from 'initializer' to 'weight_init'
joemehltretter Dec 6, 2018
4a653f7
Improve pydocs
rfratila Dec 9, 2018
e40bc25
Update weight initialization for test. Use pytest approx for checking…
joemehltretter Dec 10, 2018
23766dc
Specifying the imports from layers more strictly
rfratila Dec 10, 2018
ddd6d1f
Automatically calculate fan_in for std calculation.
joemehltretter Dec 10, 2018
0d6b7dc
Update fan_in calculations to be able to handle various kernel sizes
joemehltretter Dec 10, 2018
59bfd65
PEP8 fixes
rfratila Dec 10, 2018
b46a6ee
Merge branch 'master' into weight_bias_init_update
rfratila Dec 10, 2018
4c74741
Clean up documentation
rfratila Dec 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update weight and bias for selu activation
joemehltretter committed Nov 13, 2018
commit 155ae9bd0dabbc588e6ccc8da0e01e372180987f
36 changes: 30 additions & 6 deletions vulcanai2/models/layers.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
import torch
import torch.nn as nn
import logging
import numpy as np
logger = logging.getLogger(__name__)


@@ -52,8 +53,24 @@ def _init_weights(self):
if self.initializer is None, then pytorch default weight
will be assigned to the kernel
"""
#import pdb; pdb.set_trace()
if self.initializer:
self.initializer(self._kernel.weight)
elif isinstance(self.activation, nn.SELU):
stdv = np.sqrt(1. / self.in_features)
weight = torch.empty(self.out_features, self.in_features)
weight = nn.init.normal_(weight, stdv)
self._kernel.weight = nn.Parameter(weight)
elif isinstance(self.activation, nn.ReLU):
weight = torch.empty(self.out_features, self.in_features)
weight = nn.init.kaiming_normal_(weight, mode='fan_in', nonlinearity=self.activation)
self._kernel.weight = nn.Parameter(weight)
else:
weight = torch.empty(self.out_features, self.in_features)
weight = nn.init.xavier_uniform_(weight)

self._kernel.weight = nn.Parameter(weight)
#import pdb; pdb.set_trace()

def _init_bias(self):
"""
@@ -64,7 +81,14 @@ def _init_bias(self):
"""
if self.bias_init:
nn.init.constant_(self._kernel.bias, self.bias_init)

elif isinstance(self.activation, nn.SELU):
bias = torch.empty(self.out_features)
bias = nn.init.normal_(bias, 0.0)
self._kernel.bias = nn.Parameter(bias)
else:
bias = torch.empty(self.out_features)
bias = nn.init.constant_(bias, 0.0)
self._kernel.bias = nn.Parameter(bias)

class FlattenUnit(BaseUnit):
"""
@@ -121,17 +145,16 @@ def __init__(self, in_features, out_features,
norm, dropout)
self.in_features = in_features
self.out_features = out_features

self.activation = activation
# Main layer
self._kernel = nn.Linear(
in_features=self.in_features,
out_features=self.out_features,
bias=True
)
self.add_module('_kernel', self._kernel)
self._init_weights()
self._init_bias()

#self._init_weights()
#self._init_bias()
# Norm
if self.norm is not None:
if self.norm == 'batch':
@@ -155,7 +178,8 @@ def __init__(self, in_features, out_features,
else:
self.add_module(
'_dropout', nn.Dropout(self.dropout))

self._init_weights()
self._init_bias()

# TODO: Automatically calculate padding to be the same as input shape.
class ConvUnit(BaseUnit):