1

I am trying to use an R-script in a docker environment to do some classification on the input that I am piping to it. The script should only print the output of the classification, however I always get Using TensorFlow backend. as output of the first line where a function of Keras is called.

I made a small working example.

library(keras)

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

I want to display this as output:

[1] 1 2 3

I get however

[1] 1 2 3
Using TensorFlow backend.

So I searched around on google and stackoverflow about sink and suppress... and other stuff, from for example Suppress automatic output to console in R, Suppress one command's output in R and Suppress automatic output to console in R. I then tried the following piece of code:

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()

This still doesn't suppress the Using TensorFlow backend. message. The script is called in a docker environment using littler, from the command line: r test.R. Note: when just running the script in Rstudio I don't get the message.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
faust2016
  • 13
  • 4
  • Unfortunately, it seems standard behavior, for which other people have been complaining, too, but without a resolution so far: ["Using X backend." always printed to stdout](https://github.com/keras-team/keras/issues/1406) – desertnaut Jun 26 '18 at 11:42

1 Answers1

0

This is a Keras issue (i.e. not an R or Tensorflow one) and, as I have already commented, there have been several people complaining about this, but a solution has not been proposed by Keras maintainers so far.

A hack, as already suggested in the issue thread above, is to locate the keras/backend/__init__.py file and comment out the following line:

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

Last time I checked, Keras in R only uses the Tensorflow backend, so you shouldn't need to repeat this for the other backend options in __init__.py.

desertnaut
  • 57,590
  • 26
  • 140
  • 166