-
Notifications
You must be signed in to change notification settings - Fork 305
/
test_asr_datamodule.py
executable file
·98 lines (78 loc) · 2.69 KB
/
test_asr_datamodule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# Copyright 2022 Xiaomi Corp. (authors: Fangjun Kuang)
#
# See ../../../../LICENSE for clarification regarding multiple authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
To run this file, do:
cd icefall/egs/librispeech/ASR
python ./transducer_stateless_multi_datasets/test_asr_datamodule.py
"""
import argparse
import random
from pathlib import Path
from asr_datamodule import AsrDataModule
from gigaspeech import GigaSpeech
from lhotse import load_manifest
from librispeech import LibriSpeech
def test_dataset():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
AsrDataModule.add_arguments(parser)
args = parser.parse_args()
print(args)
if args.enable_musan:
cuts_musan = load_manifest(Path(args.manifest_dir) / "musan_cuts.jsonl.gz")
else:
cuts_musan = None
librispeech = LibriSpeech(manifest_dir=args.manifest_dir)
gigaspeech = GigaSpeech(manifest_dir=args.manifest_dir)
train_clean_100 = librispeech.train_clean_100_cuts()
train_S = gigaspeech.train_S_cuts()
asr_datamodule = AsrDataModule(args)
libri_train_dl = asr_datamodule.train_dataloaders(
train_clean_100,
on_the_fly_feats=False,
cuts_musan=cuts_musan,
)
giga_train_dl = asr_datamodule.train_dataloaders(
train_S,
on_the_fly_feats=True,
cuts_musan=cuts_musan,
)
seed = 20220216
rng = random.Random(seed)
for epoch in range(2):
print("epoch", epoch)
batch_idx = 0
libri_train_dl.sampler.set_epoch(epoch)
giga_train_dl.sampler.set_epoch(epoch)
iter_libri = iter(libri_train_dl)
iter_giga = iter(giga_train_dl)
while True:
idx = rng.choices((0, 1), weights=[0.8, 0.2], k=1)[0]
dl = iter_libri if idx == 0 else iter_giga
batch_idx += 1
print("dl idx", idx, "batch_idx", batch_idx)
try:
_ = next(dl)
except StopIteration:
print("dl idx", idx)
print("Go to the next epoch")
break
def main():
test_dataset()
if __name__ == "__main__":
main()