[pycaffe] expose global ("Caffe::") functions
authorJonathan L Long <jonlong@cs.berkeley.edu>
Thu, 8 Jan 2015 00:47:52 +0000 (16:47 -0800)
committerJonathan L Long <jonlong@cs.berkeley.edu>
Tue, 17 Feb 2015 06:46:13 +0000 (22:46 -0800)
python/caffe/_caffe.cpp

index 9a10046..7caf785 100644 (file)
 #define PyArray_SetBaseObject(arr, x) (PyArray_BASE(arr) = (x))
 #endif
 
+namespace bp = boost::python;
+
 namespace caffe {
 
 // For Python, for now, we'll just always use float as the type.
 typedef float Dtype;
 
+void set_mode_cpu() { Caffe::set_mode(Caffe::CPU); }
+void set_mode_gpu() { Caffe::set_mode(Caffe::GPU); }
+void set_phase_train() { Caffe::set_phase(Caffe::TRAIN); }
+void set_phase_test() { Caffe::set_phase(Caffe::TEST); }
+
 // For convenience, check that input files can be opened, and raise an
 // exception that boost will send to Python if not (caffe could still crash
 // later if the input files are disturbed before they are actually used, but
@@ -41,6 +48,15 @@ static void CheckFile(const string& filename) {
 }
 
 BOOST_PYTHON_MODULE(_caffe) {
+  // below, we prepend an underscore to methods that will be replaced
+  // in Python
+  // Caffe utility functions
+  bp::def("set_mode_cpu", &set_mode_cpu);
+  bp::def("set_mode_gpu", &set_mode_gpu);
+  bp::def("set_phase_train", &set_phase_train);
+  bp::def("set_phase_test", &set_phase_test);
+  bp::def("set_device", &Caffe::SetDevice);
+
   import_array();
 }