抑制(难以捕获)R 函数的输出

Suppress (hard to catch) output of an R function

有没有办法抑制R包keras的函数layer_dense()生成的输出? 以下四种变体中的任何一种都会在第一次 layer_dense() 调用时导致以下输出,我想避免这种情况:

2020-12-25 22:52:32.777776: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-12-25 22:52:32.792832: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f9ca7099490 executing computations on platform Host. Devices:
2020-12-25 22:52:32.792853: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version

一些试验:

library(keras)
in.lay <- layer_input(shape = 2)
capture.output(out.lay <- layer_dense(in.lay, units = 2))
q()

library(keras)
in.lay <- layer_input(shape = 2)
suppressWarnings(out.lay <- layer_dense(in.lay, units = 2))
q()

library(keras)
in.lay <- layer_input(shape = 2)
suppressMessages(out.lay <- layer_dense(in.lay, units = 2))
q()

library(keras)
in.lay <- layer_input(shape = 2)
suppressPackageStartupMessages(out.lay <- layer_dense(in.lay, units = 2))
q()

This 是相关的,但上面的情况似乎更难解决。

虽然它不能解决一般问题(但我想尝试过的解决方案应该会奏效),但我现在找到了解决这个特定问题的方法 here and a bit of an explanation here。简而言之,调用Sys.setenv(TF_CPP_MIN_LOG_LEVEL = "1")将避免该消息(并且有级别0,1,2,3可供选择)。