From 6ecf08b17395944febedd9867c48000a9d7a9f9f Mon Sep 17 00:00:00 2001 From: guosheng Date: Tue, 12 Dec 2017 19:39:07 +0800 Subject: [PATCH] Enhance init_from_tar to support indicating parameters excluded from the initialized model --- python/paddle/v2/parameters.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/paddle/v2/parameters.py b/python/paddle/v2/parameters.py index bd97dc119..0dd7d38d8 100644 --- a/python/paddle/v2/parameters.py +++ b/python/paddle/v2/parameters.py @@ -383,19 +383,21 @@ class Parameters(object): params.deserialize(param_name, f) return params - def init_from_tar(self, f): + def init_from_tar(self, f, exclude_params=[]): """ 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 + :param exclude_params: the names of parameters that shouldn't be initialized from the model file. + :type exclude_params: list of strings :return: Nothing. """ tar_param = Parameters.from_tar(f) for pname in tar_param.names(): - if pname in self.names(): + if pname in self.names() and pname not in exclude_params: self.set(pname, tar_param.get(pname)) -- GitLab