-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Conversation
@mxnet-label-bot add [Gluon, pr-awaiting-review] |
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.
Could you add a test? Also, what does the current string representation look like, for example for alexnet?
+1 on szha's comment |
Thanks for inputs @szha @eric-haibin-lin. Added an example in the PR description. Will add a test and submit shortly |
@szha @eric-haibin-lin added a test in test_import() of test_gluon.py |
python/mxnet/gluon/block.py
Outdated
@@ -1024,6 +1024,11 @@ def imports(symbol_file, input_names, param_file=None, ctx=None): | |||
ret.collect_params().load(param_file, ctx=ctx) | |||
return ret | |||
|
|||
def __repr__(self): | |||
s = '{name}(\n{modstr}\n)' | |||
modstr = '\n'.join(['{block}'.format(block=self.__dict__['_cached_graph'][-1])]) |
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.
why use __dict__
? or -1 index?
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.
would it be more useful to show also the input count and output count?
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.
corrected dict to self._cached_graph.
-1 index as the last element of cached_graph is the output. I could have used cached_graph[1], but did not want to hit index out of bounds (in case it ever happens).
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.
I think showing all layers like how HybridSequential prints, would be most useful, but not sure how to do that for Symbol API and SymbolBlock models.
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.
Printing the inner structure might be too complicated and also not readable, thus I suggested printing the count.
Why would cached_graph[1]
ever hit index out of bounds?
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.
something like this?
SymbolBlock(
<Symbol dense1_fwd>
)
Number of inputs: 1
Number of outputs: 1
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.
<Symbol dense1_fwd>: 1->1
?
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.
@szha thanks for the inputs. submitted after addressing the comments. Added an example of multiple outputs in the PR description
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 your contribution! LGTM
I think the test case Is too strict. We can use 'in' to test it.
@wkcn Do you mean lines[0] check? I did something similar to https://github.com/apache/incubator-mxnet/blob/a6a4fe188d4847a608952fb69ff68e7ab91c5050/tests/python/unittest/test_gluon.py#L237 |
* Add repr for SymbolBlock * Add a test * Correct self.cached_graph * Address review comments
* Add repr for SymbolBlock * Add a test * Correct self.cached_graph * Address review comments
* Add repr for SymbolBlock * Add a test * Correct self.cached_graph * Address review comments
Description
SymbolBlock uses
Block.__repr__
whenprint(SymbolBlock)
is executed. InBlock.__repr__
, data is printed only if it is of type Block. Adding a__repr__
to SymbolBlock class that prints the output symbol. This behavior is similar to printing pure Symbol API.Fixes #13616
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Executing
gives the output
Before
After change
Example with a model with more than one output:
Output:
Comments
@eric-haibin-lin @Ishitori