Tensorflow Timeline介绍及简单使用

Blog的Github地址:github.com/liuyan731/b…


最近上线了一个图片分类的机器学习Python服务,但是在线上的性能并不是特别好,就开始进行痛苦的性能分析。今天分享一个简单但是非常实用的Tensorflow性能调优工具Timeline。

简介

Tensorflow的Timeline模块是用于描述张量图一个工具,可以记录在会话中每个操作执行时间和资源分配及消耗的情况。

使用方法

执行代码sess.run()加入参数options和run_metadata

sess.run() 加入 option和run_metadata参数,然后创建timeline对象,并写入到timeline.json文件中

import tensorflow as tf
from tensorflow.python.client import timeline

run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()

predictions = use_sess.run(use_out, {'DecodeJpeg/contents:0': image_file.file.getvalue()}, options=run_options, run_metadata=run_metadata)

# Create the Timeline object, and write it to a json
tl = timeline.Timeline(run_metadata.step_stats)
ctf = tl.generate_chrome_trace_format()
with open('timeline.json', 'w') as f:
    f.write(ctf)

复制代码

查看timeline对象

打开Google Chrome,转到该页面 chrome://tracing并加载该timeline.json文件。在该页面上可以每个操作的耗时,以及op的详细信息。

chrome 加载timeline.json文件后展示的运行图


2018/4/22 done

此文章也同步至个人Github博客

转载于:https://juejin.im/post/5adc95eb6fb9a07aa9255075

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值