运行从githb上下载下来的人脸表情识别项目时,报出如下错误
Traceback (most recent call last):
File "mainpro_CK+.py", line 172, in
train(epoch)
File "mainpro_CK+.py", line 117, in train
train_loss += loss.data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
把 loss.data[0] 改成loss.item() 即可