add more act w.o. inplace opt (#329)

pull/342/head
Jerry Jiarui XU 2020-06-10 15:42:09 +08:00 committed by GitHub
parent f5be29b2b0
commit 2aa7712cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -140,7 +140,7 @@ class ConvModule(nn.Module):
if self.with_activation:
act_cfg_ = act_cfg.copy()
# nn.Tanh has no 'inplace' argument
if act_cfg_['type'] != 'Tanh':
if act_cfg_['type'] not in ['Tanh', 'PReLU', 'Sigmoid']:
act_cfg_.setdefault('inplace', inplace)
self.activate = build_activation_layer(act_cfg_)

View File

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