tensorflow2错误 - 在函数调用tf.summary.trace_exp中无法创建插件/概要/目录

2024-10-04 09:26:39 发布

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

使用tensorflow2,我尝试使用函数调用记录tensorflow的执行tf.summary.trace\u导出()并在张力板图中查看。但是,在调用tf.summary.trace_export(name="my_func_trace", step=0, profiler_outdir=logdir)

tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: logs/func/20191105-014756\plugins\profile\2019-11-05_01-47-57; No such file or directory

除了使用创建文件编写器之外,我还需要手动创建/plugin/profile/吗

stamp = datetime.now().strftime("%Y%m%d-%H%M%S")
logdir = 'logs/func/%s' % stamp
writer = tf.summary.create_file_writer(logdir)

当我尝试执行中给出的示例时,也会出现同样的错误tensorflow.org网站(https://www.tensorflow.org/tensorboard/graphs#graphs_of_tffunctions

这是我的tensorflow简单代码:

import tensorflow as tf
from datetime import datetime

stamp = datetime.now().strftime("%Y%m%d-%H%M%S")
logdir = './logs/tensor-constants/%s' % stamp
writer = tf.summary.create_file_writer(logdir)

a = tf.constant(1, dtype=tf.int32, shape=(), name='a')
b = tf.constant(2, dtype=tf.int32, shape=(), name='b')

tf.summary.trace_on(graph=True, profiler=True)

add = tf.math.add(a,b, name='addition')

# Print will be tensornode value
print(add)

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

错误跟踪:

(venv) PS C:\Users\amvij\Vijay\github\tensorflow-learning> & c:/Users/amvij/Vijay/github/tensorflow-learning/venv/Scripts/python.exe c:/Users/amvij/Vijay/github/tensorflow-learning/basics/tensor-constants.py
2019-11-05 02:11:50.385963: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-11-05 02:11:50.409tf.Tensor(3, shape=(), dtype=int32)
Traceback (most recent call last):
  File "c:/Users/amvij/Vijay/github/tensorflow-learning/basics/tensor-constants.py", line 28, in <module>
    profiler_outdir=logdir)
  File "C:\Users\amvij\Vijay\github\tensorflow-learning\venv\lib\site-packages\tensorflow_core\python\ops\summary_ops_v2.py", line 1218, in trace_export
    _profiler.save(profiler_outdir, _profiler.stop())
  File "C:\Users\amvij\Vijay\github\tensorflow-learning\venv\lib\site-packages\tensorflow_core\python\eager\profiler.py", line 140, in save
    gfile.MakeDirs(plugin_dir)
  File "C:\Users\amvij\Vijay\github\tensorflow-learning\venv\lib\site-packages\tensorflow_core\python\lib\io\file_io.py", line 438, in recursive_create_dir
    recursive_create_dir_v2(dirname)
  File "C:\Users\amvij\Vijay\github\tensorflow-learning\venv\lib\site-packages\tensorflow_core\python\lib\io\file_io.py", line 453, in recursive_create_dir_v2
    pywrap_tensorflow.RecursivelyCreateDir(compat.as_bytes(path))
tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: ./logs/tensor-constants/20191105-021150\plugins\profile\2019-11-05_02-11-50; No such file or directory
(venv) PS C:\Users\amvij\Vijay\github\tensorflow-learning>

同样的错误也出现在中给出的示例中tensorflow.org网站代码(https://www.tensorflow.org/tensorboard/graphs#graphs_of_tffunctions):

from datetime import datetime
import tensorflow as tf

# The function to be traced.
@tf.function
def my_func(x, y):
  # A simple hand-rolled layer.
  return tf.nn.relu(tf.matmul(x, y))

# Set up logging.
stamp = datetime.now().strftime("%Y%m%d-%H%M%S")
logdir = 'logs/func/%s' % stamp
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)

我正在使用Windows10进行开发。你知道吗


Tags: githubtftensorflowcreatetracesummaryusersprofiler