From b18f7d121f2f17df8bf2d0c2bbb223bc5ddbcc0f Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期四, 25 五月 2023 16:11:22 +0800
Subject: [PATCH] docs
---
egs/alimeeting/sa-asr/asr_local.sh | 189 +++++++++++++---------------------------------
1 files changed, 55 insertions(+), 134 deletions(-)
diff --git a/egs/alimeeting/sa-asr/asr_local.sh b/egs/alimeeting/sa-asr/asr_local.sh
index c0359eb..30401b9 100755
--- a/egs/alimeeting/sa-asr/asr_local.sh
+++ b/egs/alimeeting/sa-asr/asr_local.sh
@@ -107,8 +107,8 @@
# inference_asr_model=valid.acc.best.pth
# inference_asr_model=valid.loss.ave.pth
inference_sa_asr_model=valid.acc_spk.ave.pb
-download_model= # Download a model from Model Zoo and use it for decoding.
-
+infer_with_pretrained_model=false # Use pretrained model for decoding
+download_sa_asr_model= # Download the SA-ASR model from ModelScope and use it for decoding.
# [Task dependent] Set the datadir name created by local/data.sh
train_set= # Name of training set.
valid_set= # Name of validation set used for monitoring/tuning network training.
@@ -203,7 +203,8 @@
# Note that it will overwrite args in inference config.
--inference_lm # Language modle path for decoding (default="${inference_lm}").
--inference_asr_model # ASR model path for decoding (default="${inference_asr_model}").
- --download_model # Download a model from Model Zoo and use it for decoding (default="${download_model}").
+ --infer_with_pretrained_model # Use pretrained model for decoding (default="${infer_with_pretrained_model}").
+ --download_sa_asr_model= # Download the SA-ASR model from ModelScope and use it for decoding(default="${download_sa_asr_model}").
# [Task dependent] Set the datadir name created by local/data.sh
--train_set # Name of training set (required).
@@ -304,6 +305,9 @@
lm_token_type="${token_type}"
fi
+if ${infer_with_pretrained_model}; then
+ skip_train=true
+fi
# Set tag for naming of model directory
if [ -z "${asr_tag}" ]; then
@@ -434,14 +438,14 @@
log "Stage 2: Speed perturbation: data/${train_set} -> data/${train_set}_sp"
for factor in ${speed_perturb_factors}; do
if [[ $(bc <<<"${factor} != 1.0") == 1 ]]; then
- scripts/utils/perturb_data_dir_speed.sh "${factor}" "data/${train_set}" "data/${train_set}_sp${factor}"
+ local/perturb_data_dir_speed.sh "${factor}" "data/${train_set}" "data/${train_set}_sp${factor}"
_dirs+="data/${train_set}_sp${factor} "
else
# If speed factor is 1, same as the original
_dirs+="data/${train_set} "
fi
done
- utils/combine_data.sh "data/${train_set}_sp" ${_dirs}
+ local/combine_data.sh "data/${train_set}_sp" ${_dirs}
else
log "Skip stage 2: Speed perturbation"
fi
@@ -473,9 +477,11 @@
_suf=""
fi
fi
- utils/copy_data_dir.sh --validate_opts --non-print data/"${dset}" "${data_feats}${_suf}/${dset}"
+ local/copy_data_dir.sh --validate_opts --non-print data/"${dset}" "${data_feats}${_suf}/${dset}"
- cp data/"${dset}"/utt2spk_all_fifo "${data_feats}${_suf}/${dset}/"
+ if [ "${dset}" = "Train_Ali_far" ] || [ "${dset}" = "Eval_Ali_far" ] || [ "${dset}" = "Test_Ali_far" ]; then
+ cp data/"${dset}"/utt2spk_all_fifo "${data_feats}${_suf}/${dset}/"
+ fi
rm -f ${data_feats}${_suf}/${dset}/{segments,wav.scp,reco2file_and_channel,reco2dur}
_opts=
@@ -488,7 +494,7 @@
_opts+="--segments data/${dset}/segments "
fi
# shellcheck disable=SC2086
- scripts/audio/format_wav_scp.sh --nj "${nj}" --cmd "${train_cmd}" \
+ local/format_wav_scp.sh --nj "${nj}" --cmd "${train_cmd}" \
--audio-format "${audio_format}" --fs "${fs}" ${_opts} \
"data/${dset}/wav.scp" "${data_feats}${_suf}/${dset}"
@@ -515,7 +521,7 @@
for dset in $rm_dset; do
# Copy data dir
- utils/copy_data_dir.sh --validate_opts --non-print "${data_feats}/org/${dset}" "${data_feats}/${dset}"
+ local/copy_data_dir.sh --validate_opts --non-print "${data_feats}/org/${dset}" "${data_feats}/${dset}"
cp "${data_feats}/org/${dset}/feats_type" "${data_feats}/${dset}/feats_type"
# Remove short utterances
@@ -564,12 +570,15 @@
awk ' { if( NF != 1 ) print $0; } ' >"${data_feats}/${dset}/text"
# fix_data_dir.sh leaves only utts which exist in all files
- utils/fix_data_dir.sh "${data_feats}/${dset}"
+ local/fix_data_dir.sh "${data_feats}/${dset}"
# generate uttid
cut -d ' ' -f 1 "${data_feats}/${dset}/wav.scp" > "${data_feats}/${dset}/uttid"
- # filter utt2spk_all_fifo
- python local/filter_utt2spk_all_fifo.py ${data_feats}/${dset}/uttid ${data_feats}/org/${dset} ${data_feats}/${dset}
+
+ if [ "${dset}" = "Train_Ali_far" ] || [ "${dset}" = "Eval_Ali_far" ] || [ "${dset}" = "Test_Ali_far" ]; then
+ # filter utt2spk_all_fifo
+ python local/filter_utt2spk_all_fifo.py ${data_feats}/${dset}/uttid ${data_feats}/org/${dset} ${data_feats}/${dset}
+ fi
done
# shellcheck disable=SC2002
@@ -585,7 +594,7 @@
echo "<blank>" > ${token_list}
echo "<s>" >> ${token_list}
echo "</s>" >> ${token_list}
- local/text2token.py -s 1 -n 1 --space "" ${data_feats}/lm_train.txt | cut -f 2- -d" " | tr " " "\n" \
+ utils/text2token.py -s 1 -n 1 --space "" ${data_feats}/lm_train.txt | cut -f 2- -d" " | tr " " "\n" \
| sort | uniq | grep -a -v -e '^\s*$' | awk '{print $0}' >> ${token_list}
num_token=$(cat ${token_list} | wc -l)
echo "<unk>" >> ${token_list}
@@ -603,6 +612,7 @@
python local/process_text_id.py ${data_feats}/${dset}
log "Successfully generate ${data_feats}/${dset}/text_id_train"
# generate oracle_embedding from single-speaker audio segment
+ log "oracle_embedding is being generated in the background, and the log is profile_log/gen_oracle_embedding_${dset}.log"
python local/gen_oracle_embedding.py "${data_feats}/${dset}" "data/local/${dset}_correct_single_speaker" &> "profile_log/gen_oracle_embedding_${dset}.log"
log "Successfully generate oracle embedding for ${dset} (${data_feats}/${dset}/oracle_embedding.scp)"
# generate oracle_profile and cluster_profile from oracle_embedding and cluster_embedding (padding the speaker during training)
@@ -615,6 +625,7 @@
fi
# generate cluster_profile with spectral-cluster directly (for infering and without oracle information)
if [ "${dset}" = "${valid_set}" ] || [ "${dset}" = "${test_sets}" ]; then
+ log "cluster_profile is being generated in the background, and the log is profile_log/gen_cluster_profile_infer_${dset}.log"
python local/gen_cluster_profile_infer.py "${data_feats}/${dset}" "data/local/${dset}" 0.996 0.815 &> "profile_log/gen_cluster_profile_infer_${dset}.log"
log "Successfully generate cluster profile for ${dset} (${data_feats}/${dset}/cluster_profile_infer.scp)"
fi
@@ -1213,118 +1224,20 @@
log "Skip the training stages"
fi
+if ${infer_with_pretrained_model}; then
+ log "Use ${download_sa_asr_model} for decoding and evaluation"
+ sa_asr_exp="${expdir}/${download_sa_asr_model}"
+ mkdir -p "${sa_asr_exp}"
+
+
+ python local/download_pretrained_model_from_modelscope.py $download_sa_asr_model ${expdir}
+ inference_sa_asr_model="model.pb"
+ inference_config=${sa_asr_exp}/decoding.yaml
+fi
if ! "${skip_eval}"; then
if [ ${stage} -le 13 ] && [ ${stop_stage} -ge 13 ]; then
- log "Stage 13: Decoding multi-talker ASR: training_dir=${asr_exp}"
-
- if ${gpu_inference}; then
- _cmd="${cuda_cmd}"
- inference_nj=$[${ngpu}*${njob_infer}]
- _ngpu=1
-
- else
- _cmd="${decode_cmd}"
- inference_nj=$inference_nj
- _ngpu=0
- fi
-
- _opts=
- if [ -n "${inference_config}" ]; then
- _opts+="--config ${inference_config} "
- fi
- if "${use_lm}"; then
- if "${use_word_lm}"; then
- _opts+="--word_lm_train_config ${lm_exp}/config.yaml "
- _opts+="--word_lm_file ${lm_exp}/${inference_lm} "
- else
- _opts+="--lm_train_config ${lm_exp}/config.yaml "
- _opts+="--lm_file ${lm_exp}/${inference_lm} "
- fi
- fi
-
- # 2. Generate run.sh
- log "Generate '${asr_exp}/${inference_tag}/run.sh'. You can resume the process from stage 13 using this script"
- mkdir -p "${asr_exp}/${inference_tag}"; echo "${run_args} --stage 13 \"\$@\"; exit \$?" > "${asr_exp}/${inference_tag}/run.sh"; chmod +x "${asr_exp}/${inference_tag}/run.sh"
-
- for dset in ${test_sets}; do
- _data="${data_feats}/${dset}"
- _dir="${asr_exp}/${inference_tag}/${dset}"
- _logdir="${_dir}/logdir"
- mkdir -p "${_logdir}"
-
- _feats_type="$(<${_data}/feats_type)"
- if [ "${_feats_type}" = raw ]; then
- _scp=wav.scp
- if [[ "${audio_format}" == *ark* ]]; then
- _type=kaldi_ark
- else
- _type=sound
- fi
- else
- _scp=feats.scp
- _type=kaldi_ark
- fi
-
- # 1. Split the key file
- key_file=${_data}/${_scp}
- split_scps=""
- _nj=$(min "${inference_nj}" "$(<${key_file} wc -l)")
- echo $_nj
- for n in $(seq "${_nj}"); do
- split_scps+=" ${_logdir}/keys.${n}.scp"
- done
- # shellcheck disable=SC2086
- utils/split_scp.pl "${key_file}" ${split_scps}
-
- # 2. Submit decoding jobs
- log "Decoding started... log: '${_logdir}/asr_inference.*.log'"
-
- ${_cmd} --gpu "${_ngpu}" --max-jobs-run "${_nj}" JOB=1:"${_nj}" "${_logdir}"/asr_inference.JOB.log \
- python -m funasr.bin.asr_inference_launch \
- --batch_size 1 \
- --nbest 1 \
- --ngpu "${_ngpu}" \
- --njob ${njob_infer} \
- --gpuid_list ${device} \
- --data_path_and_name_and_type "${_data}/${_scp},speech,${_type}" \
- --key_file "${_logdir}"/keys.JOB.scp \
- --asr_train_config "${asr_exp}"/config.yaml \
- --asr_model_file "${asr_exp}"/"${inference_asr_model}" \
- --output_dir "${_logdir}"/output.JOB \
- --mode asr \
- ${_opts}
-
- # 3. Concatenates the output files from each jobs
- for f in token token_int score text; do
- for i in $(seq "${_nj}"); do
- cat "${_logdir}/output.${i}/1best_recog/${f}"
- done | LC_ALL=C sort -k1 >"${_dir}/${f}"
- done
- done
- fi
-
-
- if [ ${stage} -le 14 ] && [ ${stop_stage} -ge 14 ]; then
- log "Stage 14: Scoring multi-talker ASR"
-
- for dset in ${test_sets}; do
- _data="${data_feats}/${dset}"
- _dir="${asr_exp}/${inference_tag}/${dset}"
-
- python local/proce_text.py ${_data}/text ${_data}/text.proc
- python local/proce_text.py ${_dir}/text ${_dir}/text.proc
-
- python local/compute_wer.py ${_data}/text.proc ${_dir}/text.proc ${_dir}/text.cer
- tail -n 3 ${_dir}/text.cer > ${_dir}/text.cer.txt
- cat ${_dir}/text.cer.txt
-
- done
-
- fi
-
- if [ ${stage} -le 15 ] && [ ${stop_stage} -ge 15 ]; then
- log "Stage 15: Decoding SA-ASR (oracle profile): training_dir=${sa_asr_exp}"
+ log "Stage 13: Decoding SA-ASR (oracle profile): training_dir=${sa_asr_exp}"
if ${gpu_inference}; then
_cmd="${cuda_cmd}"
@@ -1390,6 +1303,7 @@
${_cmd} --gpu "${_ngpu}" --max-jobs-run "${_nj}" JOB=1:"${_nj}" "${_logdir}"/asr_inference.JOB.log \
python -m funasr.bin.asr_inference_launch \
--batch_size 1 \
+ --mc True \
--nbest 1 \
--ngpu "${_ngpu}" \
--njob ${njob_infer} \
@@ -1414,17 +1328,20 @@
done
fi
- if [ ${stage} -le 16 ] && [ ${stop_stage} -ge 16 ]; then
- log "Stage 16: Scoring SA-ASR (oracle profile)"
+ if [ ${stage} -le 14 ] && [ ${stop_stage} -ge 14 ]; then
+ log "Stage 14: Scoring SA-ASR (oracle profile)"
for dset in ${test_sets}; do
_data="${data_feats}/${dset}"
_dir="${sa_asr_exp}/${sa_asr_inference_tag}.oracle/${dset}"
- python local/proce_text.py ${_data}/text ${_data}/text.proc
- python local/proce_text.py ${_dir}/text ${_dir}/text.proc
+ sed 's/\$//g' ${_data}/text > ${_data}/text_nosrc
+ sed 's/\$//g' ${_dir}/text > ${_dir}/text_nosrc
- python local/compute_wer.py ${_data}/text.proc ${_dir}/text.proc ${_dir}/text.cer
+ python utils/proce_text.py ${_data}/text_nosrc ${_data}/text.proc
+ python utils/proce_text.py ${_dir}/text_nosrc ${_dir}/text.proc
+
+ python utils/compute_wer.py ${_data}/text.proc ${_dir}/text.proc ${_dir}/text.cer
tail -n 3 ${_dir}/text.cer > ${_dir}/text.cer.txt
cat ${_dir}/text.cer.txt
@@ -1439,8 +1356,8 @@
fi
- if [ ${stage} -le 17 ] && [ ${stop_stage} -ge 17 ]; then
- log "Stage 17: Decoding SA-ASR (cluster profile): training_dir=${sa_asr_exp}"
+ if [ ${stage} -le 15 ] && [ ${stop_stage} -ge 15 ]; then
+ log "Stage 15: Decoding SA-ASR (cluster profile): training_dir=${sa_asr_exp}"
if ${gpu_inference}; then
_cmd="${cuda_cmd}"
@@ -1506,6 +1423,7 @@
${_cmd} --gpu "${_ngpu}" --max-jobs-run "${_nj}" JOB=1:"${_nj}" "${_logdir}"/asr_inference.JOB.log \
python -m funasr.bin.asr_inference_launch \
--batch_size 1 \
+ --mc True \
--nbest 1 \
--ngpu "${_ngpu}" \
--njob ${njob_infer} \
@@ -1529,17 +1447,20 @@
done
fi
- if [ ${stage} -le 18 ] && [ ${stop_stage} -ge 18 ]; then
- log "Stage 18: Scoring SA-ASR (cluster profile)"
+ if [ ${stage} -le 16 ] && [ ${stop_stage} -ge 16 ]; then
+ log "Stage 16: Scoring SA-ASR (cluster profile)"
for dset in ${test_sets}; do
_data="${data_feats}/${dset}"
_dir="${sa_asr_exp}/${sa_asr_inference_tag}.cluster/${dset}"
- python local/proce_text.py ${_data}/text ${_data}/text.proc
- python local/proce_text.py ${_dir}/text ${_dir}/text.proc
+ sed 's/\$//g' ${_data}/text > ${_data}/text_nosrc
+ sed 's/\$//g' ${_dir}/text > ${_dir}/text_nosrc
- python local/compute_wer.py ${_data}/text.proc ${_dir}/text.proc ${_dir}/text.cer
+ python utils/proce_text.py ${_data}/text_nosrc ${_data}/text.proc
+ python utils/proce_text.py ${_dir}/text_nosrc ${_dir}/text.proc
+
+ python utils/compute_wer.py ${_data}/text.proc ${_dir}/text.proc ${_dir}/text.cer
tail -n 3 ${_dir}/text.cer > ${_dir}/text.cer.txt
cat ${_dir}/text.cer.txt
--
Gitblit v1.9.1