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

TensorBoard可查看summary数据但EventAccumulator无法提取标量导出CSV

解决方法

你输出的标签结果里scalars字段为空,所有的精度、loss指标都是以tensor格式存储的,所以需要从tensors类别下提取对应标签的数值。

具体实现代码

import pandas as pd
import tensorflow as tf
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator

# 加载tfevent文件夹
event_acc = EventAccumulator(r'path2tfeventfolder')
event_acc.Reload()

# 定义需要提取的类别AP标签前缀
ap_tag_prefix = 'PascalBoxes_PerformanceByCategory/AP@0.5IOU/'
ap_results = []

# 遍历所有tensor标签,匹配类别AP的标签
for tag in event_acc.Tags()['tensors']:
    if tag.startswith(ap_tag_prefix):
        # 提取当前标签的所有数值记录
        tensor_events = event_acc.Tensors(tag)
        # 遍历每个step的记录
        for e in tensor_events:
            class_id = tag.split('/')[-1]
            ap_value = tf.make_ndarray(e.tensor_proto).item()
            ap_results.append({
                'class_id': class_id,
                'step': e.step,
                'wall_time': e.wall_time,
                'average_precision': ap_value
            })

# 转成DataFrame,可直接导出为CSV
ap_df = pd.DataFrame(ap_results)
print(ap_df)
# 导出CSV
ap_df.to_csv('class_ap_results.csv', index=False)

代码说明

  • 匹配所有前缀为PascalBoxes_PerformanceByCategory/AP@0.5IOU/的标签,对应你需要的6个类别的AP数值
  • 通过event_acc.Tensors(tag)获取对应标签的所有记录,每个记录包含step、时间戳和tensor格式的数值
  • 用tf.make_ndarray将tensor_proto转为numpy数值,提取标量结果
  • 最终结果可直接导出为CSV文件使用

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.15 15:15:07