pytorch-deepvo icon indicating copy to clipboard operation
pytorch-deepvo copied to clipboard

请问loss_x loss_y loss_z loss_tx loss_ty loss_tz图像怎么画出来的

Open 1212kyky opened this issue 3 years ago • 2 comments

我将main.py里的run_batch函数中代码注释部分去掉之后运行报错 ` if phase == 'Train' or phase == 'Valid': label = to_var(sample['label']) # [bs, 6] label = label.view(-1, 6) loss1 = loss_func(label_pre[:, :3], label[:, :3]) loss2 = loss_func(label_pre[:, 3:], label[:, 3:]) loss = loss1 + args.beta * loss2

    loss_x = loss_func(label_pre[:, 0], label[:, 0])
    loss_y = loss_func(label_pre[:, 1], label[:, 1])
    loss_z = loss_func(label_pre[:, 2], label[:, 2])
    loss_tx = loss_func(label_pre[:, 3], label[:, 3])
    loss_ty = loss_func(label_pre[:, 4], label[:, 4])
    loss_tz = loss_func(label_pre[:, 5], label[:, 5])

    if phase == 'Train':
        optimizer.zero_grad()  # 所有权重每次都清零
        loss.backward()  # 反向传播求梯度
        optimizer.step()  #更新,step()更新函数

    #return loss.data, loss1.data, loss2.data, label_pre.data
    return loss.data[0], loss1.data[0], loss2.data[0], label_pre.data, \
        loss_x.data[0], loss_y.data[0], loss_z.data[0], loss_tx.data[0], loss_ty.data[0], loss_tz.data[0]

` 报错信息: Traceback (most recent call last): File "main.py", line 447, in main() File "main.py", line 419, in main run_batch(sample=sample_t, model=model, loss_func=loss_func, optimizer=optimizer, phase='Train') ValueError: too many values to unpack (expected 4) 请问这是因为什么导致的呢

1212kyky avatar Apr 28 '22 07:04 1212kyky

从报错来看,问题很明显,run_batch 函数返回值的数量和调用 run_batch 函数时赋值的变量个数不匹配。至于 loss_x ... 的图像如何画,保存训练过程中的 loss 数据,后处理时画图即可。

linjianz avatar May 05 '22 01:05 linjianz

好的,谢谢您,已经解决啦,十分感谢您公开的代码,受益匪浅

1212kyky avatar May 05 '22 01:05 1212kyky