INNER CODE UNIT · Python
init_weights
RichardS0268/CNN-for-Trading · model.py:10
def init_weights(self, m):
if isinstance(m, nn.Linear) or isinstance(m, nn.Conv2d):
torch.nn.init.xavier_uniform(m.weight)
m.bias.data.fill_(0.01)
def __init__(self):
super(CNN5d, self).__init__()
self.conv1 = nn.Sequential(OrderedDict([
('Conv', nn.Conv2d(1, 64, (5, 3), padding=(2, 1), stride=(1, 1), dilation=(1, 1))), # output size: [N, 64, 32, 15]
('BN', nn.BatchNorm2d(64, affine=True)),
('ReLU', nn.ReLU()),
('Max-Pool', nn.MaxPool2d((2,1))) # output size: [N, 64, 16, 15]
]))
self.conv1 = self.conv1.apply(self.init_weights)
self.conv2 = nn.Sequential(OrderedDict([
('Conv', nn.Conv2d(64, 128, (5, 3), padding=(2, 1), stride=(1, 1), dilation=(1, 1))), # output size: [N, 128, 16, 15]
('BN', nn.BatchNorm2d(128, affine=True)),