-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Added support for new pydot versions to fix find_graphviz error #6398
Conversation
keras/utils/vis_utils.py
Outdated
try: | ||
if hasattr(pydot, 'find_graphviz'): | ||
if not pydot.find_graphviz(): | ||
raise ImportError() |
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.
This needs an error message explaining what went wrong and how to fix it (like below).
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.
After experimenting more it seems like this isn't even needed anymore, so I removed it.
keras/utils/vis_utils.py
Outdated
if not pydot.find_graphviz(): | ||
raise ImportError() | ||
else: | ||
pydot.Dot.create(pydot.Dot()) |
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.
What is this statement for? A comment would be helpful.
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.
Done!
keras/utils/vis_utils.py
Outdated
raise ImportError() | ||
else: | ||
pydot.Dot.create(pydot.Dot()) | ||
except: |
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.
No catch-all exceptions. You should catch a specific class.
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.
The problem with this is that pydot raises a generic exception if it can't find dot, so there is no specific class. One alternative might be to not checking the dot installation at all, but that produces a less helpful error message that doesn't mention graphviz specifically.
keras/utils/vis_utils.py
Outdated
try: | ||
# Attempt to create an image of a blank graph to check the pydot/graphviz installation. | ||
pydot.Dot.create(pydot.Dot()) | ||
except: |
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.
Again: you should only except a specific Exception class.
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.
There is not a specific Exception class in this situation. pydot raises a generic Exception (pydot source).
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.
Oh wow... In this case let's catch the exception, add a comment on why we use Exception
, and check that the exception message is what we expect. raise
otherwise.
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.
Actually, never mind what I said, it will be safer to just catch Exception
. Do add a comment on why we do this.
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.
For what it's worth I will probably also try submit a pull request to pyplot to raise a more appropriate exception.
Please see #5313 (comment). |
I was having difficulties with the
keras.utils.plot_model
function, specifically that pydot no longer supports thefind_graphviz
function, and installingpydot-ng
instead does not seem to fix it. This pull request should solve issue #3210.