我正在使用加速度数据来预测某些活动.但我在损失计算上遇到了问题.我正在使用CrossEntropyLoss它.
如下所示使用数据我使用每行的前4个数据来预测索引,就像每行的最后一个一样.
1 84 84 81 4
81 85 85 80 1
81 82 84 80 1
1 85 84 2 0
81 85 82 80 1
81 82 84 80 1
81 25 84 80 5
Run Code Online (Sandbox Code Playgroud)
错误消息如下所示.
minoh@minoh-VirtualBox:~/cow$ python lec5.py
Traceback (most recent call last):
File "lec5.py", line 97, in <module>
train(epoch)
File "lec5.py", line 74, in train
loss = criterion(y_pred, labels)
File "/home/minoh/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
result = self.forward(*input, **kwargs)
File "/home/minoh/anaconda3/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 679, in …Run Code Online (Sandbox Code Playgroud) 我正在使用PyTorch,但出现错误!我的错误代码如下:
for train_data in trainloader:
example_count += 1
if example_count == 100:
break
optimer.zero_grad()
image, label = train_data
image = image.cuda()
label = label.cuda()
out = model(image)
_, out = torch.max(out, 1)
# print(out.cpu().data.numpy())
# print(label.cpu().data.numpy())
# out = torch.zeros(4, 10).scatter_(1, out.cpu(), 1).cuda()
# label= torch.zeros(4, 10).scatter_(1, label.cpu(), 1).cuda()
l = loss(out, label)
l.bakeward()
optimer.setp()
j += 1
count += label.size(0)
acc += (out == label).sum().item()
if j % 1000 == 0:
print(j + ' step:curent accurity is %f' % …Run Code Online (Sandbox Code Playgroud) python machine-learning image-processing computer-vision pytorch