annotate testdata/evaluation/run-piano.sh @ 255:a5c34d2eaa5f norm

Added tag eval-norm-todate for changeset d9b688700819
author Chris Cannam
date Wed, 23 Jul 2014 13:44:35 +0100
parents b609a4f2929f
children c9d2809cb86d
rev   line source
Chris@222 1 #!/bin/sh
Chris@222 2
Chris@222 3 # Assumption: instrument parameter value 0 of the Silvet plugin is
Chris@222 4 # always "multiple or unknown instruments" and 1 is always "piano".
Chris@222 5
Chris@222 6 piano_path="/home/cannam/Music/piano_small_dataset"
Chris@222 7 yc="/home/cannam/code/may/bin/yc"
Chris@222 8
Chris@222 9 if [ ! -d "$piano_path" ]; then
Chris@222 10 echo "Piano dataset directory $piano_path not found, giving up"
Chris@222 11 exit 1
Chris@222 12 fi
Chris@222 13
Chris@222 14 if ! "$yc" -v ; then
Chris@222 15 echo "Failed to run Yeti compiler yc at $yc_path, giving up";
Chris@222 16 fi
Chris@222 17
Chris@222 18 if ! sonic-annotator -v ; then
Chris@222 19 echo "Failed to run sonic-annotator (not in PATH?), giving up"
Chris@222 20 exit 1
Chris@222 21 fi
Chris@222 22
Chris@222 23 rdffile="../../silvet.n3"
Chris@222 24 if [ ! -f "$rdffile" ] ; then
Chris@222 25 echo "Failed to find plugin RDF file at $rdffile, giving up"
Chris@222 26 exit 1
Chris@222 27 fi
Chris@222 28
Chris@222 29 case "$piano_path" in
Chris@222 30 *\ *) echo "Piano dataset path $piano_path has a space in it, this script won't handle that"; exit 1;;
Chris@222 31 esac
Chris@222 32
Chris@222 33 ( cd ../.. ; make -f Makefile.linux ) || exit 1
Chris@222 34
Chris@222 35 VAMP_PATH=../..
Chris@222 36 export VAMP_PATH
Chris@222 37
Chris@222 38 outfile="/tmp/$$"
Chris@225 39 reference="/tmp/$$ref"
Chris@222 40
Chris@222 41 tmpwav="/tmp/$$.wav"
Chris@222 42
Chris@222 43 transfile="/tmp/$$transform.ttl"
Chris@222 44
Chris@222 45 trap 'rm -f "$outfile" "$tmpwav" "$instfile" "$transfile" "$outfile.lab"' 0
Chris@222 46
Chris@238 47 infiles=$(find "$piano_path" -name \*.wav | sort)
Chris@222 48
Chris@222 49 echo
Chris@222 50 echo "Input files are:"
Chris@222 51 echo $infiles | fmt -1
Chris@222 52
Chris@222 53 time for infile in $infiles; do
Chris@222 54
Chris@222 55 echo
Chris@222 56 echo "Evaluating for file $infile..."
Chris@222 57
Chris@222 58 intended_instrument=1 ## assumption: 1 == piano
Chris@222 59
Chris@222 60 # We run this twice, once using the default instrument
Chris@222 61 # (i.e. "multiple or unknown") and once using the intended
Chris@222 62 # instrument preset (piano).
Chris@222 63
Chris@222 64 filename=$(basename "$infile" .wav)
Chris@222 65
Chris@225 66 duration=30
Chris@225 67
Chris@238 68 for instrument in $intended_instrument ; do
Chris@222 69
Chris@223 70 for norm in no yes; do
Chris@222 71
Chris@223 72 echo
Chris@223 73 echo "For file $filename, instrument $instrument, norm $norm..."
Chris@222 74
Chris@223 75 if [ "$norm" = "no" ]; then
Chris@248 76 # Don't normalise; plugin is now supposed to do it
Chris@248 77 sox "$infile" "$tmpwav" trim 0 $duration
Chris@223 78 else
Chris@223 79 # Normalise as reference
Chris@225 80 sox "$infile" "$tmpwav" trim 0 $duration gain -n -6.020599913279624
Chris@223 81 fi
Chris@222 82
Chris@223 83 # generate the transform by interpolating the instrument parameter
Chris@223 84 cat transform.ttl | sed "s/INSTRUMENT_PARAMETER/$instrument/" > "$transfile"
Chris@222 85
Chris@223 86 sonic-annotator \
Chris@223 87 --writer csv \
Chris@223 88 --csv-one-file "$outfile" \
Chris@223 89 --csv-force \
Chris@223 90 --transform "$transfile" \
Chris@223 91 "$tmpwav"
Chris@222 92
Chris@223 93 cat "$outfile" | \
Chris@223 94 sed 's/^[^,]*,//' | \
Chris@223 95 while IFS=, read start duration frequency level label; do
Chris@223 96 end=`echo "$start $duration + p" | dc`
Chris@223 97 echo -e "$start\t$end\t$frequency"
Chris@223 98 done > "$outfile.lab"
Chris@223 99
Chris@224 100 for ms in 50 100 150; do
Chris@223 101 mark=""
Chris@224 102 if [ "$ms" = "50" ]; then
Chris@224 103 if [ "$instrument" = "0" ]; then
Chris@225 104 mark=" <-- main generic preset for $filename (norm = $norm)";
Chris@224 105 else
Chris@225 106 mark=" <-- main piano preset for $filename (norm = $norm)";
Chris@224 107 fi
Chris@223 108 fi;
Chris@223 109 echo
Chris@223 110 echo "Validating against ground truth at $ms ms:"
Chris@225 111 egrep '(^[0-9]\.)|(^[012][0-9]\.)' "../piano-groundtruth/$filename.lab" > "$reference.lab"
Chris@233 112 "$yc" ../scripts/evaluate_lab.yeti "$ms" "$reference.lab" "$outfile.lab" | sed 's,$,'"$mark"','
Chris@225 113 cp "$reference.lab" /tmp/reference.lab
Chris@225 114 cp "$outfile.lab" /tmp/detected.lab
Chris@223 115 done;
Chris@222 116 echo
Chris@223 117 done
Chris@222 118 done
Chris@222 119 done