From: Jonathan L Long Date: Thu, 8 Jan 2015 00:47:52 +0000 (-0800) Subject: [pycaffe] expose global ("Caffe::") functions X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=798a65b442a798b7d20466e30e1f901c1aca8354;p=platform%2Fupstream%2Fcaffe.git [pycaffe] expose global ("Caffe::") functions --- diff --git a/python/caffe/_caffe.cpp b/python/caffe/_caffe.cpp index 9a10046..7caf785 100644 --- a/python/caffe/_caffe.cpp +++ b/python/caffe/_caffe.cpp @@ -22,11 +22,18 @@ #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(); }