Esempio n. 1
0
def vad_evaluate_darpa(testing_list=None,
                       ref_annotations_list=None,
                       hyp_annotations_list=None,
                       eval_script=None,
                       audio_dir=None,
                       smp_period=0.01,
                       window_length=0.02,
                       task_id='SAD',
                       results_dir=None):
    '''
    Run the java DARPA evaluation script by calling the relevant MATLAB function. The
    MATLAB function needs to be in MATLAB path. A shell script (matlab_batcher.sh) that
    also needs to be in path is called to run the matlab command from the shell.

    Input:
    testing_list : list of audio files (absolute paths)
    ref_annotations_list : list of reference annotations (absolute paths)
    hyp_annotations_list : list of hypothesized annotations (absolute paths)
    eval_script : the java evaluation script
    audio_dir : directory where the audio files lie
    smp_period : frame period (in seconds)
    window_length : frame length (in seconds)
    task_id : an id for the task that is evaluated
    results_dir : directory where the results will be stored
    '''
    evaluation_scp_file = os.path.join(results_dir, 'evaluation.scp')
    test_files = lists.get_contents(testing_list)
    ref_files = lists.get_contents(ref_annotations_list)
    hyp_files = lists.get_contents(hyp_annotations_list)
    eval_scp = open(evaluation_scp_file, 'w')
    for t, r, h in map(None, test_files, ref_files, hyp_files):
        eval_scp.write('{} {} {}\n'.format(t, r, h))
    eval_scp.close()

    darpa_convert_labels_to_ids_file_list(hyp_annotations_list)

    args = '{in_file},{script_path},{audio_dir},{working_dir},{task_id},{smp_period},{window_length}'.format(
        in_file=add_quotes(evaluation_scp_file),
        script_path=add_quotes(eval_script),
        audio_dir=add_quotes(audio_dir),
        working_dir=add_quotes(results_dir),
        task_id=add_quotes(task_id),
        smp_period=smp_period,
        window_length=window_length)
    cmd = ['matlab_batcher.sh', 'FindPercentageFromResultFiles', args]
    assert (which.which('matlab_batcher.sh') != None)
    logging.debug(string.join(cmd, ' '))
    logging.info(subprocess.check_call(cmd, stderr=subprocess.STDOUT))
def vad_evaluate_darpa(testing_list=None, ref_annotations_list=None, hyp_annotations_list=None,
                       eval_script=None, audio_dir=None, smp_period=0.01, window_length=0.02, 
                       task_id='SAD', results_dir=None):
    '''
    Run the java DARPA evaluation script by calling the relevant MATLAB function. The 
    MATLAB function needs to be in MATLAB path. A shell script (matlab_batcher.sh) that 
    also needs to be in path is called to run the matlab command from the shell.
    
    Input:
    testing_list : list of audio files (absolute paths)
    ref_annotations_list : list of reference annotations (absolute paths)
    hyp_annotations_list : list of hypothesized annotations (absolute paths)
    eval_script : the java evaluation script
    audio_dir : directory where the audio files lie
    smp_period : frame period (in seconds)
    window_length : frame length (in seconds)
    task_id : an id for the task that is evaluated
    results_dir : directory where the results will be stored
    '''
    evaluation_scp_file = os.path.join(results_dir,'evaluation.scp')
    test_files = lists.get_contents(testing_list)
    ref_files = lists.get_contents(ref_annotations_list)
    hyp_files = lists.get_contents(hyp_annotations_list)
    eval_scp = open(evaluation_scp_file,'w')
    for t, r, h in map(None, test_files, ref_files, hyp_files):
        eval_scp.write('{} {} {}\n'.format(t, r, h))
    eval_scp.close()

    darpa_convert_labels_to_ids_file_list(hyp_annotations_list)
    
    args = '{in_file},{script_path},{audio_dir},{working_dir},{task_id},{smp_period},{window_length}'.format(in_file=add_quotes(evaluation_scp_file),
                                                               script_path=add_quotes(eval_script),
                                                               audio_dir=add_quotes(audio_dir),
                                                               working_dir=add_quotes(results_dir),
                                                               task_id=add_quotes(task_id),
                                                               smp_period=smp_period,
                                                               window_length=window_length)
    cmd = ['matlab_batcher.sh','FindPercentageFromResultFiles',args]
    assert(which.which('matlab_batcher.sh') != None)
    logging.debug(string.join(cmd,' '))
    logging.info(subprocess.check_output(cmd, stderr=subprocess.STDOUT))
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__,
                                     formatter_class=argparse.RawDescriptionHelpFormatter,)
    parser.add_argument('--in_list', help='input file list', required=True)
    parser.add_argument('--search_dir', action='append', help='directory to search in')
    parser.add_argument('--suffix', default='txt', help='suffix of the files to be found')
    parser.add_argument('--scp_file', help='scp file where all the information will be stored', required=True)
    parser.add_argument('--reverse', help='write the found files first in the scp file', action='store_true')

    args = parser.parse_args()

    in_file_list = args.in_list
    search_directories = args.search_dir
    scp_file = args.scp_file
    sfx = args.suffix

    in_files = lists.get_contents(in_file_list)
    corresponding_files = find_corresponding_files(in_files, search_directories, sfx)

    scp = open(scp_file,'w')
    for i_fl, c_fl in zip(in_files, corresponding_files):
        if args.reverse:
            scp.write('{} {}\n'.format(c_fl, i_fl))
        else:
            scp.write('{} {}\n'.format(i_fl, c_fl))


    scp.close()

    parser.add_argument('--suffix',
                        default='txt',
                        help='suffix of the files to be found')
    parser.add_argument(
        '--scp_file',
        help='scp file where all the information will be stored',
        required=True)
    parser.add_argument('--reverse',
                        help='write the found files first in the scp file',
                        action='store_true')

    args = parser.parse_args()

    in_file_list = args.in_list
    search_directories = args.search_dir
    scp_file = args.scp_file
    sfx = args.suffix

    in_files = lists.get_contents(in_file_list)
    corresponding_files = find_corresponding_files(in_files,
                                                   search_directories, sfx)

    scp = open(scp_file, 'w')
    for i_fl, c_fl in zip(in_files, corresponding_files):
        if args.reverse:
            scp.write('{} {}\n'.format(c_fl, i_fl))
        else:
            scp.write('{} {}\n'.format(i_fl, c_fl))

    scp.close()