Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics 计算报错 #1

Open
miaozjs opened this issue Apr 3, 2022 · 1 comment
Open

metrics 计算报错 #1

miaozjs opened this issue Apr 3, 2022 · 1 comment

Comments

@miaozjs
Copy link

miaozjs commented Apr 3, 2022

metrics.py 文件中计算报错,断点调试,计算的 stdout 为 '',转换float报错,文件中完整代码如下,这里应该如何处理,是否subprocess.Popen中指令需要变动,期待大佬的解答!

@register('map')
@register('mrr')
def ranking(outputs):
    args = outputs['args']
    dataset = outputs['dataset']
    prediction = [o[1] for o in outputs['prob']]
    ref_file = os.path.join(dataset, '{}.ref'.format(args.eval_file))
    rank_file = os.path.join(dataset, '{}.rank'.format(args.eval_file))
    tmp_file = os.path.join(args.summary_dir, 'tmp-pred.txt')
    with open(rank_file) as f:
        prefix = []
        for line in f:
            prefix.append(line.strip().split())
        assert len(prefix) == len(prediction), \
            'prefix {}, while prediction {}'.format(len(prefix), len(prediction))
    with open(tmp_file, 'w') as f:
        for prefix, pred in zip(prefix, prediction):
            prefix[-2] = str(pred)
            f.write(' '.join(prefix) + '\n')
    sp = subprocess.Popen('./resources/trec_eval {} {} | egrep "map|recip_rank"'.format(ref_file, tmp_file),
                          shell=True,
                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = sp.communicate()
    stdout, stderr = stdout.decode(), stderr.decode()
    os.remove(tmp_file)
    if '':
        print(00)
    else:
        print('11')
    map_, mrr = [float(s[-6:]) for s in stdout.strip().split('\n')]
    return {
        'map': map_,
        'mrr': mrr,
    }
@miaozjs
Copy link
Author

miaozjs commented Apr 3, 2022

报错位置为return 的上一行
map_, mrr = [float(s[-6:]) for s in stdout.strip().split('\n')]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant