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
相关产品推荐
相关产品推荐

