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

[MXNET-352] Document behavior of mx.initializer.Constant #10637

Merged
merged 7 commits into from
Jun 17, 2018

Conversation

ThomasDelteil
Copy link
Contributor

@ThomasDelteil ThomasDelteil commented Apr 22, 2018

Description

As I was looking for a way to initialize the value of my weights to a given specific value, I couldn't find any straightforward way to do that without hacking into the parameters and setting the value directly.
Turns out you can use the mx.initializer.Constant, even though the documentation stated that it can only accept scalar. If you give a NDArray of the right shape, you can initialize your weights using the Constant initializer, which is much cleaner than setting the data directly since you don't have to play around the names of the layers and parameters.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

@piiswrong
Copy link
Contributor

piiswrong commented Apr 22, 2018

Gluon specific tutorial shouldn't be put here. In gluon it's more convenient to use set_data.

@ThomasDelteil
Copy link
Contributor Author

There are several module API specific examples in this file, I can switch the example to a module one if you prefer.
However I have to say that I disagree that using set_data is more convenient. My opinion is that for a new user, the first place to go when wanting to initialize the weights of a layer to a specific value would be the weight_initializer parameter, rather than calling layer.collect_params()['dense0_weight'].set_data()

@szha szha requested review from piiswrong and removed request for szha May 21, 2018 22:30
@szha szha merged commit 11dd56a into apache:master Jun 17, 2018
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* document behavior of Constant

* Update initializer.py

* remove trailing whitespace

* Update initializer.py

* Update initializer.py

* Trigger build

* Trigger build
XinYao1994 pushed a commit to XinYao1994/incubator-mxnet that referenced this pull request Aug 29, 2018
* document behavior of Constant

* Update initializer.py

* remove trailing whitespace

* Update initializer.py

* Update initializer.py

* Trigger build

* Trigger build
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.

None yet

3 participants