I’m running Conv1d on a time series with 23 annual (2001 - 2023) observations. Target is 6 defined classes. Softmax is the last step in the model. All trials only 0 or 1, no matter the activation function. I’ve tried ReLU, ELU(1), LeakyReLU, PReLU, and Tanh
Model
class CNN1(nn.Module):
def init(self):
super().init()
self.layer1=nn.Sequential(
nn.Conv1d(1,10,3,1,1,bias=False),
nn.PReLU(),
nn.BatchNorm1d(10))
self.layer2=nn.Sequential(
nn.Conv1d(10,12,5,1,2,bias=False),
nn.PReLU(),
nn.BatchNorm1d(12))
self.layer3=nn.Sequential(
nn.Conv1d(12,14,7,1,3,bias=False),
nn.PReLU(),
nn.BatchNorm1d(14))
self.layer4=nn.Sequential(
nn.Conv1d(14,16,9,1,4,bias=False),
nn.PReLU(),
nn.BatchNorm1d(16))
self.layer5=nn.Sequential(
nn.Conv1d(16,18,11,1,5,bias=False),
nn.PReLU(),
nn.BatchNorm1d(18))
self.layer6=nn.Sequential(
nn.Conv1d(18,20,13,1,6,bias=False),
nn.PReLU(),
nn.BatchNorm1d(20),
nn.Flatten())
self.layer7=nn.Sequential(
nn.Linear(460,50,True),
# nn.ReLU(),
nn.Linear(50,6,True),
nn.Softmax(dim=1))
def forward(self, x):
x=self.layer1(x)
x=self.layer2(x)
x=self.layer3(x)
x=self.layer4(x)
x=self.layer5(x)
x=self.layer6(x)
x=self.layer7(x)
return x
m=CNN1().to(‘cuda:0’)
def weight_init(m):
if isinstance(nn.Conv1d,CNN1) or isinstance(nn.Linear,CNN1):
torch.nn.init.xavier_normal_(m.weight)
weight_init(m)
#print model details
def param_count(m):
for p in m.parameters():
count = sum(p.numel() for p in m.parameters() if p.requires_grad)
return count
print(summary(m,(1,23)))
model parameters
epochs = 10
lossL1 = nn.CrossEntropyLoss()
optimizer=torch.optim.AdamW(m.parameters(), lr=0.001, weight_decay=0.0002)
#implementation
print(time.strftime(‘%C++’,time.localtime()))
m.train()
for epoch in range(epochs):
running_loss=0
preds=
for i, (X, y) in enumerate(train_loader):
yhat=m(X)
preds.append([yhat])
loss = lossL1(yhat,y)
running_loss += loss.item()
epoch_loss = running_loss / len(train_loader)
optimizer.zero_grad()
loss.backward()
optimizer.step()
print(f’{epoch}, {epoch_loss: .4f}')
print(time.strftime(‘%C++’,time.localtime()))