Skip to content

Deep networks visualization - #14255

Merged
alalek merged 6 commits into
opencv:3.4from
l-bat:networks_visualization
Apr 12, 2019
Merged

alalek merged 6 commits into
opencv:3.4from
l-bat:networks_visualization

Conversation

@l-bat

@l-bat l-bat commented Apr 4, 2019

Copy link
Copy Markdown
Contributor

Fixes #9452

Comment thread modules/dnn/include/opencv2/dnn/dnn.hpp Outdated
* @param path path to output file with .dot extension
* To see correct backend, target and fusion run after forward().
*/
void dumpNet(String path);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing purposes it is better to dump into string as primary functionality.

Storing into files can be an additional method.


String

Should be const String& for input parameters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread modules/dnn/src/dnn.cpp Outdated
void Net::dumpNet(String path) {
CV_Assert(!empty());

std::ofstream file(path);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To dump into string use:

std::ostringstream out;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread modules/dnn/include/opencv2/dnn/dnn.hpp Outdated
* @returns String with structure, hyperparameters, backend, target and fusion
* To see correct backend, target and fusion run after forward().
*/
CV_WRAP String dumpNet();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method dump is a cv::Net's method. So cv::Net::dumpNet. I think that we can name them just dump() and dumpToFile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread modules/dnn/src/dnn.cpp Outdated
}
if (lp.has("pad")) {
DictValue pad = lp.get("pad");
out << "pad (HxW): " << pad << "x" << pad << "x" << pad << "x" << pad << "\\l";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pad (LxTxRxB)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@dkurt dkurt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l-bat, The graphs looks fascinating, thank you!
I wanted to ask you to experiment with adding layer's output shapes. Just numbers delimited by "x" right before backend/target line. In this way we can emit num_output entry for convolutions.

Comment thread modules/dnn/src/dnn.cpp Outdated
}
}
if (!it->second.outputBlobs.empty())
out << "output shapes: " << it->second.outputBlobs[0].size << "\\l";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's it's better to name it just output:.

Please also iterate by it->second.outputBlobs[0].size and print dimensions delimited by "x". For now it adds extra whitespaces.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix name, added whitespaces everywhere " x ".

Comment thread modules/dnn/src/dnn.cpp Outdated
out << (!it->second.backendNodes[prefBackend].empty() ? backend : "OCV/");
int colorId = 0;
switch (it->second.layerInstance->preferableTarget) {
case DNN_TARGET_CPU: out << "CPU\\n"; colorId = (backend == "OCV/") ? 0 : 5; break;

@dkurt dkurt Apr 11, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check prefBackend instead because current approach doesn't work:

image

From

python ../samples/dnn/object_detection.py yolo --input example.jpg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread modules/dnn/src/dnn.cpp Outdated
int colorId = 0;
switch (it->second.layerInstance->preferableTarget) {
case DNN_TARGET_CPU: out << "CPU\\n"; colorId = (layerBackend.empty() ||
layerBackend->backendId == DNN_BACKEND_OPENCV) ? 0 : 5; break;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can check just layerBackend.empty() because OpenCV's implementation is not wrapped as a BackendNode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l-bat, Have you pushed the changes?

@l-bat
l-bat force-pushed the networks_visualization branch 2 times, most recently from 3bd5259 to c50de63 Compare April 11, 2019 09:44

@dkurt dkurt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks cool! Thanks!

@alalek

alalek commented Apr 12, 2019

Copy link
Copy Markdown
Member

It would be nice to add some test case for that.

  • load some model (AlexNet?)
  • check that output is not empty
  • check that some layer name is dumped
  • check that some "fused" layer is not showed

@alalek
alalek merged commit 60a841c into opencv:3.4 Apr 12, 2019
@alalek alalek mentioned this pull request Apr 13, 2019
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
* Add networks visualization

* Disable CXX11

* Fixed multy inputs support

* Added output shapes

* Added color for DLIE/CPU

* Fixed graph colors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants