From e94be07e2d7e186821698df053ef77a35fe71c26 Mon Sep 17 00:00:00 2001 From: philkr Date: Thu, 23 Jul 2015 08:33:58 -0700 Subject: [PATCH] Exposing blob loss weight to python --- python/caffe/_caffe.cpp | 4 ++++ python/caffe/pycaffe.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/python/caffe/_caffe.cpp b/python/caffe/_caffe.cpp index bb5130f..e1ae3ec 100644 --- a/python/caffe/_caffe.cpp +++ b/python/caffe/_caffe.cpp @@ -211,6 +211,8 @@ BOOST_PYTHON_MODULE(_caffe) { .def("copy_from", static_cast::*)(const string)>( &Net::CopyTrainedLayersFrom)) .def("share_with", &Net::ShareTrainedLayersWith) + .add_property("_blob_loss_weights", bp::make_function( + &Net::blob_loss_weights, bp::return_internal_reference<>())) .add_property("_blobs", bp::make_function(&Net::blobs, bp::return_internal_reference<>())) .add_property("layers", bp::make_function(&Net::layers, @@ -293,6 +295,8 @@ BOOST_PYTHON_MODULE(_caffe) { .def(bp::vector_indexing_suite >()); bp::class_ >("IntVec") .def(bp::vector_indexing_suite >()); + bp::class_ >("DtypeVec") + .def(bp::vector_indexing_suite >()); bp::class_ > > >("NetVec") .def(bp::vector_indexing_suite > >, true>()); bp::class_ >("BoolVec") diff --git a/python/caffe/pycaffe.py b/python/caffe/pycaffe.py index e8a676a..4f980a9 100644 --- a/python/caffe/pycaffe.py +++ b/python/caffe/pycaffe.py @@ -28,6 +28,15 @@ def _Net_blobs(self): @property +def _Net_blob_loss_weights(self): + """ + An OrderedDict (bottom to top, i.e., input to output) of network + blob loss weights indexed by name + """ + return OrderedDict(zip(self._blob_names, self._blob_loss_weights)) + + +@property def _Net_params(self): """ An OrderedDict (bottom to top, i.e., input to output) of network @@ -270,6 +279,7 @@ def _Net_batch(self, blobs): # Attach methods to Net. Net.blobs = _Net_blobs +Net.blob_loss_weights = _Net_blob_loss_weights Net.params = _Net_params Net.forward = _Net_forward Net.backward = _Net_backward -- 2.7.4