You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TensorBoard+Caffe2报错:找不到Blob 0.7158585786819458求助

TensorBoard add_scalar 报错:Can't find blob: [数值] 解决方法

问题根源

你遇到的错误是因为给tb_writer.add_scalar()的第二个参数传了字符串类型的值,而该方法要求传入的是数值类型(int/float)。TensorBoard把你传入的字符串当成了Caffe2工作区里的blob名称去查找,自然找不到对应内容,所以抛出Can't find blob错误。

修复步骤

直接去掉precision和recall取值外的str()包裹即可:

修改后的代码段:

if (tb_writer != None):
    for key, value in qps.items():
        tb_writer.add_scalar("QPv2_" + mode + "_Threshold_" + str(key), value, global_step)
    # 取消注释后的修正代码
    for annotation_idx in range(1, args.num_classes-1):
        annotation_class = annotation_classes[annotation_idx]
        for threshold_idx in range(len(annotation_thresholds)):
            threshold = annotation_thresholds[threshold_idx]
            # 移除 str() 包裹,直接传入数值
            tb_writer.add_scalar(annotation_class + "_Threshold_" + str(threshold) + "_Precision", precision[threshold_idx][annotation_idx].item(), global_step)
            tb_writer.add_scalar(annotation_class + "_Threshold_" + str(threshold) + "_Recall", recall[threshold_idx][annotation_idx].item(), global_step)

额外检查项

  • 确认precision[threshold_idx][annotation_idx]是PyTorch张量,.item()可以正确取出单个数值;如果是numpy数组,直接用precision[threshold_idx][annotation_idx]取值即可,不用.item()。
  • 验证annotation_idx和threshold_idx的循环范围是否正确,避免数组越界导致取到无效值。

内容的提问来源于stack exchange,提问作者wheeeee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 19:06:28