Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
528bf72c
Unverified
Commit
528bf72c
authored
Apr 21, 2019
by
Kai Chen
Committed by
GitHub
Apr 21, 2019
Browse files
Merge pull request #61 from hellock/weight-init
Add caffe2_xavier_init()
parents
944da49f
5e3d09bc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
mmcv/cnn/__init__.py
mmcv/cnn/__init__.py
+2
-2
mmcv/cnn/weight_init.py
mmcv/cnn/weight_init.py
+14
-2
No files found.
mmcv/cnn/__init__.py
View file @
528bf72c
...
...
@@ -2,10 +2,10 @@ from .alexnet import AlexNet
from
.vgg
import
VGG
,
make_vgg_layer
from
.resnet
import
ResNet
,
make_res_layer
from
.weight_init
import
(
constant_init
,
xavier_init
,
normal_init
,
uniform_init
,
kaiming_init
)
uniform_init
,
kaiming_init
,
caffe2_xavier_init
)
__all__
=
[
'AlexNet'
,
'VGG'
,
'make_vgg_layer'
,
'ResNet'
,
'make_res_layer'
,
'constant_init'
,
'xavier_init'
,
'normal_init'
,
'uniform_init'
,
'kaiming_init'
'kaiming_init'
,
'caffe2_xavier_init'
]
mmcv/cnn/weight_init.py
View file @
528bf72c
...
...
@@ -30,6 +30,7 @@ def uniform_init(module, a=0, b=1, bias=0):
def
kaiming_init
(
module
,
a
=
0
,
mode
=
'fan_out'
,
nonlinearity
=
'relu'
,
bias
=
0
,
...
...
@@ -37,9 +38,20 @@ def kaiming_init(module,
assert
distribution
in
[
'uniform'
,
'normal'
]
if
distribution
==
'uniform'
:
nn
.
init
.
kaiming_uniform_
(
module
.
weight
,
mode
=
mode
,
nonlinearity
=
nonlinearity
)
module
.
weight
,
a
=
a
,
mode
=
mode
,
nonlinearity
=
nonlinearity
)
else
:
nn
.
init
.
kaiming_normal_
(
module
.
weight
,
mode
=
mode
,
nonlinearity
=
nonlinearity
)
module
.
weight
,
a
=
a
,
mode
=
mode
,
nonlinearity
=
nonlinearity
)
if
hasattr
(
module
,
'bias'
)
and
module
.
bias
is
not
None
:
nn
.
init
.
constant_
(
module
.
bias
,
bias
)
def
caffe2_xavier_init
(
module
,
bias
=
0
):
# `XavierFill` in Caffe2 corresponds to `kaiming_uniform_` in PyTorch
# Acknowledgment to FAIR's internal code
kaiming_init
(
module
,
a
=
1
,
mode
=
'fan_in'
,
nonlinearity
=
'leaky_relu'
,
distribution
=
'uniform'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment