Skip to content

Commit c606ef5

Browse files
committed
Update export-onnx.py
1 parent d922766 commit c606ef5

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

egs/wenetspeech/ASR/pruned_transducer_stateless2/export-onnx.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
2. Export the model to ONNX
2929
3030
./pruned_transducer_stateless2/export-onnx.py \
31-
--lang-dir $repo/data/lang_char \
31+
--tokens $repo/data/lang_char/tokens.txt \
3232
--epoch 99 \
3333
--avg 1 \
3434
--exp-dir $repo/exp
@@ -48,6 +48,7 @@
4848
from pathlib import Path
4949
from typing import Dict, Tuple
5050

51+
import k2
5152
import onnx
5253
import torch
5354
import torch.nn as nn
@@ -57,14 +58,8 @@
5758
from scaling_converter import convert_scaled_to_non_scaled
5859
from train import get_params, get_transducer_model
5960

60-
from icefall.checkpoint import (
61-
average_checkpoints,
62-
average_checkpoints_with_averaged_model,
63-
find_checkpoints,
64-
load_checkpoint,
65-
)
66-
from icefall.lexicon import Lexicon
67-
from icefall.utils import setup_logger, str2bool
61+
from icefall.checkpoint import average_checkpoints, load_checkpoint
62+
from icefall.utils import num_tokens, setup_logger, str2bool
6863

6964

7065
def get_parser():
@@ -110,10 +105,10 @@ def get_parser():
110105
)
111106

112107
parser.add_argument(
113-
"--lang-dir",
108+
"--tokens",
114109
type=str,
115-
default="data/lang_char",
116-
help="The lang dir",
110+
default="data/lang_char/tokens.txt",
111+
help="Path to the tokens.txt",
117112
)
118113

119114
parser.add_argument(
@@ -397,9 +392,9 @@ def main():
397392

398393
logging.info(f"device: {device}")
399394

400-
lexicon = Lexicon(params.lang_dir)
401-
params.blank_id = 0
402-
params.vocab_size = max(lexicon.tokens) + 1
395+
token_table = k2.SymbolTable.from_file(params.tokens)
396+
params.blank_id = token_table["<blk>"]
397+
params.vocab_size = num_tokens(token_table) + 1
403398

404399
logging.info(params)
405400

0 commit comments

Comments
 (0)