Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1212kyky opened this issue Apr 28, 2022 · 2 comments

Comments

@1212kyky
Copy link

我将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)
请问这是因为什么导致的呢

@linjianz
Copy link
Owner

linjianz commented May 5, 2022

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

@1212kyky
Copy link
Author

1212kyky commented May 5, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants