Thanks for reply.
I write this code ,is it correct?
I have another question, if i use some losses in my code, is it necessary to use loss.backward() for each of losses?
import torch
N, C = 8, 21
loss = torch.nn.MSELoss()
data = torch.randn(8,21 ,64, 64, 64)
target = torch.empty(8, 64, 64,64, dtype=torch.long).random_(0, 21)

_, preds_argmax = torch.max(data.data, 1)
labels3 = target.eq(3).float()
preds3 = preds_argmax.eq(3).float()
loss1 = loss(preds3, labels3)
# loss for class 3
print(loss1)