From e6f58e7bc74a2dc4b371a4045b1a8d86e39333bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=B8=E9=9B=81?= Date: Thu, 31 Oct 2024 18:38:05 +0800 Subject: [PATCH] =?UTF-8?q?docs(tutorial):=20=E6=B7=BB=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=B3=A8=E5=86=8C=E6=95=99=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tutorial/README.md | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/docs/tutorial/README.md b/docs/tutorial/README.md index 9b68e73c6..590c6256f 100644 --- a/docs/tutorial/README.md +++ b/docs/tutorial/README.md @@ -7,6 +7,7 @@ FunASR has open-sourced a large number of pre-trained models on industrial data. Model Inference Model Training and Testing Model Export and Testing +| New Model Registration Tutorial @@ -424,3 +425,59 @@ print(result) ``` More examples ref to [demo](https://github.com/alibaba-damo-academy/FunASR/tree/main/runtime/python/onnxruntime) + + + +## New Model Registration Tutorial + +### Viewing the Registry + +```plaintext +from funasr.register import tables + +tables.print() +``` + +Supports viewing the registry of a specified type: `tables.print("model")` + +### Registering Models + +```python +from funasr.register import tables + +@tables.register("model_classes", "SenseVoiceSmall") +class SenseVoiceSmall(nn.Module): + def __init__(*args, **kwargs): + ... + + def forward( + self, + **kwargs, + ): + + def inference( + self, + data_in, + data_lengths=None, + key: list = None, + tokenizer=None, + frontend=None, + **kwargs, + ): + ... + +``` + +Add `@tables.register("model_classes","SenseVoiceSmall")` before the class name that needs to be registered to complete the registration. The class needs to implement the methods: __init__, forward, and inference. + +Complete code: [https://github.com/modelscope/FunASR/blob/main/funasr/models/sense_voice/model.py#L443](https://github.com/modelscope/FunASR/blob/main/funasr/models/sense_voice/model.py#L443) + +After registration, specify the newly registered model in config.yaml to define the model + +```python +model: SenseVoiceSmall +model_conf: + ... +``` + +[More detailed tutorial documents](https://github.com/modelscope/FunASR/blob/main/docs/tutorial/Tables_zh.md) \ No newline at end of file