loss(y_hat, y_true)使用batch_size来进行维度匹配
criterion = nn.CrossEntropyLoss().to(self.device)
loss = criterion(out.view(self.batch_size, self.n_classes), Y.view(
self.batch_size).long())
out的维度view为[batch_size, self.n_class]
Y的维度先view为[batch_size],然后通过.long()变为长tensor:
[batch_size, self.n_class]
从而匹配了out的维度
Y为label的那个元素为1,其余为0