From 042c5cc16f4a41efd538b89e7d720f4b93781824 Mon Sep 17 00:00:00 2001 From: "Matthew D. Scholefield" Date: Mon, 20 Apr 2020 09:21:43 -0500 Subject: [PATCH] Add train_speech_commands.sh This is a script runs the the training process for a given word in the speech commands dataset --- train_speech_commands.sh | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 train_speech_commands.sh diff --git a/train_speech_commands.sh b/train_speech_commands.sh new file mode 100755 index 00000000..fcffff69 --- /dev/null +++ b/train_speech_commands.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +cd "$(dirname "$0")" # Cd to script location +set -eE + +dataset_url="http://download.tensorflow.org/data/speech_commands_v0.02.tar.gz" +dataset_md5="6b74f3901214cb2c2934e98196829835" +dataset_filename="speech_commands_v0.02.tar.gz" +dataset_folder="speech_commands" +demo_class="marvin" + +mkdir -p "data" +echo "Downloading speech commands dataset..." +cur_md5=$(md5sum "data/$dataset_filename" | awk '{print $1}') +if [ "$cur_md5" != "$dataset_md5" ] || [ ! -d "data/$dataset_folder" ]; then + if [ "$cur_md5" != "$dataset_md5" ]; then + wget "$dataset_url" -O "data/$dataset_filename" + fi + pushd "data/$dataset_folder" + tar xvf "../$dataset_filename" + popd 2>/dev/null +else + echo "Skipping, already downloaded." +fi + +pushd "data/$dataset_folder" +classes=$(find * -maxdepth 0 -type d -name '[a-zA-Z]*') +for class in $classes; do + if [ -f "tags-$class.txt" ]; then + echo "Already generated tags-$class.txt." + continue + fi + echo "Generating tags-$class.txt..." + { + find "$class" -name '*.wav' | { + while read line; do + printf "${line%.wav}\twake-word\n" + done + } + for other_class in $classes; do + if [ "$class" = "$other_class" ]; then + continue + fi + find "$other_class" -name '*.wav' | { + while read line; do + printf "${line%.wav}\tnot-wake-word\n" + done + } + done + } > "tags-$class.txt" +done +popd 2>/dev/null + +./setup.sh +source .venv/bin/activate + +echo "Dataset import complete." + +mkdir -p models/ +train_command="precise-train models/$demo_class.net data/$dataset_folder --tags-file data/$dataset_folder/tags-$demo_class.txt -e 3 --batch-size 128 --sensitivity 0.5" +echo "" +echo "Training $demo_class model with command:" +echo "$ $train_command" +echo "" +echo "Press any key to begin model training..." +read -n 1 +eval "$train_command" + +echo "Model saved to models/$demo_class.net" +echo "" + +test_command="precise-test models/$demo_class.net data/$dataset_folder --tags-file data/$dataset_folder/tags-$demo_class.txt" +echo "Testing $demo_class model with command:" +echo "$ $test_command" +echo "" +echo "Press any key to test model..." +read -n 1 +eval "$test_command" + +listen_command="precise-listen models/$demo_class.net --sensitivity 0.5" +echo "Running $demo_class model against microphone with command:" +echo "$ $listen_command" +echo "" +echo "Note: This will continuously listen to the microphone and should activate with the word \"$demo_class\". When you are done testing you can exit with Ctrl+C." +echo "Press any key to test against microphone..." +read -n 1 +eval "$listen_command"