lutzroeder / netron

Visualizer for neural network, deep learning and machine learning models
https://netron.app
MIT License
27.76k stars 2.76k forks source link

Graph visualization unnecessarily wide #864

Open leosh64 opened 2 years ago

leosh64 commented 2 years ago

For some networks, the visualization of the graph becomes unnecessarily wide. This makes it difficult to understand connections when zoomed in:

image

Throughout the model, there is no section that would justify such a wide visualization.

Below some screenshots when zoomed out:

image

The same issue (unnecessarily high) occurs in horizontal mode:

image

KarelPeeters commented 2 years ago

I was just about to report this as well!

For example, yolov5n.onnx looks like this for me:

image

This width is somewhat justifiable since the final layers of the model do indeed need the width, but there is no reason for the connections that go from a conv to the following mul to go all the way to the right and back.

lutzroeder commented 2 years ago

@leosh64 @KarelPeeters @AlessandroMondin can you investigate this and suggest a fix.

dagrejs/dagre#239 has some context. The paper describing the algorithm can be found here and the code here.

lutzroeder commented 2 years ago

yolov5n.onnx.zip

AlessandroMondin commented 2 years ago

Hello all, any news on this bug? I am facing the same issue as weel:

Screenshot 2022-08-31 at 12 56 39
beru commented 1 year ago

It seems the second pass (link) of the horizontalCompaction function is related to this issue.

Tested with yolov5n.onnx.

With the second pass Without the second pass
image image

So my bet is everyone should edit the code to adjust the view when needed.

seanshpark commented 4 months ago

There was a change to make unnecessary wide edges become narrow. I assume there are still wide lines, and if so, please share the model to this issue.

beru commented 3 months ago

@seanshpark

I assume there are still wide lines, and if so, please share the model to this issue.

I've just encountered the issue with EfficientDet-d0.onnx file in EfficientDet-d0.onnx.zip so just letting you know it.

The file is listed in test/models.json. link

screenshot ![image](https://github.com/lutzroeder/netron/assets/1131125/e580ae5d-ee14-47e2-a5fc-2a6c2968e643)
beru commented 1 month ago

I still haven't understood the root cause of this problem but applying the change somehow resolved it.

Before: ![image](https://github.com/user-attachments/assets/5ec56c22-34e0-4975-bc7d-a5c259c2240e) After: ![image](https://github.com/user-attachments/assets/7d5fc646-ca35-4682-a5fd-40c0ccbbf958)
lutzroeder commented 1 month ago

@beru thank you for investigating. I tried the change on a few files and noticed it changes the symmetry of squeezenet1.1.onnx.

beru commented 1 month ago

@lutzroeder

I tried the change on a few files and noticed it changes the symmetry of squeezenet1.1.onnx.

Thank you for checking it. And... could you also please check this change? link Applying the change yields preferrable result with the EfficientDet-d0.onnx model.

Before: ![image](https://github.com/user-attachments/assets/5ec56c22-34e0-4975-bc7d-a5c259c2240e) After: ![image](https://github.com/user-attachments/assets/535fa6b3-72b7-4ac3-8e28-e525518a57ed)

I've debugged around horizontalCompaction function for a few days to find out why the problem appears on xss['dl']. With the change, graphs built by buildBlockGraph function contain less edges so it could be that clustering has improved? It's hard (for me) to explain relations of how the change improves layouting results due to lack of understanding.

Edited: This change is more easier to understand.