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

如何修复运行tf.summary.trace_on时提示使用tf.profiler.experimental.start的警告?

警告修复方案

场景1:仅需要导出计算图,不需要性能分析

直接修改原代码的参数即可,无需调整其他逻辑:
将原代码
tf.summary.trace_on(graph=True, profiler=True)
修改为
tf.summary.trace_on(graph=True, profiler=False)
即可消除警告。

场景2:需要同时使用计算图导出 + 性能分析功能

推荐替换为官方推荐的新版Profiler接口,完整使用示例如下:

import tensorflow as tf

# 替换为你自己的TensorBoard日志存储路径
log_dir = "./tensorboard_logs"

# 启动Profiler性能采样
tf.profiler.experimental.start(log_dir)

# 你要追踪的业务逻辑,比如模型训练、前向计算
with tf.summary.create_file_writer(log_dir).as_default():
    # 此处替换为你的实际计算逻辑
    model_output = your_model(input_data)
    # 导出计算图到TensorBoard
    tf.summary.graph(tf.compat.v1.get_default_graph(), step=0)

# 停止Profiler采样,生成性能数据
tf.profiler.experimental.stop()

临时应急方案

如果暂时不想调整代码逻辑,可以在代码开头加入以下内容隐藏废弃警告:

import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning, module="tensorflow")

注意:该方法仅隐藏警告不会修复底层问题,TensorFlow后续版本移除废弃接口后代码会直接报错,不推荐长期使用

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.08 23:15:03