mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
docs(tutorial): 添加新模型注册教程
This commit is contained in:
parent
949a95986c
commit
e6f58e7bc7
@ -7,6 +7,7 @@ FunASR has open-sourced a large number of pre-trained models on industrial data.
|
||||
<a href="#Inference"> Model Inference </a>
|
||||
|<a href="#Training"> Model Training and Testing </a>
|
||||
|<a href="#Export"> Model Export and Testing </a>
|
||||
|<a href="#new-model-registration-tutorial"> New Model Registration Tutorial </a>
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
@ -424,3 +425,59 @@ print(result)
|
||||
```
|
||||
|
||||
More examples ref to [demo](https://github.com/alibaba-damo-academy/FunASR/tree/main/runtime/python/onnxruntime)
|
||||
|
||||
|
||||
<a name="new-model-registration-tutorial"></a>
|
||||
## 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)
|
||||
Loading…
Reference in New Issue
Block a user