Skip to content

Commit 2317fa1

Browse files
committed
Logging from python, e.g. for lower log level on multi-GPU workers
1 parent f731bc4 commit 2317fa1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

python/caffe/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
2-
from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver, layer_type_list, set_random_seed
2+
from ._caffe import init_log, log, set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver, layer_type_list, set_random_seed
33
from ._caffe import __version__
44
from .proto.caffe_pb2 import TRAIN, TEST
55
from .classifier import Classifier

python/caffe/_caffe.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ const int NPY_DTYPE = NPY_FLOAT32;
5151
void set_mode_cpu() { Caffe::set_mode(Caffe::CPU); }
5252
void set_mode_gpu() { Caffe::set_mode(Caffe::GPU); }
5353

54+
void InitLog(int level) {
55+
FLAGS_logtostderr = 1;
56+
FLAGS_minloglevel = level;
57+
::google::InitGoogleLogging("");
58+
::google::InstallFailureSignalHandler();
59+
}
60+
void InitLogInfo() {
61+
InitLog(google::INFO);
62+
}
63+
void Log(const string& s) {
64+
LOG(INFO) << s;
65+
}
66+
5467
void set_random_seed(unsigned int seed) { Caffe::set_random_seed(seed); }
5568

5669
// For convenience, check that input files can be opened, and raise an
@@ -283,6 +296,9 @@ BOOST_PYTHON_MODULE(_caffe) {
283296
bp::scope().attr("__version__") = AS_STRING(CAFFE_VERSION);
284297

285298
// Caffe utility functions
299+
bp::def("init_log", &InitLog);
300+
bp::def("init_log", &InitLogInfo);
301+
bp::def("log", &Log);
286302
bp::def("set_mode_cpu", &set_mode_cpu);
287303
bp::def("set_mode_gpu", &set_mode_gpu);
288304
bp::def("set_random_seed", &set_random_seed);

0 commit comments

Comments
 (0)