python - 在 google colab 中重定向或查看 stderr

标签 python tensorflow keras google-colaboratory tf.keras

我正在尝试在 google colab 中查看 keras.backend.print_tensor 的输出。有人说它会转到 stderr,假设 IPython notebook 在本地运行。

如何看待这一输出?或者如何在 colab 中重定向/查看 stderr,同时在网络浏览器中运行?

最佳答案

我可以使用 Tensorflow Version 2.1 在 Google Colab 中成功执行 tf.keras.backend.print_tensor 的输出。

下面提到的是代码:

import tensorflow as tf
tf.__version__  #2.1.0

x = tf.constant([[1.0, 2.0], [3.0, 4.0]])
tf.keras.backend.print_tensor(x)

输出如下所示:

[[1 2]
 [3 4]]
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[1., 2.],
       [3., 4.]], dtype=float32)>

这是 Google Colab Gist 的链接.

关于python - 在 google colab 中重定向或查看 stderr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59905087/

相关文章:

python - Keras:使用 flow_from_directory 的 fit_generator 的多个输入

python - 有没有办法在 "pure"Keras 中将图像从灰度转换为 RGB

python - 多特征因果CNN——Keras实现

python - 使用 Python 在每行末尾添加新行

带有 Office 2013 (office 15) 的 Python Makepy

python - 使用 python 在 Windows 10 上检测 USB 设备插入

python - 使用 HDFS 上的文件运行 tensorflow(找不到 libhdfs.so)

python - 检查抑扬格五音步?

tensorflow - tensorflow 中的自定义中值池

tensorflow - 如何将多个相同模型从保存文件加载到 Tensorflow 中的一个 session 中