Mercurial > hg > silvet
changeset 71:ce64d11ef336
evaluation of transcription output
author | emmanouilb <emmanouil.benetos.1@city.ac.uk> |
---|---|
date | Sat, 03 May 2014 20:49:51 +0100 |
parents | c8a4a541f3bb |
children | daca1bab4946 |
files | testdata/evaluation/batchProcessingEvaluate.m testdata/evaluation/brahms.mid testdata/evaluation/computeNoteLevelAccuracy.m testdata/evaluation/convertMIDIToPianoRoll.m testdata/evaluation/lussier.mid testdata/evaluation/mozart.mid testdata/evaluation/schubert.mid testdata/evaluation/take_five.mid |
diffstat | 8 files changed, 112 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/evaluation/batchProcessingEvaluate.m Sat May 03 20:49:51 2014 +0100 @@ -0,0 +1,33 @@ +function [Pre,Rec,F] = batchProcessingEvaluate(folder) + +% Evaluate transcription output, using onset-only note-based metrics +% e.g. [Pre,Rec,F] = batchProcessingEvaluate('TRIOS-mirex2012-matlab'); + + +fileList = dir(folder); +fileCount = 0; + +for i=3:length(fileList) + + if(isdir([folder '/' fileList(i).name])) + + fileCount = fileCount + 1; + + + % Load ground truth + [pianoRollGT,nmatGT] = convertMIDIToPianoRoll([fileList(i).name '.mid'],10,1.0); + + + % Load transcripton nmat + nmat = load([folder '/' fileList(i).name '/' 'mix.lab']); + + + % Convert 3rd nmat column to MIDI scale + nmat(:,3) = round(12.*log2(nmat(:,3)./27.5) + 1); + + + % Compute onset-based note-level accuracy + [Pre(fileCount),Rec(fileCount),F(fileCount)] = computeNoteLevelAccuracy(nmat,nmatGT); + + end; +end; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/evaluation/computeNoteLevelAccuracy.m Sat May 03 20:49:51 2014 +0100 @@ -0,0 +1,48 @@ +function [Pre,Rec,F,Acc,PreOff,RecOff,FOff,AccOff] = computeNoteLevelAccuracy(nmat1,nmat2) + +% Compute note-level onset-only and onset-offset accuracy (Bay09) + + +% Initialize +if (isempty(nmat1)) Pre=0; Rec=0; F=0; Acc=0; return; end; + +% Total number of transcribed notes +Ntot = size(nmat1,1); + +% Number of reference notes +Nref = size(nmat2,1); + +% Number of correctly transcribed notes, onset within a +/-50 ms range +Ncorr = 0; +NcorrOff = 0; +for j=1:size(nmat2,1) + for i=1:size(nmat1,1) + if( (nmat1(i,3) == nmat2(j,3)) && (abs(nmat2(j,1)-nmat1(i,1))<=0.05) ) + Ncorr = Ncorr+1; + + % If offset within a +/-50 ms range or within 20% of ground-truth note's duration + if abs(nmat2(j,2) - nmat1(i,2)) <= max(0.05, 0.2 * (nmat2(j,2) - nmat2(j,1))) + NcorrOff = NcorrOff +1; + end; + + break; % In order to consider duplicates as false alarms + + end; + end; +end; + +% Number of onset-only P-R-F-Acc +Nfp = Ntot-Ncorr; +Nfn = Nref-Ncorr; +Rec = Ncorr/Nref; +Pre = Ncorr/Ntot; +F = 2*((Pre*Rec)/(Pre+Rec)); +Acc= Ncorr/(Ncorr+Nfp+Nfn); + +% Number of onset-offset P-R-F-Acc +NfpOff = Ntot-NcorrOff; +NfnOff = Nref-NcorrOff; +RecOff = NcorrOff/Nref; +PreOff = NcorrOff/Ntot; +FOff = 2*((PreOff*RecOff)/(PreOff+RecOff)); +AccOff= NcorrOff/(NcorrOff+NfpOff+NfnOff); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/evaluation/convertMIDIToPianoRoll.m Sat May 03 20:49:51 2014 +0100 @@ -0,0 +1,31 @@ +function [pianoRoll,newnmat] = convertMIDIToPianoRoll(filename,timeResolution,dur) + +% Time resolution is in msec +% eg. pianoRoll = convertMIDIToPianoRoll('bach_847MINp_align.mid',10); + +% Read MIDI file +nmat = readmidi(filename); + + +% Gather MIDI information +[n1 n2] = size(nmat); +lenthInSec = nmat(n1,6) + nmat(n1,7); +pianoRoll = zeros(88,round(lenthInSec*(1000/timeResolution))); + + +% Fill piano roll +for i=1:n1 + pianoRoll(round(nmat(i,4)-20),round(nmat(i,6)*(1000/timeResolution))+1:round(nmat(i,6)*(1000/timeResolution)+dur*nmat(i,7)*(1000/timeResolution))+1) = 1; +end; + +pianoRoll = pianoRoll'; + +% Plot piano roll +%figure; imagesc(imrotate(pianoRoll,0)); axis xy +%colormap('gray'); xlabel('time frame'); ylabel('Pitch'); + + +% Convert to non-MIDI nmat +newnmat(:,1) = nmat(:,6); +newnmat(:,2) = nmat(:,6)+nmat(:,7); +newnmat(:,3) = nmat(:,4)-20; \ No newline at end of file