未验证 提交 0c8f69c3 编写于 作者: Y yuyang18

Hide more APIs

上级 6eba4b32
......@@ -68,11 +68,11 @@ class LayerHelper(object):
@property
def param_attr(self):
return ParamAttr.to_attr(self.kwargs.get('param_attr', None))
return ParamAttr._to_attr(self.kwargs.get('param_attr', None))
@property
def bias_attr(self):
return ParamAttr.to_attr(self.kwargs.get('bias_attr', None))
return ParamAttr._to_attr(self.kwargs.get('bias_attr', None))
def multiple_param_attr(self, length):
param_attr = self.param_attr
......@@ -262,11 +262,11 @@ class LayerHelper(object):
g_param = self.startup_program.global_block().create_parameter(
dtype=dtype,
shape=g_param_shape,
**g_param_attr.to_kwargs(with_initializer=False))
**g_param_attr._to_kwargs(with_initializer=False))
v_param = self.startup_program.global_block().create_parameter(
dtype=dtype,
shape=v_param_shape,
**v_param_attr.to_kwargs(with_initializer=True))
**v_param_attr._to_kwargs(with_initializer=True))
__norm_except_dim(
x=v_param,
out=g_param,
......@@ -275,9 +275,9 @@ class LayerHelper(object):
# Add weight normalization to main_program
g_param = self.main_program.global_block().create_parameter(
dtype=dtype, shape=g_param_shape, **g_param_attr.to_kwargs())
dtype=dtype, shape=g_param_shape, **g_param_attr._to_kwargs())
v_param = self.main_program.global_block().create_parameter(
dtype=dtype, shape=v_param_shape, **v_param_attr.to_kwargs())
dtype=dtype, shape=v_param_shape, **v_param_attr._to_kwargs())
w_param = __weight_normalize(g_param, v_param, dim=attr.dim)
return w_param
......@@ -296,11 +296,11 @@ class LayerHelper(object):
if default_initializer is None and attr.initializer is None:
if is_bias:
attr.set_default_bias_initializer()
attr._set_default_bias_initializer()
else:
attr.set_default_param_initializer()
attr._set_default_param_initializer()
else:
attr.set_default_initializer(default_initializer)
attr._set_default_initializer(default_initializer)
# If weight normalization is set, insert extra parameters and ops.
# Refer to https://arxiv.org/pdf/1602.07868.pdf
......@@ -310,9 +310,9 @@ class LayerHelper(object):
return param
self.startup_program.global_block().create_parameter(
dtype=dtype, shape=shape, **attr.to_kwargs(with_initializer=True))
dtype=dtype, shape=shape, **attr._to_kwargs(with_initializer=True))
return self.main_program.global_block().create_parameter(
dtype=dtype, shape=shape, **attr.to_kwargs())
dtype=dtype, shape=shape, **attr._to_kwargs())
def get_parameter(self, name):
param = self.main_program.global_block().var(name)
......
......@@ -67,7 +67,7 @@ class ParamAttr(object):
self.gradient_clip = gradient_clip
self.model_average = do_model_average
def set_default_initializer(self, initializer):
def _set_default_initializer(self, initializer):
"""
Set the default initializer, the initializer should be Constant,
Uniform, Normal, Xavier, MSRA.
......@@ -88,7 +88,7 @@ class ParamAttr(object):
self.initializer = initializer
def set_default_param_initializer(self):
def _set_default_param_initializer(self):
"""
Set the default initializer for the parameter with Xavier.
......@@ -98,9 +98,9 @@ class ParamAttr(object):
Returns:
None.
"""
self.set_default_initializer(Xavier())
self._set_default_initializer(Xavier())
def set_default_bias_initializer(self):
def _set_default_bias_initializer(self):
"""
Set the default initializer for the bias with Constant(0.0).
......@@ -110,10 +110,10 @@ class ParamAttr(object):
Returns:
None.
"""
self.set_default_initializer(Constant(0.0))
self._set_default_initializer(Constant(0.0))
@staticmethod
def to_attr(arg):
def _to_attr(arg):
"""
Create ParamAttr[s].
......@@ -131,7 +131,7 @@ class ParamAttr(object):
if arg is None:
return ParamAttr()
elif isinstance(arg, list) or isinstance(arg, tuple):
return [ParamAttr.to_attr(a) for a in arg]
return [ParamAttr._to_attr(a) for a in arg]
elif isinstance(arg, ParamAttr):
return arg
elif isinstance(arg, str) or isinstance(arg, unicode):
......@@ -141,11 +141,11 @@ class ParamAttr(object):
elif isinstance(arg, WeightDecayRegularizer):
return ParamAttr(regularizer=arg)
elif isinstance(arg, bool):
return ParamAttr.to_attr(None) if arg else False
return ParamAttr._to_attr(None) if arg else False
else:
raise TypeError("{0} cast to ParamAttr".format(type(arg)))
def to_kwargs(self, with_initializer=False):
def _to_kwargs(self, with_initializer=False):
"""
Returns the attributes of this parameter.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册