rkerassuppress-warningssuppressmessage

Suppress (hard to catch) output of an R function


Is there any way to suppress the output generated by the function layer_dense() of the R package keras? Any of the four variants below leads to the following output on the first layer_dense() call, which I want to avoid:

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

Some trials:

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 is related but the above seems to be a harder to solve case.


Solution

  • Although it doesn't solve the problem in general (but I guess the tried solutions would be expected to work then), I now found a solution to this particular problem here and a bit of an explanation here. In short, calling Sys.setenv(TF_CPP_MIN_LOG_LEVEL = "1") will avoid the message (and there are levels 0,1,2,3 to choose from).