We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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.py 文件中计算报错,断点调试,计算的 stdout 为 '',转换float报错,文件中完整代码如下,这里应该如何处理,是否subprocess.Popen中指令需要变动,期待大佬的解答!
metrics.py
@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, }
The text was updated successfully, but these errors were encountered:
报错位置为return 的上一行 map_, mrr = [float(s[-6:]) for s in stdout.strip().split('\n')]
map_, mrr = [float(s[-6:]) for s in stdout.strip().split('\n')]
Sorry, something went wrong.
No branches or pull requests
metrics.py
文件中计算报错,断点调试,计算的 stdout 为 '',转换float报错,文件中完整代码如下,这里应该如何处理,是否subprocess.Popen中指令需要变动,期待大佬的解答!The text was updated successfully, but these errors were encountered: