I have a dataset in the size of [88,498,20] which represent 88 samples with the length of 498, each Time-steps will be represent by 20 classes.
My output is [88,498,3] so it’s the same as input only different is now I only have 3 classes to predict.
So this is my first time with Pytorch. With Keras, I just simply create Dense layers , using Categorical_CrossEntropy loss function.
But for Pytorch I tried to create like this :
class MLP(torch.nn.Module):
def init(self):
super(MLP, self).init()
self.dense1 = torch.nn.Linear(20,128)
self.relu = torch.nn.ReLU()
self.dropout = nn.Dropout(0.5)
self.dense2 = torch.nn.Linear(128, 3)
self.softmax = torch.nn.Softmax()def forward(self, x): x = self.dense1(x) x = self.relu(x) x = self.dense2(x) x = self.dropout(x) x = self.softmax(x) return x
and the training go like this:
model = MLP()
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(model.parameters(), lr=0.001, momentum=0.9)
train_losses =
val_losses =
for epoch in range(100):
running_loss = 0.0
optimizer.zero_grad()
outputs = model(x_train)
loss = criterion(outputs, y_train)
loss.backward()
optimizer.step()
But I got this error with the Loss function :
ValueError: Expected target size (88, 3), got torch.Size([88, 498, 3])
So I don’t know what should I configure with the network and how to determine the size of each Linear layers.