[英]Tensorflow: Save tensors in graph to file (or image)
I currently have a complex set of operations that iteratively create images and feed them to processes to be used. 我目前有一组复杂的操作,这些操作可以迭代创建图像并将它们提供给要使用的进程。 This is part of a very huge and complex graph. 这是非常庞大而复杂的图的一部分。 I would like to make sure that those images are being created correctly. 我想确保正确创建了这些图像。
Normally for debugging, we have tf.Print
, which creates a no-op with a side-effect of printing to the screen. 通常用于调试,我们有tf.Print
,它创建了一个无操作,具有打印到屏幕的副作用。
Is there either 有没有
a) Some way I can store a very large intermediate tensor to a file? a)我可以以某种方式将非常大的中间张量存储到文件中吗?
b) Some way to specifically store intermediate tensor images to file (or the screen)? b)专门将中间张量图像存储到文件(或屏幕)的某种方法?
Obviously, if I have an evaluated numeric tensor this is no problem as I can visualize it using matplotlib's imshow
, but as a symbolic tensor it's not so obvious how to do this. 显然,如果我有一个评估的数字张量,这没问题,因为我可以使用matplotlib的imshow
可视化它,但作为符号张量,如何执行它并不是那么明显。
I could save a bunch of intermediate tensors to evaluate with sess.run
, but the way my code is architected, it will be very hard to manually access and gather those all. 我可以保存一堆中间张量,以使用sess.run
进行评估,但是我的代码的sess.run
方式将非常难以手动访问并收集所有这些。
The best way to save tensors with spatial correlations (image like tensors) in tensorflow is via tf.summary.image
. 在张量流中保存具有空间相关性(例如张量的图像)的张量的最佳方法是通过tf.summary.image
。 Check out the tensorboard tutorial for how it all fits together, but the crux is like the following: 查看tensorboard教程 ,了解如何将它们完美地组合在一起,但关键之处如下:
tf.summary.image("img", img)
merged = tf.summary.merge_all()
train_writer = tf.summary.FileWriter('logs', sess.graph)
for i in range(num_iters):
summary = sess.run(merged)
train_writer.add_summary(summary, i)
Then start up tensorboard: 然后启动张量板:
tensorboard --logdir logs
Then go to localhost:6006
in a browser to see the summaries. 然后在浏览器中转到localhost:6006
以查看摘要。
The downside to this approach is that you don't have fine grain control over what slice you see unless you explicitly specify (eg tf.summary.image("img", img[...,10])
) 这种方法的缺点是,除非明确指定,否则您无法很好地控制所看到的切片(例如tf.summary.image("img", img[...,10])
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.