add load_dygraph_pretrain_from_url function

pull/742/head
cuicheng01 2021-05-28 10:55:48 +08:00 committed by GitHub
parent 5671f9d9bb
commit 31e59dfa1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import tempfile
import paddle
from paddle.static import load_program_state
from paddle.utils.download import get_weights_path_from_url
from ppcls.utils import logger
@ -70,6 +71,14 @@ def load_dygraph_pretrain(model, path=None, load_static_weights=False):
return
def load_dygraph_pretrain_from_url(model, pretrained_url, use_ssld, load_static_weights=False):
if use_ssld:
pretrained_url = pretrained_url.replace("_pretrained", "_ssld_pretrained")
local_weight_path = get_weights_path_from_url(pretrained_url).replace(".pdparams", "")
load_dygraph_pretrain(model, path=local_weight_path, load_static_weights=load_static_weights)
return
def load_distillation_model(model, pretrained_model, load_static_weights):
logger.info("In distillation mode, teacher model will be "
"loaded firstly before student model.")