如何在张力板中显示tf.data.Dataset数据集.map子图在Tensorflow 2.0中?

2024-06-28 20:36:58 发布

您现在位置:Python中文网/ 问答频道 /正文

根据documentationtf.data.Datasets在图形模式下工作(在eager和graph模式下):

Note that irrespective of the context in which map_func is defined (eager vs. graph), tf.data traces the function and executes it as a graph

在TensorFlow1.X中,我们可以很容易地在Tensorboard中绘制这个图:处理函数被绘制在一个子图中。你知道吗

例如

def _parse_function(x):
    return x * 2

x = tf.constant([0 , 1])
dataset = tf.data.Dataset.from_tensor_slices(x)
dataset = dataset.map(_parse_function)

在Tensorboard中,会出现一个子图,对应于\u parse \u函数: enter image description here

但是,在Tensorflow 2.0中,这不会在Tensorboard图中生成任何可见元素。 以下代码不会根据Tensorboard生成任何图形:

def _parse_function(x):
    return x * 2

logdir = 'logs'
writer = tf.summary.create_file_writer(logdir)

tf.summary.trace_on(graph=True, profiler=True)
x = tf.constant([0 , 1])
dataset = tf.data.Dataset.from_tensor_slices(x)
dataset = dataset.map(_parse_function)

with writer.as_default():
  tf.summary.trace_export(
      name="trace",
      step=0,
      profiler_outdir=logdir)

那么,既然一个图是在调用map时创建的,那么有没有方法访问/可视化这个图呢?你知道吗


Tags: 图形mapdataparsetf模式tracefunction