summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorCyprien Noel <cyprien.noel@gmail.com>2016-11-22 13:14:45 -0800
committerCyprien Noel <cyprien.noel@gmail.com>2017-01-06 14:56:17 -0800
commit2317fa19d3f5a65cb22adcbd3792ea248996744e (patch)
tree120dfb761b550fdcab23aead7fc2e2c6c2835e66 /python
parentf731bc4a8fc63666ae2b997e435ceb2f13752403 (diff)
downloadcaffeonacl-2317fa19d3f5a65cb22adcbd3792ea248996744e.tar.gz
caffeonacl-2317fa19d3f5a65cb22adcbd3792ea248996744e.tar.bz2
caffeonacl-2317fa19d3f5a65cb22adcbd3792ea248996744e.zip
Logging from python, e.g. for lower log level on multi-GPU workers
Diffstat (limited to 'python')
-rw-r--r--python/caffe/__init__.py2
-rw-r--r--python/caffe/_caffe.cpp16
2 files changed, 17 insertions, 1 deletions
diff --git a/python/caffe/__init__.py b/python/caffe/__init__.py
index 35868a40..5fc6ec9b 100644
--- a/python/caffe/__init__.py
+++ b/python/caffe/__init__.py
@@ -1,5 +1,5 @@
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
-from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver, layer_type_list, set_random_seed
+from ._caffe import init_log, log, set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver, layer_type_list, set_random_seed
from ._caffe import __version__
from .proto.caffe_pb2 import TRAIN, TEST
from .classifier import Classifier
diff --git a/python/caffe/_caffe.cpp b/python/caffe/_caffe.cpp
index bdee75ac..0a86045b 100644
--- a/python/caffe/_caffe.cpp
+++ b/python/caffe/_caffe.cpp
@@ -51,6 +51,19 @@ const int NPY_DTYPE = NPY_FLOAT32;
void set_mode_cpu() { Caffe::set_mode(Caffe::CPU); }
void set_mode_gpu() { Caffe::set_mode(Caffe::GPU); }
+void InitLog(int level) {
+ FLAGS_logtostderr = 1;
+ FLAGS_minloglevel = level;
+ ::google::InitGoogleLogging("");
+ ::google::InstallFailureSignalHandler();
+}
+void InitLogInfo() {
+ InitLog(google::INFO);
+}
+void Log(const string& s) {
+ LOG(INFO) << s;
+}
+
void set_random_seed(unsigned int seed) { Caffe::set_random_seed(seed); }
// For convenience, check that input files can be opened, and raise an
@@ -283,6 +296,9 @@ BOOST_PYTHON_MODULE(_caffe) {
bp::scope().attr("__version__") = AS_STRING(CAFFE_VERSION);
// Caffe utility functions
+ bp::def("init_log", &InitLog);
+ bp::def("init_log", &InitLogInfo);
+ bp::def("log", &Log);
bp::def("set_mode_cpu", &set_mode_cpu);
bp::def("set_mode_gpu", &set_mode_gpu);
bp::def("set_random_seed", &set_random_seed);