tensorflow--监控运行

import tensorflow as tf
@tf.function      #启用图必须开启
def my_func(x, y):
  # A simple hand-rolled layer.
  return tf.multiply(x, y)

# Set up logging.
logdir = r"C:\Users\Admin\Documents\vscode\g"
writer = tf.summary.create_file_writer(logdir)      #日志文件保存

# Sample data for your function.
x = tf.random.uniform((3, 3))
y = tf.random.uniform((3, 3))

# Bracket the function call with
# tf.summary.trace_on() and tf.summary.trace_export().
tf.summary.trace_on(graph=True, profiler=True)    #打开流监控
# Call only one tf.function when tracing.
z = my_func(x, y)
with writer.as_default():
  tf.summary.trace_export(
      name="my_func_trace",
      step=0,
      profiler_outdir=logdir)

参考:
https://www.tensorflow.org/tensorboard/graphs?hl=zh-cn

posted @ 2021-08-31 22:40  kuanleung  阅读(22)  评论(0)    收藏  举报  来源