Created
March 18, 2018 12:32
-
-
Save berak/161b220097ceba0baf013a267ae67829 to your computer and use it in GitHub Desktop.
dnn print net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __printnet_onboard__ | |
#define __printnet_onboard__ | |
void printnet(cv::dnn::Net &net, int batch_size, int channels, int WINSIZE) { | |
cv::dnn::MatShape ms1 = { batch_size, channels, WINSIZE, WINSIZE }; | |
std::vector<cv::String> lnames = net.getLayerNames(); | |
for (size_t i=1; i<lnames.size()+1; i++) { // skip __NetInputLayer__ | |
cv::Ptr<cv::dnn::Layer> lyr = net.getLayer((unsigned)i); | |
std::vector<cv::dnn::MatShape> in,out; | |
net.getLayerShapes(ms1,i,in,out); | |
std::cout << format("%-38s %-13s", lyr->name.c_str(), lyr->type.c_str()); | |
for (auto j:in) std::cout << "i" << cv::Mat(j).t() << "\t"; | |
for (auto j:out) std::cout << "o" << cv::Mat(j).t() << "\t"; | |
for (auto b:lyr->blobs) { // what the net trains on, e.g. weights and bias | |
std::cout << "b[" << b.size[0]; | |
for (size_t d=1; d<b.dims; d++) std::cout << ", " << b.size[d]; | |
std::cout << "] "; | |
} | |
std::cout << std::endl; | |
} | |
} | |
#endif // __printnet_onboard__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment