本文整理汇总了Python中tensorflow.python.client.timeline.Timeline方法的典型用法代码示例。如果您正苦于以下问题:Python timeline.Timeline方法的具体用法?Python timeline.Timeline怎么用?Python timeline.Timeline使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.client.timeline
的用法示例。
在下文中一共展示了timeline.Timeline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def _get(self, feed_data, op_names):
""" Get results of one mini-batch """
ops = [self._model.ops[nn] for nn in op_names]
# profile code
if self._is_profile:
op_results = self._session.run(
ops,
feed_dict=feed_data,
options=self._run_options,
run_metadata=self._run_metadata)
trace = timeline.Timeline(self._run_metadata.step_stats)
chrome_trace = trace.generate_chrome_trace_format()
with open(os.path.join(self._save_dir, 'timeline.json'), 'w') as f:
f.write(chrome_trace)
else:
op_results = self._session.run(ops, feed_dict=feed_data)
results = {}
for rr, name in zip(op_results, op_names):
results[name] = rr
return results
示例2: create_tf_timeline
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def create_tf_timeline(model_dir, run_metadata):
"""
This is helpful for profiling slow Tensorflow code.
Args:
model_dir:
run_metadata:
Returns:
"""
tl = timeline.Timeline(run_metadata.step_stats)
ctf = tl.generate_chrome_trace_format()
timeline_file_path = os.path.join(model_dir,'timeline.json')
with open(timeline_file_path, 'w') as f:
f.write(ctf)
示例3: evaluate_full_batch
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def evaluate_full_batch(sess,model,minibatch_iter,many_runs_timeline,mode):
"""
Full batch evaluation
NOTE: HERE GCN RUNS THROUGH THE FULL GRAPH. HOWEVER, WE CALCULATE F1 SCORE
FOR VALIDATION / TEST NODES ONLY.
"""
options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
t1 = time.time()
num_cls = minibatch_iter.class_arr.shape[-1]
feed_dict, labels = minibatch_iter.feed_dict(mode)
if args_global.timeline:
preds,loss = sess.run([model.preds, model.loss], feed_dict=feed_dict, options=options, run_metadata=run_metadata)
fetched_timeline = timeline.Timeline(run_metadata.step_stats)
chrome_trace = fetched_timeline.generate_chrome_trace_format()
many_runs_timeline.append(chrome_trace)
else:
preds,loss = sess.run([model.preds, model.loss], feed_dict=feed_dict)
node_val_test = minibatch_iter.node_val if mode=='val' else minibatch_iter.node_test
t2 = time.time()
f1_scores = calc_f1(labels[node_val_test],preds[node_val_test],model.sigmoid_loss)
return loss, f1_scores[0], f1_scores[1], (t2-t1)
示例4: cli_profile_timeline
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def cli_profile_timeline(self):
"""Performs training profiling to produce timeline.json. """
# TODO integrate this into Profile.
from tensorflow.python.client import timeline
options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
session = self._get_session('train')
# run 100 iterations to warm up
max_iterations = 100
for i in range(max_iterations):
log.info(
'Running {}/{} iterations to warm up...'
.format(i, max_iterations), update=True)
session.run(session._train_op)
log.info('Running the final iteration to generate timeline...')
session.run(
session._train_op, options=options, run_metadata=run_metadata)
fetched_timeline = timeline.Timeline(run_metadata.step_stats)
chrome_trace = fetched_timeline.generate_chrome_trace_format()
with open('timeline.json', 'w') as f:
f.write(chrome_trace)
示例5: run
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def run(self, fetches, feed_dict=None):
"""like Session.run, but return a Timeline object in Chrome trace format (JSON).
Save the json to a file, go to chrome://tracing, and open the file.
Args:
fetches
feed_dict
Returns:
dict: a JSON dict
"""
options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
super(ProfiledSession, self).run(fetches, feed_dict, options=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()
return json.loads(ctf)
示例6: E_val
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def E_val(self, X):
with self.graph.as_default(), tf.device(self.energy_device):
if self.prof_run:
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
energy = self.sess.run(self.energy_op, feed_dict={self.state_pl: X},
options=run_options, run_metadata=run_metadata)
tf_tl = timeline.Timeline(run_metadata.step_stats)
ctf = tf_tl.generate_chrome_trace_format()
log_path = expanduser('~/tmp/logs/tf_{}_energy_timeline_{}.json'.format(self.name, time.time()))
with open(log_path, 'w') as log_file:
log_file.write(ctf)
else:
energy = self.sess.run(self.energy_op, feed_dict={self.state_pl: X})
return energy
示例7: dEdX_val
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def dEdX_val(self, X):
with self.graph.as_default(), tf.device(self.grad_device):
if self.prof_run:
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
grad = self.sess.run(self.grad_op, feed_dict={self.state_pl: X},
options=run_options, run_metadata=run_metadata)
tf_tl = timeline.Timeline(run_metadata.step_stats)
ctf = tf_tl.generate_chrome_trace_format()
log_path = expanduser('~/tmp/logs/tf_{}_grad_timeline_{}.json'.format(self.name, time.time()))
with open(log_path, 'w') as log_file:
log_file.write(ctf)
else:
grad = self.sess.run(self.grad_op, feed_dict={self.state_pl: X})
return grad
示例8: profiled_run
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def profiled_run(sess, ops, feed_dict, is_profiling=False, log_dir=None):
if not is_profiling:
return sess.run(ops, feed_dict=feed_dict)
else:
if log_dir is None:
raise ValueError("You need to provide a log_dir for profiling.")
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
outputs = sess.run(ops, feed_dict=feed_dict, 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(os.path.join(log_dir, 'timeline.json'), 'w') as f:
f.write(ctf)
return outputs
示例9: save_checkpoint_chrome_trace
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def save_checkpoint_chrome_trace(dataset: str, model_name: str, log_base: PathLike, batch_size: int = 32):
def trace_solver_solution(save_path: PathLike, train_ds, solver):
import tensorflow.compat.v1 as tf1
from tensorflow.python.client import timeline
data_iter = train_ds.__iter__()
data_list = [x.numpy() for x in data_iter.next()]
with tf1.Session() as sess:
sqrtn_fn, *_ = _build_model_via_solver(dataset, model_name, train_ds.element_spec, solver)
out = sqrtn_fn(*[tf1.convert_to_tensor(x) for x in data_list])
run_meta = tf1.RunMetadata()
sess.run(tf1.global_variables_initializer())
sess.run(out, options=tf1.RunOptions(trace_level=tf1.RunOptions.FULL_TRACE), run_metadata=run_meta)
t1 = timeline.Timeline(run_meta.step_stats)
lctf = t1.generate_chrome_trace_format()
with Path(save_path).open("w") as f:
f.write(lctf)
log_base = Path(log_base)
log_base.mkdir(parents=True, exist_ok=True)
train_ds, test_ds = get_data(dataset, batch_size=batch_size)
trace_solver_solution(log_base / "check_all.json", train_ds, solve_checkpoint_all)
trace_solver_solution(log_base / "check_sqrtn_noap.json", train_ds, solve_chen_sqrtn_noap)
示例10: profile
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def profile(self, session):
evals = [self.model.cost]
for batch in self.batcher:
state, att_states, att_ids, att_counts = get_initial_state(self.model)
for seq_batch in self.batcher.sequence_iterator(batch):
feed_dict = construct_feed_dict(self.model, seq_batch, state, att_states, att_ids, att_counts)
run_metadata = tf.RunMetadata()
session.run(evals, feed_dict=feed_dict,
options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE),
run_metadata=run_metadata)
break
from tensorflow.python.client import timeline
trace = timeline.Timeline(step_stats=run_metadata.step_stats)
trace_file = open('timeline.ctf.json', 'w')
trace_file.write(trace.generate_chrome_trace_format())
示例11: _save
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def _save(self, step, save_path, step_stats):
logging.info("Saving timeline for %d into '%s'.", step, save_path)
with gfile.Open(save_path, "w") as f:
trace = timeline.Timeline(step_stats)
f.write(trace.generate_chrome_trace_format(
show_dataflow=self._show_dataflow,
show_memory=self._show_memory))
示例12: update_timeline_if_necessary
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def update_timeline_if_necessary(self):
"""
Writes a timeline json file according to specification.
"""
if self.timeline_step % self.timeline_frequency == 0:
fetched_timeline = timeline.Timeline(self.run_metadata.step_stats)
chrome_trace = fetched_timeline.generate_chrome_trace_format()
with open("timeline_{:02d}.json".format(self.timeline_step), "w") as f:
f.write(chrome_trace)
self.timeline_step += 1
示例13: trace
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def trace(config, sess, model, train_data):
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
X, Q, Y = random_batch(*train_data, config.batch_size)
model.batch_fit(X, Q, Y, learning_rate, run_options, run_metadata)
train_writer.add_run_metadata(run_metadata, 'step%d' % step)
from tensorflow.python.client import timeline
tl = timeline.Timeline(run_metadata.step_stats)
ctf = tl.generate_chrome_trace_format()
with open('timeline.json', 'w') as f:
f.write(ctf)
return
示例14: write_timeline
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def write_timeline(self,step_stats,file_name):
fetched_timeline = timeline.Timeline(step_stats)
chrome_trace = fetched_timeline.generate_chrome_trace_format()
with open(file_name, 'w') as f:
f.write(chrome_trace)
示例15: testSimpleTimeline
# 需要导入模块: from tensorflow.python.client import timeline [as 别名]
# 或者: from tensorflow.python.client.timeline import Timeline [as 别名]
def testSimpleTimeline(self):
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
with tf.device('/cpu:0'):
with tf.Session() as sess:
sess.run(
tf.constant(1.0),
options=run_options,
run_metadata=run_metadata)
self.assertTrue(run_metadata.HasField('step_stats'))
tl = timeline.Timeline(run_metadata.step_stats)
ctf = tl.generate_chrome_trace_format()
self._validateTrace(ctf)