fix building ConvModule with Tanh activation (#309)

* fix: tanh has not inplace

* feat: add ConvModule with Tanh
pull/313/head
Harry 2020-06-01 21:26:51 +08:00 committed by GitHub
parent 213156cebb
commit efecf7d1fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -139,7 +139,9 @@ class ConvModule(nn.Module):
# build activation layer
if self.with_activation:
act_cfg_ = act_cfg.copy()
act_cfg_.setdefault('inplace', inplace)
# nn.Tanh has no 'inplace' argument
if act_cfg_['type'] != 'Tanh':
act_cfg_.setdefault('inplace', inplace)
self.activate = build_activation_layer(act_cfg_)
# Use msra init by default

View File

@ -117,6 +117,12 @@ def test_conv_module():
output = conv(x)
assert output.shape == (1, 8, 256, 256)
# tanh
conv = ConvModule(3, 8, 3, padding=1, act_cfg=dict(type='Tanh'))
assert isinstance(conv.activate, nn.Tanh)
output = conv(x)
assert output.shape == (1, 8, 256, 256)
def test_bias():
# bias: auto, without norm