提交 23d6c594 编写于 作者: D dangqingqing

add comments

上级 7c9b53c3
...@@ -284,6 +284,18 @@ class Parameters(object): ...@@ -284,6 +284,18 @@ class Parameters(object):
@staticmethod @staticmethod
def from_tar(f): def from_tar(f):
"""
Create a `Parameters` object from the given file. And
the `Parameters` only contains the parameters in this
file. It is adapted the parameters are same in the
defined network and the given file. For example, it
can be used in the inference.
:param f: the initialized model file.
:type f: tar file
:return: A Parameters object.
:rtype: Parameters.
"""
params = Parameters() params = Parameters()
tar = tarfile.TarFile(fileobj=f, mode='r') tar = tarfile.TarFile(fileobj=f, mode='r')
for finfo in tar: for finfo in tar:
...@@ -300,6 +312,15 @@ class Parameters(object): ...@@ -300,6 +312,15 @@ class Parameters(object):
return params return params
def init_from_tar(self, f): def init_from_tar(self, f):
"""
Different from `from_tar`, this interface can be used to
init partial network parameters from another saved model.
:param f: the initialized model file.
:type f: tar file
:return: Nothing.
"""
tar_param = Parameters.from_tar(f) tar_param = Parameters.from_tar(f)
for pname in tar_param.names(): for pname in tar_param.names():
if pname in self.names(): if pname in self.names():
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册