From bce72487636cf84c463381096216e995deb1920d Mon Sep 17 00:00:00 2001
From: hnluo <haoneng.lhn@alibaba-inc.com>
Date: 星期四, 10 八月 2023 12:38:55 +0800
Subject: [PATCH] add mossformer code
---
funasr/build_utils/build_model_from_file.py | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/funasr/build_utils/build_model_from_file.py b/funasr/build_utils/build_model_from_file.py
index 8fd4e46..6130e71 100644
--- a/funasr/build_utils/build_model_from_file.py
+++ b/funasr/build_utils/build_model_from_file.py
@@ -6,11 +6,22 @@
import torch
import yaml
-from typeguard import check_argument_types
from funasr.build_utils.build_model import build_model
from funasr.models.base_model import FunASRModel
+
+def load_checkpoint(checkpoint_path, use_cuda=1):
+ if use_cuda:
+ checkpoint = torch.load(checkpoint_path)
+ else:
+ checkpoint = torch.load(
+ checkpoint_path, map_location=lambda storage, loc: storage)
+ return checkpoint
+
+def reload_ss_for_eval(model, checkpoint_path, use_cuda=False):
+ checkpoint = load_checkpoint(checkpoint_path, use_cuda)
+ model.load_state_dict(checkpoint['model'], strict=False)
def build_model_from_file(
config_file: Union[Path, str] = None,
@@ -30,7 +41,6 @@
device: Device type, "cpu", "cuda", or "cuda:N".
"""
- assert check_argument_types()
if config_file is None:
assert model_file is not None, (
"The argument 'model_file' must be provided "
@@ -72,6 +82,9 @@
model.load_state_dict(model_dict)
else:
model_dict = torch.load(model_file, map_location=device)
+ if task_name == 'ss':
+ reload_ss_for_eval(model, model_file, use_cuda=True)
+ logging.info("model is loaded from path: {}".format(model_file))
if task_name == "diar" and mode == "sond":
model_dict = fileter_model_dict(model_dict, model.state_dict())
if task_name == "vad":
--
Gitblit v1.9.1