I know this is probably discussed somewhere but I couldn't find it. I always have a missmatch of shapes when using pytorch between target and label. For a batch size of 64 I would get [64, 1]
for the target and [64]
for the label. I always fix this using label.view(-1, 1)
inside the loss function.
I was wondering if there is a "best way" to fix this. Because I could also just use target.view(-1)
to get the same result. Or I could even change the output in the network to output.view(-1)
. Maybe it's also better to use something like .reshape()
?
The missmatch probably comes from inside the dataloader, which gets y_train, y_test as a Series not as a dataframe (since y = X.pop(target_name)
). So doing y_train.values
will give a 1D array. Should I fix it here?
I am happy for any kind of feedback :) If needed, I could also provide a small example of the process, but I think the question should also work without since it is a general problem.