未验证 提交 afbaee56 编写于 作者: L lvmengsi 提交者: GitHub

Revert in (#3836)

* revert_in
上级 d8b44efc
...@@ -64,6 +64,12 @@ def norm_layer(input, ...@@ -64,6 +64,12 @@ def norm_layer(input,
moving_variance_name=name + '_var') moving_variance_name=name + '_var')
elif norm_type == 'instance_norm': elif norm_type == 'instance_norm':
helper = fluid.layer_helper.LayerHelper("instance_norm", **locals())
dtype = helper.input_dtype()
epsilon = 1e-5
mean = fluid.layers.reduce_mean(input, dim=[2, 3], keep_dim=True)
var = fluid.layers.reduce_mean(
fluid.layers.square(input - mean), dim=[2, 3], keep_dim=True)
if name is not None: if name is not None:
scale_name = name + "_scale" scale_name = name + "_scale"
offset_name = name + "_offset" offset_name = name + "_offset"
...@@ -85,8 +91,15 @@ def norm_layer(input, ...@@ -85,8 +91,15 @@ def norm_layer(input,
name=offset_name, name=offset_name,
initializer=fluid.initializer.Constant(0.0), initializer=fluid.initializer.Constant(0.0),
trainable=False) trainable=False)
return fluid.layers.instance_norm( scale = helper.create_parameter(
input, param_attr=scale_param, bias_attr=offset_param) attr=scale_param, shape=input.shape[1:2], dtype=dtype)
offset = helper.create_parameter(
attr=offset_param, shape=input.shape[1:2], dtype=dtype)
tmp = fluid.layers.elementwise_mul(x=(input - mean), y=scale, axis=1)
tmp = tmp / fluid.layers.sqrt(var + epsilon)
tmp = fluid.layers.elementwise_add(tmp, offset, axis=1)
return tmp
else: else:
raise NotImplementedError("norm type: [%s] is not support" % norm_type) raise NotImplementedError("norm type: [%s] is not support" % norm_type)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册