运行报错:IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>() in C++ to convert a 0-dim tensor to a number
遇到类似错误直接将代码中.data[0]改成.item()
例如将:
M = (d_loss_real + torch.abs(diff)).data[0]
改为:
M = (d_loss_real + torch.abs(diff)).data[0]
父主题:
FAQ