Skip to content
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

模型权重初始化并非小随机数,使用的是kaiming初始化 #5

Open
pascal1129 opened this issue Dec 26, 2018 · 1 comment

Comments

@pascal1129
Copy link

pascal1129 commented Dec 26, 2018

0.0.4版本第26页处,您写道:

其实,在创建网络实例的过程中, 一旦调用 nn.Conv2d 的时候就会有对权值进行初始化
Conv2d 是继承_ConvNd,初始化赋值是在_ConvNd当中,这些值是创建一个 Tensor 时得到的,是一些很小的随机数。

实际上,并非如此,在pytorch源码中使用的是kaiming初始化,也就是说,pytorch的模型权值初始化不是很小的随机数。

参见:
https://github.com/pytorch/pytorch/blob/6e453e56f991d43ff9d0eac715020b7ef877ca77/torch/nn/modules/conv.py#L43

https://github.com/pytorch/pytorch/blob/6e453e56f991d43ff9d0eac715020b7ef877ca77/torch/nn/modules/conv.py#L45

@pascal1129 pascal1129 changed the title 模型权重初始化介绍部分有一处错误 模型权重初始化并非小随机数,使用的是kaiming初始化 Dec 26, 2018
@TingsongYu
Copy link
Owner

您说的正确,我那里确实弄错了,默认初始值的设置是在_ConvNd类中的
--> self.reset_parameters()
---> def reset_parameters(self)
---> self.weight.data.uniform_(-stdv, stdv)

不过我发现我这个版本的pytorch采用的是均匀分布,不知从哪个版本之后修改成了kaiming初始化。如果以后有需要,就从 torch/nn/modules/conv.py 中 reset_parameters(self)函数去查找。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants