diff --git a/include/caffe/net.hpp b/include/caffe/net.hpp index 179eadb8627..46d72a6b0a1 100644 --- a/include/caffe/net.hpp +++ b/include/caffe/net.hpp @@ -89,6 +89,8 @@ class Net { inline int num_outputs() { return net_output_blobs_.size(); } inline vector*>& input_blobs() { return net_input_blobs_; } inline vector*>& output_blobs() { return net_output_blobs_; } + inline vector& input_blob_indices() { return net_input_blob_indices_; } + inline vector& output_blob_indices() { return net_output_blob_indices_; } // has_blob and blob_by_name are inspired by // https://github.com/kencoken/caffe/commit/f36e71569455c9fbb4bf8a63c2d53224e32a4e7b // Access intermediary computation layers, testing with centre image only diff --git a/python/caffe/_caffe.cpp b/python/caffe/_caffe.cpp index bd2b28177e3..e1ee652b402 100644 --- a/python/caffe/_caffe.cpp +++ b/python/caffe/_caffe.cpp @@ -350,6 +350,24 @@ struct CaffeNet { return result; } + list inputs() { + list input_blob_names; + for (vector::iterator it = net_->input_blob_indices().begin(); + it != net_->input_blob_indices().end(); ++it) { + input_blob_names.append(net_->blob_names()[*it]); + } + return input_blob_names; + } + + list outputs() { + list output_blob_names; + for (vector::iterator it = net_->output_blob_indices().begin(); + it != net_->output_blob_indices().end(); ++it) { + output_blob_names.append(net_->blob_names()[*it]); + } + return output_blob_names; + } + // The pointer to the internal caffe::Net instant. shared_ptr > net_; // if taking input from an ndarray, we need to hold references @@ -399,6 +417,8 @@ BOOST_PYTHON_MODULE(_caffe) { .def("set_device", &CaffeNet::set_device) .add_property("_blobs", &CaffeNet::blobs) .add_property("layers", &CaffeNet::layers) + .add_property("inputs", &CaffeNet::inputs) + .add_property("outputs", &CaffeNet::outputs) .def("_set_input_arrays", &CaffeNet::set_input_arrays); boost::python::class_(