Caffe关闭日志输出

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

在训练Caffe模型后,部署Caffe服务时我们通常会使用pycaffe来加载模型并处理图像,但是pycaffe加载模型时通常会输出加载模型的日志,影响我们查看自己的日志,因此需要移除Caffe加载模型时的日志。代码如下:

1
2
os.environ['GLOG_minloglevel'] = '2'
import caffe

Caffe使用的日志是GLOG,其日志级别如下:

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

注意:由于在导入Caffe时Caffe会加载GLOG,因此os.environ['GLOG_minloglevel'] = '2'需要在import caffe之前。

参考资料

  1. https://stackoverflow.com/questions/29788075/setting-glog-minloglevel-1-to-prevent-output-in-shell-from-caffe
如果有收获,可以请我喝杯咖啡!