|
28 | 28 | 2. Export the model to ONNX
|
29 | 29 |
|
30 | 30 | ./pruned_transducer_stateless2/export-onnx.py \
|
31 |
| - --lang-dir $repo/data/lang_char \ |
| 31 | + --tokens $repo/data/lang_char/tokens.txt \ |
32 | 32 | --epoch 99 \
|
33 | 33 | --avg 1 \
|
34 | 34 | --exp-dir $repo/exp
|
|
48 | 48 | from pathlib import Path
|
49 | 49 | from typing import Dict, Tuple
|
50 | 50 |
|
| 51 | +import k2 |
51 | 52 | import onnx
|
52 | 53 | import torch
|
53 | 54 | import torch.nn as nn
|
|
57 | 58 | from scaling_converter import convert_scaled_to_non_scaled
|
58 | 59 | from train import get_params, get_transducer_model
|
59 | 60 |
|
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 |
68 | 63 |
|
69 | 64 |
|
70 | 65 | def get_parser():
|
@@ -110,10 +105,10 @@ def get_parser():
|
110 | 105 | )
|
111 | 106 |
|
112 | 107 | parser.add_argument(
|
113 |
| - "--lang-dir", |
| 108 | + "--tokens", |
114 | 109 | 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", |
117 | 112 | )
|
118 | 113 |
|
119 | 114 | parser.add_argument(
|
@@ -397,9 +392,9 @@ def main():
|
397 | 392 |
|
398 | 393 | logging.info(f"device: {device}")
|
399 | 394 |
|
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 |
403 | 398 |
|
404 | 399 | logging.info(params)
|
405 | 400 |
|
|
0 commit comments