annotate testdata/evaluation/run-singleinstrumenttest.sh @ 372:af71cbdab621 tip

Update bqvec code
author Chris Cannam
date Tue, 19 Nov 2019 10:13:32 +0000
parents 40684b5dd478
children
rev   line source
Chris@210 1 #!/bin/sh
Chris@210 2
Chris@210 3 trios_path="/home/cannam/Music/TRIOS_dataset"
Chris@210 4 yc="/home/cannam/code/may/bin/yc"
Chris@210 5
Chris@210 6 if [ ! -d "$trios_path" ]; then
Chris@210 7 echo "TRIOS dataset directory $trios_path not found, giving up"
Chris@210 8 exit 1
Chris@210 9 fi
Chris@210 10
Chris@210 11 if ! "$yc" -v ; then
Chris@210 12 echo "Failed to run Yeti compiler yc at $yc_path, giving up";
Chris@210 13 fi
Chris@210 14
Chris@210 15 if ! sonic-annotator -v ; then
Chris@210 16 echo "Failed to run sonic-annotator (not in PATH?), giving up"
Chris@210 17 exit 1
Chris@210 18 fi
Chris@210 19
Chris@210 20 rdffile="../../silvet.n3"
Chris@210 21 if [ ! -f "$rdffile" ] ; then
Chris@210 22 echo "Failed to find plugin RDF file at $rdffile, giving up"
Chris@210 23 exit 1
Chris@210 24 fi
Chris@210 25
Chris@210 26 case "$trios_path" in
Chris@210 27 *\ *) echo "TRIOS dataset path $trios_path has a space in it, this script won't handle that"; exit 1;;
Chris@210 28 esac
Chris@210 29
Chris@210 30 ( cd ../.. ; make -f Makefile.linux ) || exit 1
Chris@210 31
Chris@210 32 VAMP_PATH=../..
Chris@210 33 export VAMP_PATH
Chris@210 34
Chris@210 35 outfile="/tmp/$$"
Chris@210 36
Chris@210 37 tmpwav="/tmp/$$norm.wav"
Chris@210 38
Chris@210 39 instfile="/tmp/$$instruments.txt"
Chris@210 40
Chris@210 41 transfile="/tmp/$$transform.ttl"
Chris@210 42
Chris@210 43 trap 'rm -f "$outfile" "$tmpwav" "$instfile" "$transfile" "$outfile.lab"' 0
Chris@210 44
Chris@210 45 # Use the single-instrument monophonic non-synthetic files for a
Chris@210 46 # (varied) subset of the TRIOS dataset. We take only those instruments
Chris@210 47 # for which we have a preset available
Chris@210 48 infiles="$trios_path/lussier/bassoon.wav $trios_path/take_five/saxophone.wav $trios_path/schubert/violin.wav $trios_path/mozart/clarinet.wav"
Chris@210 49
Chris@210 50 grep Piano "$rdffile" | sed 's/^.*( *//' | sed 's/ *).*$//' | sed 's/ "/\n/g' | sed 's/"//g' | tr '[A-Z]' '[a-z]' | tail -n +2 | cat -n > "$instfile"
Chris@210 51
Chris@210 52 instrument_for() {
Chris@210 53 filename="$1"
Chris@210 54 base=`basename "$filename" .wav`
Chris@210 55 if [ "$base" = "saxophone" ]; then base="tenorsax"; fi
Chris@210 56 instrument_no=`grep "$base" "$instfile" | awk '{ print $1; }'`
Chris@210 57 if [ -z "$instrument_no" ] || [ -z "$base" ];
Chris@210 58 then echo 0
Chris@210 59 else echo "$instrument_no"
Chris@210 60 fi
Chris@210 61 }
Chris@210 62
Chris@210 63 echo
Chris@210 64 echo "Input files are:"
Chris@210 65 echo $infiles | fmt -1
Chris@210 66
Chris@210 67 time for infile in $infiles; do
Chris@210 68
Chris@210 69 echo
Chris@210 70 echo "Evaluating for file $infile..."
Chris@210 71
Chris@210 72 intended_instrument=`instrument_for "$infile"`
Chris@210 73 case "$intended_instrument" in
Chris@210 74 [0-9]*) ;;
Chris@210 75 *) echo "Instrument extraction failed for infile $infile -- not even default multi-instrument setting returned?"; exit 1;;
Chris@210 76 esac
Chris@210 77
Chris@210 78 piece=`basename \`dirname "$infile" \``
Chris@210 79 arrangement=`basename "$infile" .wav`
Chris@269 80 mode=1
Chris@210 81
Chris@210 82 # We run this twice, once using the default instrument
Chris@210 83 # (i.e. "multiple or unknown") and once using the intended
Chris@210 84 # instrument preset (the solo one).
Chris@210 85
Chris@210 86 for instrument in $intended_instrument 0; do
Chris@210 87
Chris@210 88 echo
Chris@210 89 echo "For piece $piece, arrangement $arrangement, using instrument $instrument..."
Chris@210 90
Chris@210 91 sox "$infile" "$tmpwav" gain -n -6.020599913279624
Chris@210 92
Chris@210 93 # generate the transform by interpolating the instrument parameter
Chris@269 94 cat transform.ttl | \
Chris@269 95 sed "s/INSTRUMENT_PARAMETER/$instrument/" | \
Chris@269 96 sed "s/MODE_PARAMETER/$mode/" > "$transfile"
Chris@210 97
Chris@210 98 sonic-annotator \
Chris@210 99 --writer csv \
Chris@210 100 --csv-one-file "$outfile" \
Chris@210 101 --csv-force \
Chris@210 102 --transform "$transfile" \
Chris@210 103 "$tmpwav"
Chris@210 104
Chris@210 105 cat "$outfile" | \
Chris@210 106 sed 's/^[^,]*,//' | \
Chris@210 107 while IFS=, read start duration frequency level label; do
Chris@210 108 end=`echo "$start $duration + p" | dc`
Chris@210 109 echo -e "$start\t$end\t$frequency"
Chris@210 110 done > "$outfile.lab"
Chris@210 111
Chris@210 112 for ms in 50 100; do
Chris@210 113 mark=""
Chris@210 114 if [ "$ms" = "50" ]; then mark=" <-- main $piece/$arrangement"; fi;
Chris@210 115 echo
Chris@210 116 echo "Validating against ground truth at $ms ms:"
Chris@233 117 "$yc" ../scripts/evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "$outfile.lab" | sed 's,$,'"$mark"','
Chris@210 118 echo
Chris@210 119 echo "Validating against MIREX submission at $ms ms:"
Chris@233 120 "$yc" ../scripts/evaluate_lab.yeti "$ms" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab" "$outfile.lab"
Chris@210 121 echo
Chris@210 122 echo "Validating MIREX against ground truth at $ms ms":
Chris@233 123 "$yc" ../scripts/evaluate_lab.yeti "$ms" "../TRIOS-groundtruth/$piece/$arrangement.lab" "../TRIOS-mirex2012-matlab/$piece/$arrangement.lab"
Chris@210 124 done;
Chris@210 125
Chris@210 126 echo
Chris@210 127 done
Chris@210 128 done