我使用tensorflow2尝试使用函数调用tf.summary.trace_export()记录tensorflow执行,并在tensorboard图形中查看它。但是,在调用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,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",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,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",profiler_outdir=logdir)
我正在使用Windows 10进行开发。