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

Hide more APIs

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