tomwalters@54: #!/bin/bash tomwalters@54: # Script to run a single HMM train/test cycle with the given parameters. tomwalters@54: # This script expects the following variables to be set tomwalters@54: # tomwalters@54: # total_hmm_states - total number of HMM states (including the 2 non-emitting states) tomwalters@54: # mixture_components - number of components in the output distribution for each emitting state tomwalters@54: # input_vector_size - number or elements in the input vector (normally 39 for MFCCs, 12 for AIM) tomwalters@54: # feature_code - HTK feature type code for the features being used (normally MFCC_0_D_A for MFCCs and USER_E_D_A for AIM features) tomwalters@54: # FEATURE_SUFFIXES - List of suffixes appended to the feature filenames. For the MFCCs this is just "mfc" but for the AIM feature, there can be multiple features generated from each run of AIMCopy tomwalters@54: # WORK - working directory tomwalters@54: # SYLLIST_COMPLETE tomwalters@54: tomwalters@54: # Filenames generated here tomwalters@54: HMMPROTO=hmm_prototype tomwalters@54: HHED_SCRIPT=hhed_change_components_script tomwalters@54: RECOUT=recognition_output tomwalters@54: RESULTS_FILE=results tomwalters@54: MISCLASSIFIED=misclassified_syllables tomwalters@54: tomwalters@54: # Filenames used here tomwalters@54: TRAIN_SCRIPT=training_script tomwalters@54: TEST_SCRIPT=testing_script tomwalters@54: SYLLIST_COMPLETE=syllable_list_with_silence tomwalters@54: tomwalters@54: hmm_type=${total_hmm_states}states_${mixture_components}mixture_components tomwalters@54: echo "HMM type: $hmm_type" tomwalters@54: mkdir -p $WORK/$hmm_type tomwalters@54: tomwalters@54: echo "Creating HMM structure..." tomwalters@54: ./gen_hmmproto.py --input_size ${input_vector_size} --total_hmm_states ${total_hmm_states} --feature_type ${feature_code} > $WORK/$hmm_type/$HMMPROTO tomwalters@54: tomwalters@54: echo "Adding output mixture components..." tomwalters@54: ./gen_hhed_script.py --num_means ${mixture_components} --total_hmm_states ${total_hmm_states} > $WORK/$hmm_type/$HHED_SCRIPT tomwalters@54: tomwalters@54: tomwalters@54: echo "Training HMM..." tomwalters@54: echo "Setting up prototype HMM..." tomwalters@54: mkdir -p $WORK/$hmm_type/hmm0 tomwalters@54: HCompV -C $WORK/$HMMCONFIG -f 0.01 -m -S $WORK/$TRAIN_SCRIPT -M $WORK/$hmm_type/hmm0 $WORK/$hmm_type/$HMMPROTO tomwalters@54: tomwalters@54: echo "Generating HMM definitions..." tomwalters@54: # Now take the prototype file from hmm0, and create the other HMM definitions tomwalters@54: # from it tomwalters@54: grep -A 9999 "" $WORK/$hmm_type/hmm0/$HMMPROTO > $WORK/$hmm_type/hmm0/hmms tomwalters@54: for syllable in $(cat $WORK/$SYLLIST_COMPLETE); do tomwalters@54: echo "~h $syllable" >> $WORK/$hmm_type/$feature/hmm0/hmmdefs tomwalters@54: cat $WORK/$hmm_type/$feature/hmm0/hmms >> $WORK/$hmm_type/$feature/hmm0/hmmdefs tomwalters@54: done tomwalters@54: tomwalters@54: echo -n "~o 1 ${input_vector_size} ${input_vector_size}<${feature_code}>" > $WORK/$hmm_type/$feature/hmm0/macros tomwalters@54: tomwalters@54: cat $WORK/$hmm_type/$feature/hmm0/vFloors >> $WORK/$hmm_type/$feature/hmm0/macros tomwalters@54: tomwalters@54: ${HTK_PREFIX}HHEd -H $WORK/$hmm_type/$feature/hmm0/macros -H $WORK/$hmm_type/$feature/hmm0/hmmdefs $WORK/$hmm_type/$HHED_SCRIPT $WORK/$SYLLIST_COMPLETE tomwalters@54: tomwalters@54: for iter in $TRAINING_ITERATIONS_LIST; do tomwalters@54: echo "Training iteration ${iter}..." tomwalters@54: let "nextiter=$iter+1" tomwalters@54: mkdir $WORK/$hmm_type/hmm$nextiter tomwalters@54: ${HTK_PREFIX}HERest -C $WORK/$HMMCONFIG -I $WORK/$TRAIN_MLF \ tomwalters@54: -t 250.0 150.0 1000.0 -S $WORK/$TRAIN_SCRIPT \ tomwalters@54: -H $WORK/$hmm_type/hmm$iter/macros -H $WORK/$hmm_type/hmm$iter/hmmdefs \ tomwalters@54: -M $WORK/$hmm_type/hmm$nextiter $WORK/$SYLLIST_COMPLETE tomwalters@54: done tomwalters@54: tomwalters@54: for iter in $TESTING_ITERATIONS_LIST; do tomwalters@54: echo "Testing iteration ${iter}..." tomwalters@54: ${HTK_PREFIX}HVite -H $WORK/$hmm_type/hmm$iter/macros -H $WORK/$hmm_type/hmm$iter/hmmdefs \ tomwalters@54: -C $WORK/$HMMCONFIG -S $WORK/$TEST_SCRIPT -i $WORK/$hmm_type/$RECOUT \ tomwalters@54: -w $WORK/$WDNET -p 0.0 -s 5.0 $WORK/$DICT $WORK/$SYLLIST_COMPLETE tomwalters@54: echo "Results from testing on iteration ${iter}..." tomwalters@54: ${HTK_PREFIX}HResults -e "???" ${SILENCE} -I $WORK/$TEST_MLF $WORK/$SYLLIST_COMPLETE $WORK/$hmm_type/$RECOUT tomwalters@54: ${HTK_PREFIX}HResults -p -t -e "???" ${SILENCE} \ tomwalters@54: -I $WORK/$TEST_MLF $WORK/$SYLLIST_COMPLETE $WORK/$hmm_type/$RECOUT > $WORK/$hmm_type/${RESULTS_FILE}_iteration_$iter tomwalters@54: grep Aligned $WORK/$hmm_type/${RESULTS_FILE}_iteration_$iter| sed -E "s/.*\/..\/([a-z]{2})([0-9]{2,3}\.[0-9])p([0-9]{2,3}\.[0-9])s.*/\2 \3/" | sort | uniq -c > $WORK/$hmm_type/${MISCLASSIFIED}_iteration_$iter tomwalters@54: done