Vij*_*ran 5 python tensorboard tensorflow2.0
使用 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
Run Code Online (Sandbox Code Playgroud)
除了使用创建文件编写器之外,我是否需要手动创建 /plugin/profile/
stamp = datetime.now().strftime("%Y%m%d-%H%M%S")
logdir = 'logs/func/%s' % stamp
writer = tf.summary.create_file_writer(logdir)
Run Code Online (Sandbox Code Playgroud)
当我尝试执行 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)
Run Code Online (Sandbox Code Playgroud)
错误跟踪:
(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>
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
我正在使用 Windows 10 进行开发。
小智 1
logdir = 从日志目录logs\\fit\\ + datetime.now().strftime("%Y%m%d-%H%M%S")
查看运行tensorboard的输出--logdir=fit
对于@tf.function不使用日期时间的情况,只需使用logdir = logs\\func.
要查看从日志目录tf.function运行的图表。tensorboard --logdir=func
如果使用tensorboard扩展(真的很好,不离开jupyter实验室)从/logs/fit和运行logs/func。
| 归档时间: |
|
| 查看次数: |
517 次 |
| 最近记录: |