24

I'm using Caffe, which is printing a lot of output to the shell when loading the neural net.
I'd like to suppress that output, which supposedly can be done by setting GLOG_minloglevel=1 when running the Python script. I've tried doing that using the following code, but I still get all the output from loading the net. How do I suppress the output correctly?

os.environ["GLOG_minloglevel"] = "1"
net = caffe.Net(model_file, pretrained, caffe.TEST)
os.environ["GLOG_minloglevel"] = "0"
Shai
  • 111,146
  • 38
  • 238
  • 371
pir
  • 5,513
  • 12
  • 63
  • 101

2 Answers2

50

To supress the output level you need to increase the loglevel to at least 2

 os.environ['GLOG_minloglevel'] = '2' 

The levels are

0 - debug
1 - info (still a LOT of outputs)
2 - warnings
3 - errors


Update:
Since this flag is global to caffe, it must be set prior to importing of caffe package (as pointed out by jbum). Once the flag is set and caffe is imported the behavior of the GLOG tool cannot be changed.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • 1
    > `minloglevel` Log messages at or above this level. Again, the numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. http://rpg.ifi.uzh.ch/docs/glog.html – Till Jan 19 '19 at 17:04
  • In case of PyCharm, You can set environment variable as follows: 1) Click menu item `Run` - `Edit Configurations...` 2) Find `Environment variables:` in the `Environment` group in `Configuration` tab and click the rightmost `...` icon 3) Click `+` and set Name `GLOG_minloglevel` and its value `2` or you want. You don't need to use ` os.environ['GLOG_minloglevel'] = '2' ` before `import caffe` and don't need to restart PyCharm session. – Hongsoog Oct 20 '21 at 05:50
28

I was able to get Shai's solution to work, but only by executing that line in Python before calling

import caffe
Community
  • 1
  • 1
jbum
  • 411
  • 4
  • 5