Tensorflow Timeline介绍及简单使用

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


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

简介

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

使用方法

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

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

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的详细信息。json

timeline-tool
chrome 加载timeline.json文件后展现的运行图


2018/4/22 done机器学习

此文章也同步至我的Github博客工具

相关文章
相关标签/搜索