Skip to content

Commit

Permalink
expose input and output blob names to python as lists
Browse files Browse the repository at this point in the history
  • Loading branch information
shelhamer committed May 14, 2014
1 parent 872ddf3 commit 56ca978
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/caffe/net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Net {
inline int num_outputs() { return net_output_blobs_.size(); }
inline vector<Blob<Dtype>*>& input_blobs() { return net_input_blobs_; }
inline vector<Blob<Dtype>*>& output_blobs() { return net_output_blobs_; }
inline vector<int>& input_blob_indices() { return net_input_blob_indices_; }
inline vector<int>& 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
Expand Down
20 changes: 20 additions & 0 deletions python/caffe/_caffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,24 @@ struct CaffeNet {
return result;
}

list inputs() {
list input_blob_names;
for (vector<int>::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<int>::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<float> > net_;
// if taking input from an ndarray, we need to hold references
Expand Down Expand Up @@ -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_<CaffeBlob, CaffeBlobWrap>(
Expand Down

0 comments on commit 56ca978

Please sign in to comment.