online-label-smoothing-pt icon indicating copy to clipboard operation
online-label-smoothing-pt copied to clipboard

代码报错

Open luckyonetwo opened this issue 2 years ago • 1 comments

你好,非常感谢你提供的代码,请问一下,报错出现这个问题怎么解决呢:RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu

luckyonetwo avatar Sep 22 '22 02:09 luckyonetwo

Hi @luckyonetwo! If you are training with gpu, then you will need to move the loss to the gpu, so it'd be something like:

from ols import OnlineLabelSmoothing
import torch

k = 4  # Number of classes
b = 32  # Batch size
criterion = OnlineLabelSmoothing(alpha=0.5, n_classes=k, smoothing=0.1).cuda()

Let me know if this didn't solve the issue and need any help

ankandrew avatar Sep 27 '22 06:09 ankandrew