-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Bug fixes in plot_model with nested models.
#21243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21243 +/- ##
=======================================
Coverage 82.60% 82.61%
=======================================
Files 564 564
Lines 54501 54581 +80
Branches 8469 8481 +12
=======================================
+ Hits 45020 45091 +71
- Misses 7397 7403 +6
- Partials 2084 2087 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
fchollet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
ImportError: You must install pydot (
pip install pydot) for model_to_dot to work.
If we want these tests on CI (questionable) we need to add pydot to requirements.
|
There is currently a manually-run integration test for plots. It's manually run because the idea is to manually inspect the generated image files after running it. |
Oh, I didn't realize that. |
Hmm... it's easy enough to install. But let me try something, maybe I should just mock it since we're not rendering anyway. It does feel wasteful to run these every time for every backend, but then, when else would we run them? |
When we modify the plotting logic -- I feel like this strictly requires a step of manually inspecting the visual effect of a change across all kinds of models (which is what the current integration test seeks to achieve). It's basically impossible to catch issues without actually looking at the images that come out We rarely every modify this logic so it seems fine |
I'll move the tests I created to the integration test file.
Actually, the unit tests get you most of the way there (the existing ones and the ones I added). It verifies that at least the topology is correct: existence of nodes, nesting of nodes in subgraphs, edges between nodes. In fact, I found a bug that I didn't notice visually. |
There were several issues with `keras.utils.plot_model()` / `keras.utils.model_to_dot()` when rendering nested models with `expand_nested=True`: - Sequential models were not expanded - Edges going into nested models would always connect to the first box in the subgraph, which is incorrect because: - Functional models can have multiple inputs and the edge needs to point to the correct input - The destination of the edge can be further nested sub-models like Sequential sub-models - Edges going out of nested models would always connect from the last box in the subgraph, which is incorrect because: - Functional models can have multiple outputs and the edge needs to come from the correct layer - The source of the edge can be further nested in sub-models since there is no "output" box This adds to the integration tests. In particular, it augments the way the topology is verified: - it provides detailed message for dangling edges - it can inspected nested subgraphs - it verifies there are no extra edges that the ones expected - it can verify splits in the graph Visual tests: https://colab.research.google.com/gist/hertschuh/fb7dfdbf4fb31139e33e750ab10aaad4/plot_model-testing.ipynb Fixes keras-team#21119
a59e204 to
b97b5ab
Compare
|
@fchollet ready for review. |
fchollet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
|
Hey @hertschuh ! Thank you for this PR. I have a question. Can you look this gist? Is this behavior intended? keras.layers.Input(shape=(30,),dtype='float32')into this keras.layers.Input(tensor=encoder.outputs[0])IMO, the last plot is correct. |
Correct, they should look the same. That's a bug. |
There were several issues with
keras.utils.plot_model()/keras.utils.model_to_dot()when rendering nested models withexpand_nested=True:This adds unit tests, which check that the graph has the expected topology (correct nodes and edges).
Visual tests: https://colab.research.google.com/gist/hertschuh/fb7dfdbf4fb31139e33e750ab10aaad4/plot_model-testing.ipynb
Fixes #21119