Using tensorflow2, I am trying to log the tensorflow execution using function call tf.summary.trace_export() and view it in tensorboard graph. But, While calling tf.summary.trace_export(name="my_func_trace", step=0, profiler_outdir=logdir)
, getting error as
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
Do i need to create /plugin/profile/ manually apart from creating file writer using
stamp = datetime.now().strftime("%Y%m%d-%H%M%S")
logdir = 'logs/func/%s' % stamp
writer = tf.summary.create_file_writer(logdir)
This same error comes when i tried to execute the example given in tensorflow.org (https://www.tensorflow.org/tensorboard/graphs#graphs_of_tffunctions)
Here is my tensorflow simple code:
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)
Error Trace:
(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>
This same error comes for the example given in tensorflow.org code (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)
I am using windows 10 for development.
logdir = logs\\fit\\ + datetime.now().strftime("%Y%m%d-%H%M%S")
to see the output run tensorboard --logdir=fit
from the logs directory
for the @tf.function
don't use the datetime just use logdir = logs\\func
.
To see the tf.function
graph run tensorboard --logdir=func
from the logs directory.
If using tensorboard extension (really nice not leaving jupyter lab) run from /logs/fit
and logs/func
.
On windows, use logdir = 'logs\\tensor-constants\\%s' % stamp
instead of logdir = './logs/tensor-constants/%s' % stamp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With