Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

fix print_summary bug and add groups of convolution #9492

Merged
merged 8 commits into from
Feb 19, 2018

Conversation

chinakook
Copy link
Contributor

@chinakook chinakook commented Jan 19, 2018

Description

  1. Bug fixed: invalid literal for int() with base 10: 'True'
  2. Convolution param number calculation now support channel group. We will get right param number when calculating CNN with group conv such as Mobilenet, Shufflenet and Xception.

Checklist

Essentials

  • Passed code style checking (make lint)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

1. fix "int(node["attrs"]["no_bias"])" bug
2. add groups of convolution param calculation
num_group = int(node["attrs"]["num_group"]) if \
("num_group" in node["attrs"]) else 1
cur_param = (pre_filter * int(node["attrs"]["num_filter"])) \
// num_group
Copy link
Member

Choose a reason for hiding this comment

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

the outer parentheses are not necessary and make it hard to read. would you clean it up?

for k in _str2tuple(node["attrs"]["kernel"]):
cur_param *= int(k)
cur_param += int(node["attrs"]["num_filter"])
elif op == 'FullyConnected':
if ("no_bias" in node["attrs"]) and int(node["attrs"]["no_bias"]):
if ("no_bias" in node["attrs"]) and node["attrs"]["no_bias"] == 'True':
Copy link
Member

Choose a reason for hiding this comment

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

if bool_str == 'True' -> if bool(bool_str)

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure about this?
bool("False") is True

Copy link
Member

Choose a reason for hiding this comment

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

you're right. @chinakook sorry for the misleading comment.
@piiswrong BTW do you happen to know why we are not using json's built-in boolean type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think i can replace bool(bool_str) with built-in function eval(bool_str).

Copy link
Member

Choose a reason for hiding this comment

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

That would create an injection point, since the files may not be trusted. (e.g. "no_bias": "import shutil; shutil.rmtree('/')")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Then use

node["attrs"]["no_bias"] == 'True' 

back?

Copy link
Member

Choose a reason for hiding this comment

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

yes

Copy link
Member

@szha szha Feb 8, 2018

Choose a reason for hiding this comment

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

The json dump should have made booleans without the parenthesis so that the json's type is used, i.e.

"attrs": {
  "flatten": "True",
  "no_bias": "False",
  "num_hidden": "1000"
}
# should have been
"attrs": {
  "flatten": True,
  "no_bias": False,
  "num_hidden": 1000
}

@piiswrong would it be OK to change json export to properly use json boolean?

Copy link
Contributor

Choose a reason for hiding this comment

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

no. there is compatibility issue

@chinakook
Copy link
Contributor Author

It' done.

Copy link
Member

@szha szha left a comment

Choose a reason for hiding this comment

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

sorry for the delay. one last change request

cur_param = pre_filter * int(node["attrs"]["num_filter"])
if "no_bias" in node["attrs"] and node["attrs"]["no_bias"] == 'True':
num_group = int(node["attrs"]["num_group"]) if \
"num_group" in node["attrs"] else 1
Copy link
Member

Choose a reason for hiding this comment

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

int(node['attrs'].get('num_group', '1')). same below.

Copy link
Member

Choose a reason for hiding this comment

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

dict.get handles default value for missing value so the trailing if is no longer necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@piiswrong piiswrong merged commit f14b2eb into apache:master Feb 19, 2018
@marcoabreu
Copy link
Contributor

Wait, in how far does this have test coverage?

rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* fix print_summary bug and add groups of convolution

1. fix "int(node["attrs"]["no_bias"])" bug
2. add groups of convolution param calculation

* Update visualization.py

lint

* Update visualization.py

* Update visualization.py

* Update visualization.py

* Update visualization.py

* Update visualization.py

* Update visualization.py
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* fix print_summary bug and add groups of convolution

1. fix "int(node["attrs"]["no_bias"])" bug
2. add groups of convolution param calculation

* Update visualization.py

lint

* Update visualization.py

* Update visualization.py

* Update visualization.py

* Update visualization.py

* Update visualization.py

* Update visualization.py
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants