Skip to content

Commit

Permalink
bugfix time_speech_total_per_sample=0
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraGPT committed Jan 25, 2024
1 parent fa56f36 commit 4091bf6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ python funasr/bin/inference.py \
--config-path="/Users/zhifu/funasr_github/test_local/funasr_cli_egs" \
--config-name="config.yaml" \
++init_param="/Users/zhifu/funasr_github/test_local/funasr_cli_egs/model.pt" \
+tokenizer_conf.token_list="/Users/zhifu/funasr_github/test_local/funasr_cli_egs/tokens.txt" \
+frontend_conf.cmvn_file="/Users/zhifu/funasr_github/test_local/funasr_cli_egs/am.mvn" \
+input="data/wav.scp" \
+output_dir="./outputs/debug" \
+device="cuda" \
++tokenizer_conf.token_list="/Users/zhifu/funasr_github/test_local/funasr_cli_egs/tokens.txt" \
++frontend_conf.cmvn_file="/Users/zhifu/funasr_github/test_local/funasr_cli_egs/am.mvn" \
++input="data/wav.scp" \
++output_dir="./outputs/debug" \
++device="cuda" \

43 changes: 24 additions & 19 deletions funasr/auto/auto_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def inference(self, input, input_len=None, model=None, kwargs=None, key=None, **
time_escape_total += time_escape

if pbar:
pbar.update(1)
# pbar.update(1)
pbar.set_description(f"rtf_avg: {time_escape_total/time_speech_total:0.3f}")
torch.cuda.empty_cache()
return asr_result_list
Expand All @@ -285,10 +285,10 @@ def inference_with_vad(self, input, input_len=None, **cfg):

key_list, data_list = prepare_data_iterator(input, input_len=input_len, data_type=kwargs.get("data_type", None))
results_ret_list = []
time_speech_total_all_samples = 0.0
time_speech_total_all_samples = 1e-6

beg_total = time.time()
pbar_total = tqdm(colour="red", total=len(res) + 1, dynamic_ncols=True)
pbar_total = tqdm(colour="red", total=len(res), dynamic_ncols=True)
for i in range(len(res)):
key = res[i]["key"]
vadsegments = res[i]["value"]
Expand All @@ -310,14 +310,14 @@ def inference_with_vad(self, input, input_len=None, **cfg):
batch_size_ms_cum = 0
beg_idx = 0
beg_asr_total = time.time()
time_speech_total_per_sample = speech_lengths/16000 + 1e-6
time_speech_total_per_sample = speech_lengths/16000
time_speech_total_all_samples += time_speech_total_per_sample

pbar_sample = tqdm(colour="blue", total=n + 1, dynamic_ncols=True)
# pbar_sample = tqdm(colour="blue", total=n, dynamic_ncols=True)

all_segments = []
for j, _ in enumerate(range(0, n)):
pbar_sample.update(1)
# pbar_sample.update(1)
batch_size_ms_cum += (sorted_data[j][0][1] - sorted_data[j][0][0])
if j < n - 1 and (
batch_size_ms_cum + sorted_data[j + 1][0][1] - sorted_data[j + 1][0][0]) < batch_size and (
Expand All @@ -336,19 +336,19 @@ def inference_with_vad(self, input, input_len=None, **cfg):
segments = sv_chunk(vad_segments)
all_segments.extend(segments)
speech_b = [i[2] for i in segments]
spk_res = self.inference(speech_b, input_len=None, model=self.spk_model, kwargs=kwargs, **cfg)
spk_res = self.inference(speech_b, input_len=None, model=self.spk_model, kwargs=kwargs, disable_pbar=True, **cfg)
results[_b]['spk_embedding'] = spk_res[0]['spk_embedding']
beg_idx = end_idx
if len(results) < 1:
continue
results_sorted.extend(results)

end_asr_total = time.time()
time_escape_total_per_sample = end_asr_total - beg_asr_total
pbar_sample.update(1)
pbar_sample.set_description(f"rtf_avg_per_sample: {time_escape_total_per_sample / time_speech_total_per_sample:0.3f}, "
f"time_speech_total_per_sample: {time_speech_total_per_sample: 0.3f}, "
f"time_escape_total_per_sample: {time_escape_total_per_sample:0.3f}")
# end_asr_total = time.time()
# time_escape_total_per_sample = end_asr_total - beg_asr_total
# pbar_sample.update(1)
# pbar_sample.set_description(f"rtf_avg_per_sample: {time_escape_total_per_sample / time_speech_total_per_sample:0.3f}, "
# f"time_speech_total_per_sample: {time_speech_total_per_sample: 0.3f}, "
# f"time_escape_total_per_sample: {time_escape_total_per_sample:0.3f}")

restored_data = [0] * n
for j in range(n):
Expand Down Expand Up @@ -386,7 +386,7 @@ def inference_with_vad(self, input, input_len=None, **cfg):
# step.3 compute punc model
if self.punc_model is not None:
self.punc_kwargs.update(cfg)
punc_res = self.inference(result["text"], model=self.punc_model, kwargs=self.punc_kwargs, **cfg)
punc_res = self.inference(result["text"], model=self.punc_model, kwargs=self.punc_kwargs, disable_pbar=True, **cfg)
import copy; raw_text = copy.copy(result["text"])
result["text"] = punc_res[0]["text"]

Expand Down Expand Up @@ -418,13 +418,18 @@ def inference_with_vad(self, input, input_len=None, **cfg):

result["key"] = key
results_ret_list.append(result)
end_asr_total = time.time()
time_escape_total_per_sample = end_asr_total - beg_asr_total
pbar_total.update(1)

pbar_total.update(1)
pbar_total.set_description(f"rtf_avg: {time_escape_total_per_sample / time_speech_total_per_sample:0.3f}, "
f"time_speech: {time_speech_total_per_sample: 0.3f}, "
f"time_escape: {time_escape_total_per_sample:0.3f}")


end_total = time.time()
time_escape_total_all_samples = end_total - beg_total
pbar_total.set_description(f"rtf_avg_all_samples: {time_escape_total_all_samples / time_speech_total_all_samples:0.3f}, "
f"time_speech_total_all_samples: {time_speech_total_all_samples: 0.3f}, "
f"time_escape_total_all_samples: {time_escape_total_all_samples:0.3f}")
print(f"rtf_avg_all: {time_escape_total_all_samples / time_speech_total_all_samples:0.3f}, "
f"time_speech_all: {time_speech_total_all_samples: 0.3f}, "
f"time_escape_all: {time_escape_total_all_samples:0.3f}")
return results_ret_list

0 comments on commit 4091bf6

Please sign in to comment.