【问题标题】:Suppress console output from Keras in R在 R 中抑制 Keras 的控制台输出
【发布时间】:2018-06-26 11:01:03
【问题描述】:

我正在尝试在 docker 环境中使用 R 脚本对我通过管道传输的输入进行一些分类。 该脚本应该只打印分类的输出,但是我总是得到 Using TensorFlow backend. 作为调用 Keras 函数的第一行的输出。

我做了一个小的工作示例。

library(keras)

v <- (c(1,2,3))
print(v)
vCat<-to_categorical(v)

我想将其显示为输出:

[1] 1 2 3

我明白了

[1] 1 2 3
Using TensorFlow backend.

所以我在 google 和 stackoverflow 上搜索了 sinksuppress... 以及其他内容,例如 Suppress automatic output to console in RSuppress one command's output in RSuppress automatic output to console in R。然后我尝试了以下代码:

library(keras, quietly = T)

v <- (c(1,2,3))
print(v) 
sink("/dev/null")
capture.output(suppressMessages(suppressWarnings(
suppressPackageStartupMessages(
vCat<-to_categorical(v) ))), file = "/dev/null")
sink()

这仍然不会抑制Using TensorFlow backend. 消息。该脚本在 docker 环境中使用 littler 从命令行调用:r test.R。 注意:仅在 Rstudio 中运行脚本时,我没有收到消息。

【问题讨论】:

标签: r keras


【解决方案1】:

这是一个 Keras 问题(即不是 R 或 Tensorflow 问题),正如我已经评论过的,有几个人 complaining about this,但到目前为止,Keras 维护人员还没有提出解决方案。

正如issue thread above 中已经建议的那样,hack 是找到keras/backend/__init__.py 文件并注释掉following line

sys.stderr.write('Using TensorFlow backend.\n')

上次我检查时,R 中的 Keras 仅使用 Tensorflow 后端,因此您无需对 __init__.py 中的其他后端选项重复此操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    相关资源
    最近更新 更多